Use moose db pull to refresh the definitions of tables you marked as EXTERNALLY_MANAGED from a live ClickHouse instance. It reads your code to find external tables, fetches their remote schemas, regenerates one external models file, and creates a small git commit if anything changed. If new external tables were added remotely (e.g., new CDC streams), they are added to the external models file as part of the same run.
lifeCycle: EXTERNALLY_MANAGED (TypeScript) or life_cycle=LifeCycle.EXTERNALLY_MANAGED (Python)db pull accepts both native and HTTP(S) URLs. Native strings are automatically converted to HTTP(S) with the appropriate ports.
Examples:
# Native (auto-converted to HTTPS + 8443)
moose db pull --clickhouse-url "clickhouse://explorer@play.clickhouse.com:9440/default"
# HTTPS (explicit database via query param)
moose db pull --clickhouse-url "https://play.clickhouse.com/?user=explorer&database=default"
# Local HTTP
moose db pull --clickhouse-url "http://localhost:8123/?user=default&database=default"app/externalModels.ts
db pull treats this file as the single source of truth for EXTERNALLY_MANAGED tables. It introspects the remote schema, updates existing external tables, and adds any newly detected external tables here. It does not modify models elsewhere in your codebase.
Keep all external tables in this file and import it once from your root (app/index.ts for TypeScript or app/main.py for Python).
Important:
--file-path).When you run db pull the CLI does the following:
EXTERNALLY_MANAGED.--clickhouse-url and introspects the live schemas for those tables.app/index.ts (TypeScript) or app/main.py (Python), or the database itself.// AUTO-GENERATED FILE. DO NOT EDIT.// This file will be replaced when you run `moose db pull`. // ...typed table definitions matching remote EXTERNALLY_MANAGED tables...moose db pull --clickhouse-url <URL> [--file-path <OUTPUT_PATH>]clickhouse://user:pass@host:port/database or https://user:pass@host:port/database). Can also be set via CLICKHOUSE_URL environment variable.Your DBA, CDC pipeline (e.g., ClickPipes), or ETL job updated a table's schema. To keep your code accurate and type-safe, refresh your external models so queries, APIs, and materialized views reference the correct columns and types.
moose db pull --clickhouse-url <YOUR_CLICKHOUSE_URL>This updates only EXTERNALLY_MANAGED models and leaves managed code untouched.
In active development, schemas can drift faster than you commit updates. Running db pull on dev startup helps ensure your local code matches the live schema you depend on.
export CLICKHOUSE_URL="clickhouse://<user>:<password>@<host>:<port>/<database>"Add to moose.config.toml:
[http_server_config]on_first_start_script = "moose db pull"This runs once when the dev server first starts. The CLI will read the URL from the CLICKHOUSE_URL environment variable. To run after code reloads, use on_reload_complete_script.
If you're starting with an existing ClickHouse database, bootstrap code with init --from-remote, then use db pull over time to keep external models fresh:
moose init my-project --from-remote $REMOTE_CLICKHOUSE_URL --language <typescript|python>Your CDC pipeline created a new table (or exposed a new stream). Pull to add the new table to your external models file automatically.
moose db pull --clickhouse-url <YOUR_CLICKHOUSE_URL>The regenerated external models file will now include the newly discovered external table.
EXTERNALLY_MANAGED and names match remote.