--- title: "ktx connection" description: "Add, list, test, and map data sources." --- Manage database and source connections in your KTX project. Connections define how KTX reaches your data warehouse, BI tools, and context sources. ## Command signature ```bash ktx connection [options] ``` ## Subcommands | Subcommand | Description | |-----------|-------------| | `list` | List configured connections | | `test ` | Test a configured connection | | `add ` | Add or replace a configured connection | | `remove ` | Remove a configured connection from `ktx.yaml` | | `map ` | Refresh and validate BI-to-warehouse mappings | | `mapping list ` | List Metabase database mappings | | `mapping set ` | Set a Metabase or Looker warehouse mapping | | `mapping apply-bulk ` | Apply mappings from JSON | | `mapping set-sync-enabled ` | Enable or disable sync for one Metabase database | | `mapping sync-state get ` | Read sync-state selection | | `mapping sync-state set ` | Write sync-state selection | | `mapping refresh ` | Refresh Metabase database mappings | | `mapping validate ` | Validate Metabase database mappings | | `mapping clear [dbId]` | Clear Metabase database mappings | | `metabase setup` | Guided setup for a Metabase connection | | `notion pick ` | Pick Notion root pages for a configured Notion connection | ## Options ### `connection add` | Flag | Description | Default | |------|-------------|---------| | `--url ` | Connection URL, `env:NAME`, or `file:/path` reference | — | | `--schema ` | Schema to include; repeatable | — | | `--readonly` | Mark the connection as read-only | `false` | | `--force` | Replace an existing connection | `false` | | `--allow-literal-credentials` | Allow writing a literal credential URL to `ktx.yaml` | `false` | #### Notion-specific options for `connection add` | Flag | Description | Default | |------|-------------|---------| | `--token-env ` | Environment variable containing Notion auth token | — | | `--token-file ` | File containing Notion auth token | — | | `--crawl-mode ` | Notion crawl mode (`all_accessible` or `selected_roots`) | `selected_roots` | | `--root-page-id ` | Root page to crawl; repeatable | — | | `--root-database-id ` | Root database to crawl; repeatable | — | | `--root-data-source-id ` | Root data source to crawl; repeatable | — | | `--max-pages ` | Maximum pages per run | — | | `--max-knowledge-creates ` | Maximum knowledge creates per run | — | | `--max-knowledge-updates ` | Maximum knowledge updates per run | — | ### `connection remove` | Flag | Description | Default | |------|-------------|---------| | `--force` | Remove without prompting | `false` | | `--no-input` | Disable interactive terminal input | — | ### `connection map` | Flag | Description | Default | |------|-------------|---------| | `--json` | Print JSON output | `false` | ### `connection mapping` subcommands | Flag | Subcommand | Description | Default | |------|-----------|-------------|---------| | `--json` | `list`, `sync-state get` | Print JSON output | `false` | | `--file ` | `apply-bulk` | JSON mapping file (required) | — | | `--enabled ` | `set-sync-enabled` | `true` or `false` (required) | — | | `--mode ` | `sync-state set` | `ALL`, `ONLY`, or `EXCEPT` (required) | — | | `--collections ` | `sync-state set` | Comma-separated collection ids | — | | `--items ` | `sync-state set` | Comma-separated item ids | — | | `--tag-names ` | `sync-state set` | Comma-separated tag names | — | | `--auto-accept` | `refresh` | Accept refresh changes without prompting | `false` | ### `connection metabase setup` | Flag | Description | Default | |------|-------------|---------| | `--id ` | KTX connection id to write | — | | `--url ` | Metabase API URL | — | | `--api-key ` | Metabase API key | — | | `--mint-api-key` | Mint a Metabase API key with credentials | `false` | | `--username ` | Metabase admin username for API-key minting | — | | `--password ` | Metabase admin password for API-key minting | — | | `--map ` | Assign a Metabase database id to a warehouse connection; repeatable | — | | `--sync ` | Enable sync for a discovered database; repeatable | — | | `--sync-mode ` | Metabase sync selection mode (`ALL`, `ONLY`, or `EXCEPT`) | `ALL` | | `--run-ingest` | Run ingest after setup | `false` | | `--yes` | Confirm and apply setup changes without prompting | `false` | | `--no-input` | Disable interactive terminal input | — | ### `connection notion pick` | Flag | Description | Default | |------|-------------|---------| | `--no-input` | Disable interactive terminal input | — | | `--root-page-id ` | Root page UUID to crawl; repeatable (required with `--no-input`) | — | ## Examples ```bash # List all configured connections ktx connection list # Add a Postgres connection using an environment variable ktx connection add postgres my-warehouse --url "env:DATABASE_URL" # Add a Postgres connection with specific schemas ktx connection add postgres analytics --url "env:PG_URL" --schema public --schema analytics # Add a read-only Snowflake connection ktx connection add snowflake sf-prod --url "env:SNOWFLAKE_URL" --readonly # Test a connection ktx connection test my-warehouse # Remove a connection ktx connection remove old-warehouse # Add a Notion source connection ktx connection add notion my-notion \ --token-env NOTION_TOKEN \ --crawl-mode selected_roots \ --root-page-id abc123def456... # Run guided Metabase setup ktx connection metabase setup --url https://metabase.example.com # Map a BI database to a warehouse connection ktx connection mapping set metabase-prod databaseMappings 1=my-warehouse # Refresh Metabase mappings ktx connection mapping refresh metabase-prod --auto-accept # Pick Notion root pages interactively ktx connection notion pick my-notion ``` ## Output Interactive commands render prompts and status text. Commands with `--json` return machine-readable JSON suitable for scripts and agents. ```json { "connections": [ { "id": "my-warehouse", "driver": "postgres", "readonly": false } ] } ``` ## Common errors | Error | Cause | Recovery | |-------|-------|----------| | Connection test fails | Credentials, network access, database, warehouse, or schema is invalid | Verify the same URL with the database's native client, then rerun `ktx connection add ... --force` | | Literal credentials rejected | KTX avoids writing raw secrets to `ktx.yaml` by default | Use `env:NAME` or `file:/path/to/secret`; use `--allow-literal-credentials` only for local throwaway projects | | Mapping validation fails | BI database mappings do not point at valid warehouse connections | Run `ktx connection mapping refresh --auto-accept`, then set invalid mappings explicitly | | Notion pick cannot run non-interactively | `--no-input` was used without root page or database ids | Pass `--root-page-id`, `--root-database-id`, or `--root-data-source-id` with `--no-input` |