Skip to content

feat: Add pgschema.toml configuration file support#1

Merged
NFUChen merged 19 commits into
mainfrom
feat/config-file
May 14, 2026
Merged

feat: Add pgschema.toml configuration file support#1
NFUChen merged 19 commits into
mainfrom
feat/config-file

Conversation

@NFUChen
Copy link
Copy Markdown
Owner

@NFUChen NFUChen commented May 14, 2026

Summary

Add pgschema.toml configuration file support, enabling users to run pgschema plan / pgschema apply without repeating CLI flags. Includes named environment overrides, multi-tenant schema loop, and CI workflow improvements.

Configuration file (pgschema.toml)

  • New cmd/config package: TOML parsing with BurntSushi/toml, base + [env.*] merge logic using toml.MetaData.IsDefined() to correctly handle boolean zero-value overrides (e.g. auto-approve = false in env block overrides auto-approve = true at base level)
  • --config and --env persistent flags on root command
  • Priority chain: CLI flags > env vars > config env > config base > built-in defaults
  • All three commands (plan, apply, dump) read config values as fallback when CLI flags are not explicitly set

Multi-tenant schema loop

  • [schemas] config section with a SQL query field that discovers tenant schema names dynamically
  • plan and apply iterate over all discovered schemas automatically
  • dump is excluded — it produces a single template schema, looping would be redundant
  • Multi-schema functions call core logic directly (GeneratePlan, ApplyMigration) to avoid infinite recursion through the dispatch check
  • Schema discovery query runs in a read-only transaction (sql.TxOptions{ReadOnly: true}) to prevent accidental data modification

CI workflow improvements

  • ci-test.yml: Split into unit (fast, go test -short) and integration (matrix across PG 14-18) jobs running in parallel
  • release.yml: Converted serial PG version testing into parallel matrix strategy
  • docker-latest.yml: Switched from Docker Hub to GitHub Container Registry (GHCR)

Changed files

File Change
cmd/config/config.go New config package: TOML parsing, env merge, schema discovery
cmd/config/config_test.go Unit tests for config merge, boolean overrides, error cases
cmd/config_integration_test.go Integration tests for config loading + read-only enforcement
cmd/root.go --config, --env flags and loadConfig() in PersistentPreRun
cmd/plan/plan.go Config fallback, multi-schema loop, removed MarkFlagRequired("file")
cmd/apply/apply.go Config fallback, multi-schema loop
cmd/dump/dump.go Config fallback only (no multi-schema)
README.md Configuration file documentation section
.github/workflows/ci-test.yml Matrix strategy for parallel PG version testing
.github/workflows/release.yml Matrix strategy for parallel PG version testing
.github/workflows/docker-latest.yml Switch to GHCR

Test plan

  • go test -v ./cmd/config — unit tests for config parsing and merge logic
  • go test -v ./cmd -run TestConfigLoading — integration tests for config file loading through root command
  • go test -v ./cmd -run TestDiscoverSchemas_ReadOnlyEnforcement — read-only transaction enforcement (SELECT allowed, CREATE/DROP/INSERT rejected)
  • go test -v ./... — full test suite to verify no regressions
  • Manual test: create pgschema.toml with connection details, run pgschema plan without flags
  • Manual test: create config with [env.dev] / [env.prod], verify --env switching
  • Manual test: verify CLI flags override config values

William-W-Chen and others added 19 commits May 14, 2026 22:17
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… flags

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When a config file defines [schemas] with a SQL query, plan and apply
commands discover tenant schemas dynamically and iterate over each one.
Dump is excluded since it produces a single template schema.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tests cover: no config file, explicit config path, env overrides with
inheritance, schemas section, plan fields, boolean overrides, and
command-level config fallback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@NFUChen NFUChen changed the title Feat/config file feat: Add pgschema.toml configuration file support May 14, 2026
@NFUChen NFUChen merged commit 282b531 into main May 14, 2026
1 check passed
@NFUChen NFUChen deleted the feat/config-file branch May 14, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants