-
Notifications
You must be signed in to change notification settings - Fork 501
fix(cli): repair remote db pull with pg-delta and per-connection role step-down #5895
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6ffa721
fix(cli): repair remote db pull with pg-delta and per-connection role…
avallete 4407659
fix(cli): write one migration file per pg-delta plan unit and format …
avallete 70f1717
fix(cli): close failed connection-probe pools and report all pulled m…
avallete 797c43b
Merge branch 'develop' into avallete/slack-message-bug-debug-adb372
avallete 555063e
fix(cli): split db diff file output by plan unit and record pulled hi…
avallete d72d355
fix(cli): harden the pg-delta migration writer against collisions, ne…
avallete 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
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,88 @@ | ||
| package diff | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/spf13/afero" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "github.com/supabase/cli/internal/utils" | ||
| ) | ||
|
|
||
| func TestSaveDiff(t *testing.T) { | ||
| t.Run("reports no changes on empty diff", func(t *testing.T) { | ||
| fsys := afero.NewMemMapFs() | ||
| require.NoError(t, SaveDiff(DatabaseDiff{SQL: ""}, "my_diff", fsys)) | ||
| // Nothing written when there are no schema changes. | ||
| entries, err := afero.ReadDir(fsys, utils.MigrationsDir) | ||
| assert.Error(t, err) | ||
| assert.Empty(t, entries) | ||
| }) | ||
|
|
||
| t.Run("writes a single migration file for a single-unit plan", func(t *testing.T) { | ||
| fsys := afero.NewMemMapFs() | ||
| files := []PgDeltaPlanFile{ | ||
| {Order: 1, Name: "schema_changes", TransactionMode: "transactional", SQL: "create table a ();"}, | ||
| } | ||
| result := DatabaseDiff{SQL: joinPgDeltaFiles(files), Files: files} | ||
| require.NoError(t, SaveDiff(result, "my_diff", fsys)) | ||
| entries, err := afero.ReadDir(fsys, utils.MigrationsDir) | ||
| require.NoError(t, err) | ||
| require.Len(t, entries, 1) | ||
| // A single-unit plan keeps the plain `<ts>_<name>.sql` name and the exact | ||
| // diff SQL, byte-identical to the pre-multi-file behavior (no trailing newline | ||
| // added, no unit-name suffix). | ||
| assert.Regexp(t, `^\d{14}_my_diff\.sql$`, entries[0].Name()) | ||
| contents, err := afero.ReadFile(fsys, utils.MigrationsDir+"/"+entries[0].Name()) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, "create table a ();", string(contents)) | ||
| }) | ||
|
|
||
| t.Run("writes one migration file per unit for a multi-unit plan", func(t *testing.T) { | ||
| fsys := afero.NewMemMapFs() | ||
| files := []PgDeltaPlanFile{ | ||
| {Order: 1, Name: "schema_changes", TransactionMode: "transactional", SQL: "alter type mood add value 'ok';"}, | ||
| {Order: 2, Name: "after_enum_values", TransactionMode: "transactional", SQL: "insert into t values ('ok');"}, | ||
| } | ||
| result := DatabaseDiff{SQL: joinPgDeltaFiles(files), Files: files} | ||
| require.NoError(t, SaveDiff(result, "my_diff", fsys)) | ||
| entries, err := afero.ReadDir(fsys, utils.MigrationsDir) | ||
| require.NoError(t, err) | ||
| require.Len(t, entries, 2) | ||
| // Multi-unit plans split into one ordered file per unit, each suffixed with the | ||
| // unit name, so `db push`/`reset` applies each unit as its own transaction. | ||
| assert.Regexp(t, `^\d{14}_my_diff_schema_changes\.sql$`, entries[0].Name()) | ||
| assert.Regexp(t, `^\d{14}_my_diff_after_enum_values\.sql$`, entries[1].Name()) | ||
| }) | ||
|
|
||
| t.Run("prints diff to stdout when no file is given", func(t *testing.T) { | ||
| fsys := afero.NewMemMapFs() | ||
| require.NoError(t, SaveDiff(DatabaseDiff{SQL: "create table a ();"}, "", fsys)) | ||
| entries, _ := afero.ReadDir(fsys, utils.MigrationsDir) | ||
| assert.Empty(t, entries) | ||
| }) | ||
|
|
||
| t.Run("creates nested parent directories for a nested single-unit name", func(t *testing.T) { | ||
| fsys := afero.NewMemMapFs() | ||
| require.NoError(t, SaveDiff(DatabaseDiff{SQL: "create table a ();"}, "snapshots/remote", fsys)) | ||
| matches, err := afero.Glob(fsys, utils.MigrationsDir+"/*_snapshots/remote.sql") | ||
| require.NoError(t, err) | ||
| require.Len(t, matches, 1) | ||
| contents, err := afero.ReadFile(fsys, matches[0]) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, "create table a ();", string(contents)) | ||
| }) | ||
|
|
||
| t.Run("creates nested parent directories for a nested multi-unit name", func(t *testing.T) { | ||
| fsys := afero.NewMemMapFs() | ||
| files := []PgDeltaPlanFile{ | ||
| {Order: 1, Name: "schema_changes", TransactionMode: "transactional", SQL: "alter type mood add value 'ok';"}, | ||
| {Order: 2, Name: "after_enum_values", TransactionMode: "transactional", SQL: "insert into t values ('ok');"}, | ||
| } | ||
| result := DatabaseDiff{SQL: joinPgDeltaFiles(files), Files: files} | ||
| require.NoError(t, SaveDiff(result, "snapshots/remote", fsys)) | ||
| matches, err := afero.Glob(fsys, utils.MigrationsDir+"/*_snapshots/remote_*.sql") | ||
| require.NoError(t, err) | ||
| require.Len(t, matches, 2) | ||
| }) | ||
| } |
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.