Skip to content

feat: Environment config overrides (.strata.<env>.yaml) #32

@Lazialize

Description

@Lazialize

Problem

The current .strata.yaml requires all environment configurations to be written in a single environments section. Writing production credentials (passwords, etc.) directly in the config file is a security risk, and teams managing different environments are prone to Git merge conflicts.

Proposed Solution

Support environment-specific override files .strata.<env>.yaml that are deep-merged with the base configuration.

Design

project/
├── .strata.yaml              # Base config (shared)
├── .strata.development.yaml  # Development overrides
├── .strata.staging.yaml      # Staging overrides
└── .strata.production.yaml   # Production overrides (recommended in .gitignore)

Merge Rules

  1. Load .strata.yaml as the base configuration
  2. If a .strata.<env>.yaml file exists for the environment specified by --env, deep-merge it into the base
  3. Fields in the override file overwrite the same-named fields in the base
  4. Environment variable STRATA_ENV can also specify the environment name (--env takes precedence)

Configuration Example

.strata.yaml (base):

version: "1.0"
dialect: postgresql
schema_dir: schema
migrations_dir: migrations
environments:
  development:
    host: localhost
    port: 5432
    database: myapp_dev

.strata.production.yaml (override):

environments:
  production:
    host: db.production.internal
    database: myapp_prod
    ssl_mode: require
    max_connections: 20

Implementation Plan

  1. Extend Config loader (src/core/src/core/config.rs)

    • Add override file discovery logic to Config::load()
    • Implement Config::merge(base, override) method (deep merge of HashMaps)
  2. Add --env CLI argument (src/cli/src/cli/cli.rs)

    • Add --env <ENV> as a global argument
    • Fall back to STRATA_ENV environment variable
  3. Update .gitignore template (strata init)

    • Suggest adding .strata.production.yaml to .gitignore by default

Files Affected

  • src/core/src/core/config.rs — Config::load() merge logic
  • src/cli/src/cli/cli.rs--env argument
  • src/cli/src/cli/commands/command_context.rs — Config loading flow changes
  • src/cli/src/cli/commands/init.rs — .gitignore template update

Alternatives Considered

  • Environment variables only: Override all settings via STRATA_DB_HOST, etc. Simple but file-based management is easier to maintain
  • TOML format: TOML excels at section management, but YAML consistency with the existing ecosystem is preferred
  • Vault integration: HashiCorp Vault or similar secret management tools are future scope; file-based overrides come first

Additional Context

  • Corresponds to "Support environment overrides in config" in ROADMAP.md
  • The existing Config::validate() must also apply to the merged result
  • Typical usage with Docker Compose: STRATA_ENV=production strata apply

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions