Skip to content

Conversation

@tianzhou
Copy link
Contributor

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_) and cleans them up after plan generation (best effort).

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings October 30, 2025 07:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DesiredStateProvider interface to abstract embedded vs external database functionality
  • Adds ExternalDatabase implementation that uses temporary schemas with timestamps for isolation
  • Updates the plan and apply commands 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.

tianzhou and others added 2 commits October 30, 2025 16:07
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>
@tianzhou tianzhou merged commit 5ae1d8c into main Oct 30, 2025
2 checks passed
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.

1 participant