Skip to content

Support inserting ClickHouse env vars into .env files #90

@sdairs

Description

@sdairs

Summary

Add a clickhousectl local server dotenv command that writes standard ClickHouse connection environment variables into a .env file (or .env.local with --local), making it easy to configure apps that read from dotenv files.

Proposed CLI

clickhousectl local server dotenv [--name <server-name>] [--local]
  • --name <server-name> — target a specific named server (defaults to default)
  • --local — write to .env.local instead of .env

Behavior

  1. Read the connection details for the given server (host, port, user, password, database, etc.)
  2. Write opinionated env var names into the target file, e.g.:
    CLICKHOUSE_HOST=localhost
    CLICKHOUSE_PORT=9000
    CLICKHOUSE_HTTP_PORT=8123
    CLICKHOUSE_USER=default
    CLICKHOUSE_PASSWORD=
    CLICKHOUSE_DATABASE=default
    
  3. If the .env / .env.local file already exists, find and replace any existing CLICKHOUSE_* vars in-place rather than appending duplicates
  4. If the file doesn't exist, create it with just the ClickHouse vars

Use case

When switching between servers (e.g. dev vs staging), you can quickly swap your app's ClickHouse connection config:

clickhousectl local server dotenv --name dev
# .env now points to dev server

clickhousectl local server dotenv --name staging
# .env now points to staging server

Using --local lets you keep a .env.local override that isn't committed to git, which is the common convention for local-only config.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions