Conversation
Allow users to optionally provide an external PostgreSQL database for plan generation instead of always using embedded postgres. This addresses limitations in issues #121 and #122. Key changes: - Add DesiredStateProvider interface to abstract embedded/external DB - Implement ExternalDatabase for user-provided databases - Add --plan-host, --plan-port, --plan-db, --plan-user, --plan-password flags - Support PGSCHEMA_PLAN_* environment variables - Create temporary schemas with nanosecond timestamps for isolation - Validate major version compatibility between plan and target DB - Maintain backwards compatibility (embedded postgres remains default) The external database creates temporary schemas (pgschema_plan_<timestamp>) and cleans them up after plan generation (best effort). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces support for using an external PostgreSQL database as the plan database instead of always using an embedded PostgreSQL instance. This allows users to optionally specify an external database via --plan-host and related flags for generating migration plans.
- Introduces a
DesiredStateProviderinterface to abstract embedded vs external database functionality - Adds
ExternalDatabaseimplementation that uses temporary schemas with timestamps for isolation - Updates the
planandapplycommands to support external database configuration via flags and environment variables
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/postgres/desired_state.go | Defines the DesiredStateProvider interface to abstract desired state database implementations |
| internal/postgres/external.go | Implements ExternalDatabase for connecting to external PostgreSQL databases with version checking and temporary schema management |
| internal/postgres/embedded.go | Adds GetSchemaName() method to implement DesiredStateProvider interface |
| cmd/plan/plan.go | Updates to use DesiredStateProvider interface and adds plan-* flags for external database configuration |
| cmd/apply/apply.go | Updates to use DesiredStateProvider interface instead of concrete EmbeddedPostgres type |
| cmd/util/env.go | Adds helper functions for plan database environment variable handling and validation |
| cmd/plan/external_db_integration_test.go | Integration tests for external database functionality |
| go.mod, go.sum | Updates dependencies (moves testify from indirect to direct) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Correct the comment to match the actual Go time format string. The period (.) is required in Go's time format for fractional seconds, not an underscore. The format "20060102_150405.000000000" produces timestamps like "20251030_160428.458109000". Updated comment from: Format: pgschema_plan_YYYYMMDD_HHMMSS_NNNNNNNNN To: Format: pgschema_plan_YYYYMMDD_HHMMSS.NNNNNNNNN Added clarifying note about Go's time format requirements. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allow users to optionally provide an external PostgreSQL database for plan generation instead of always using embedded postgres. This addresses limitations in issues #121 and #122.
Key changes:
The external database creates temporary schemas (pgschema_plan_) and cleans them up after plan generation (best effort).
🤖 Generated with Claude Code