-
Notifications
You must be signed in to change notification settings - Fork 484
feat(cli): port db diff and db pull to native TypeScript (CLI-1313) #5620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Coly010
wants to merge
25
commits into
develop
Choose a base branch
from
cli/port-db-diff-pull-commands
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d029667
feat(cli): port db diff and db pull to native TypeScript (CLI-1313)
Coly010 c9d4206
test(cli): drop non-parity db pull --local e2e assertion to match Go …
Coly010 4866659
fix(db): stop logging shadow DB password to stdout in db __shadow seam
Coly010 7433b71
fix(db): honor --experimental flag and skip history prompt in machine…
Coly010 84aa1fa
fix(db): remove shadow database anonymous volume on cleanup to match Go
Coly010 a6f8861
fix(db): close four Go-parity gaps in native db diff/pull (review)
Coly010 3d72468
fix(db): load config in db __shadow seam and create parent dirs for e…
Coly010 e2a4eb9
fix(db): honor project .env for pg-delta flag and local-target shadow…
Coly010 d81ee15
Merge remote-tracking branch 'origin/develop' into cli/port-db-diff-p…
Coly010 923d6a4
fix(db): fail db pull on a migration name with a path separator inste…
Coly010 d3f2787
fix(db): forward false target flags, disable shadow-seam telemetry, t…
Coly010 0f99c79
fix(db): treat empty --file as stdout and forward --profile into the …
Coly010 18ee03c
fix(db): merge linked [remotes.<ref>] config overrides for db diff an…
Coly010 bd5b101
fix(db): retry linked db pull diffs and declarative exports through t…
Coly010 23585a7
fix(db): update [db.migrations] schema_paths after db pull --declarative
Coly010 7ac6b72
fix(db): emit structured output after Go-delegated db diff and db pul…
Coly010 dfebd99
fix(db): save a pg-delta debug bundle for empty db pull diffs under P…
Coly010 534cc9e
fix(db): harden db pull/diff parity (version range, migra fallback ne…
Coly010 457e7e6
fix(db): merge linked [remotes.<ref>] config into the shadow baseline
Coly010 6a5fa73
fix(db): correct delegated-pull repair reporting and explicit-diff mi…
Coly010 fc6dd28
fix(db): faithful schema CSV round-trip, undefined-table-only suppres…
Coly010 dfccaf8
fix(db): explicit-diff linked preflight + empty refs, int64 version p…
Coly010 2a4d9df
fix(db): defer base config read in db diff until the target/ref is known
Coly010 cbc32bd
fix(db): pass linked ref to __catalog via a flag so it merges the rem…
Coly010 a016ddc
fix(db): defer base config validation until after the linked ref reso…
Coly010 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package diff | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/jackc/pgconn" | ||
| "github.com/jackc/pgx/v4" | ||
| "github.com/spf13/afero" | ||
| "github.com/supabase/cli/internal/db/start" | ||
| "github.com/supabase/cli/internal/pgdelta" | ||
| "github.com/supabase/cli/internal/utils" | ||
| ) | ||
|
|
||
| // ShadowSource is a provisioned shadow database, left running for an external | ||
| // caller (the native-TypeScript db diff/pull commands) to diff against and then | ||
| // remove. It mirrors the shadow that DiffDatabase prepares as the diff "source". | ||
| type ShadowSource struct { | ||
| // Container is the shadow database container id; the caller MUST remove it | ||
| // (e.g. `docker rm -f <id>`) when the diff completes. | ||
| Container string | ||
| // Source is the connection config for the diff source (the shadow with the | ||
| // platform baseline + local migrations applied). | ||
| Source pgconn.Config | ||
| // TargetOverride, when non-nil, replaces the diff target with a second shadow | ||
| // database (contrib_regression with declarative schemas applied). Mirrors | ||
| // DiffDatabase's local-target declarative branch, where the user's local | ||
| // database is not diffed at all. | ||
| TargetOverride *pgconn.Config | ||
| } | ||
|
|
||
| // PrepareShadowSource provisions the shadow database that DiffDatabase diffs | ||
| // against, but returns it running instead of diffing + removing, so a native | ||
| // caller can run the differ itself. targetLocal mirrors | ||
| // utils.IsLocalDatabase(config) — the only target-derived input the shadow prep | ||
| // needs. usePgDelta selects the declarative-apply engine for the local-declared | ||
| // branch, matching DiffDatabase. On error the shadow container is removed. | ||
| func PrepareShadowSource(ctx context.Context, schema []string, targetLocal bool, usePgDelta bool, fsys afero.Fs, options ...func(*pgx.ConnConfig)) (ShadowSource, error) { | ||
| shadow, err := CreateShadowDatabase(ctx, utils.Config.Db.ShadowPort) | ||
| if err != nil { | ||
| return ShadowSource{}, err | ||
| } | ||
| ok := false | ||
| defer func() { | ||
| if !ok { | ||
| utils.DockerRemove(shadow) | ||
| } | ||
| }() | ||
| if err := start.WaitForHealthyService(ctx, utils.Config.Db.HealthTimeout, shadow); err != nil { | ||
| return ShadowSource{}, err | ||
| } | ||
| if err := MigrateShadowDatabase(ctx, shadow, fsys, options...); err != nil { | ||
| return ShadowSource{}, err | ||
| } | ||
| shadowConfig := pgconn.Config{ | ||
| Host: utils.Config.Hostname, | ||
| Port: utils.Config.Db.ShadowPort, | ||
| User: "postgres", | ||
| Password: utils.Config.Db.Password, | ||
| Database: "postgres", | ||
| } | ||
| var targetOverride *pgconn.Config | ||
| if targetLocal { | ||
| declared, err := loadDeclaredSchemas(fsys) | ||
| if err != nil { | ||
| return ShadowSource{}, err | ||
| } | ||
| if len(declared) > 0 { | ||
| override := shadowConfig | ||
| override.Database = "contrib_regression" | ||
| if usePgDelta { | ||
| declDir := utils.GetDeclarativeDir() | ||
| if exists, _ := afero.DirExists(fsys, declDir); exists { | ||
| if err := pgdelta.ApplyDeclarative(ctx, override, fsys); err != nil { | ||
| return ShadowSource{}, err | ||
| } | ||
| } else { | ||
| if err := migrateBaseDatabase(ctx, override, declared, fsys, options...); err != nil { | ||
| return ShadowSource{}, err | ||
| } | ||
| } | ||
| } else { | ||
| if err := migrateBaseDatabase(ctx, override, declared, fsys, options...); err != nil { | ||
| return ShadowSource{}, err | ||
| } | ||
| } | ||
| targetOverride = &override | ||
| } | ||
| } | ||
| ok = true | ||
| return ShadowSource{Container: shadow, Source: shadowConfig, TargetOverride: targetOverride}, nil | ||
| } | ||
|
|
||
| // PrepareRawShadow provisions a bare shadow database (created + healthy, with no | ||
| // platform baseline or migrations applied), left running for an external caller. | ||
| // Mirrors the shadow that pull.pullDeclarativePgDelta uses as the empty | ||
| // declarative-export source. On error the shadow container is removed. | ||
| func PrepareRawShadow(ctx context.Context) (ShadowSource, error) { | ||
| shadow, err := CreateShadowDatabase(ctx, utils.Config.Db.ShadowPort) | ||
| if err != nil { | ||
| return ShadowSource{}, err | ||
| } | ||
| if err := start.WaitForHealthyService(ctx, utils.Config.Db.HealthTimeout, shadow); err != nil { | ||
| utils.DockerRemove(shadow) | ||
| return ShadowSource{}, err | ||
| } | ||
| return ShadowSource{ | ||
| Container: shadow, | ||
| Source: pgconn.Config{ | ||
| Host: utils.Config.Hostname, | ||
| Port: utils.Config.Db.ShadowPort, | ||
| User: "postgres", | ||
| Password: utils.Config.Db.Password, | ||
| Database: "postgres", | ||
| }, | ||
| }, nil | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.