Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ var (
Use: "push",
Short: "Push new migrations to the remote database",
RunE: func(cmd *cobra.Command, args []string) error {
return push.Run(cmd.Context(), dryRun, includeAll, includeRoles, includeSeed, flags.DbConfig, afero.NewOsFs())
return push.Run(cmd.Context(), dryRun, includeAll, includeRoles, includeSeed, flags.ProjectRef, flags.DbConfig, afero.NewOsFs())
},
}

Expand Down
2 changes: 1 addition & 1 deletion internal/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func Run(ctx context.Context, starter StarterTemplate, fsys afero.Fs, options ..
}
policy.Reset()
if err := backoff.RetryNotify(func() error {
return push.Run(ctx, false, false, true, true, config, fsys)
return push.Run(ctx, false, false, true, true, "", config, fsys)
}, policy, utils.NewErrorCallback()); err != nil {
return err
}
Expand Down
19 changes: 18 additions & 1 deletion internal/db/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ import (
"github.com/supabase/cli/pkg/vault"
)

func Run(ctx context.Context, dryRun, ignoreVersionMismatch bool, includeRoles, includeSeed bool, config pgconn.Config, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error {
func Run(ctx context.Context, dryRun, ignoreVersionMismatch bool, includeRoles, includeSeed bool, projectRef string, config pgconn.Config, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

The easiest change is to print the current project ref when parsing the --linked flag https://github.com/supabase/cli/blob/develop/internal/utils/flags/db_url.go#L83

Copy link
Author

Choose a reason for hiding this comment

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

Ahhh, totally missed that.

I've pushed changes addressing the above feedback. Let me know if they require further amendments.

if dryRun {
fmt.Fprintln(os.Stderr, "DRY RUN: migrations will *not* be pushed to the database.")
}
if len(projectRef) > 0 {
if err := printProjectInfo(ctx, projectRef); err != nil {
return err
}
}
conn, err := utils.ConnectByConfig(ctx, config, options...)
if err != nil {
return err
Expand Down Expand Up @@ -130,3 +135,15 @@ func confirmSeedAll(pending []migration.SeedFile) (msg string) {
}
return msg
}

func printProjectInfo(ctx context.Context, projectRef string) error {
resp, err := utils.GetSupabase().V1GetProjectWithResponse(ctx, projectRef)
if err != nil {
return errors.Errorf("failed to retrieve project: %w", err)
}
if resp.JSON200 == nil {
return errors.Errorf("unexpected retrieve project status %d: %s", resp.StatusCode(), string(resp.Body))
}
fmt.Fprintf(os.Stderr, "Pushing to linked project: %s (%s)\n", utils.Aqua(resp.JSON200.Name), resp.JSON200.Ref)
return nil
}
18 changes: 9 additions & 9 deletions internal/db/push/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestMigrationPush(t *testing.T) {
conn.Query(migration.LIST_MIGRATION_VERSION).
Reply("SELECT 0")
// Run test
err := Run(context.Background(), true, false, true, true, dbConfig, fsys, conn.Intercept)
err := Run(context.Background(), true, false, true, true, "", dbConfig, fsys, conn.Intercept)
// Check error
assert.NoError(t, err)
})
Expand All @@ -54,7 +54,7 @@ func TestMigrationPush(t *testing.T) {
conn.Query(migration.LIST_MIGRATION_VERSION).
Reply("SELECT 0")
// Run test
err := Run(context.Background(), false, false, false, false, dbConfig, fsys, conn.Intercept)
err := Run(context.Background(), false, false, false, false, "", dbConfig, fsys, conn.Intercept)
// Check error
assert.NoError(t, err)
})
Expand All @@ -63,7 +63,7 @@ func TestMigrationPush(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
// Run test
err := Run(context.Background(), false, false, false, false, pgconn.Config{}, fsys)
err := Run(context.Background(), false, false, false, false, "", pgconn.Config{}, fsys)
// Check error
assert.ErrorContains(t, err, "invalid port (outside range)")
})
Expand All @@ -77,7 +77,7 @@ func TestMigrationPush(t *testing.T) {
conn.Query(migration.LIST_MIGRATION_VERSION).
ReplyError(pgerrcode.InvalidCatalogName, `database "target" does not exist`)
// Run test
err := Run(context.Background(), false, false, false, false, pgconn.Config{
err := Run(context.Background(), false, false, false, false, "", pgconn.Config{
Host: "db.supabase.co",
Port: 5432,
User: "admin",
Expand All @@ -104,7 +104,7 @@ func TestMigrationPush(t *testing.T) {
Query(migration.INSERT_MIGRATION_VERSION, "0", "test", nil).
ReplyError(pgerrcode.NotNullViolation, `null value in column "version" of relation "schema_migrations"`)
// Run test
err := Run(context.Background(), false, false, false, false, dbConfig, fsys, conn.Intercept)
err := Run(context.Background(), false, false, false, false, "", dbConfig, fsys, conn.Intercept)
// Check error
assert.ErrorContains(t, err, `ERROR: null value in column "version" of relation "schema_migrations" (SQLSTATE 23502)`)
assert.ErrorContains(t, err, "At statement: 0\n"+migration.INSERT_MIGRATION_VERSION)
Expand All @@ -128,7 +128,7 @@ func TestPushAll(t *testing.T) {
Query(migration.INSERT_MIGRATION_VERSION, "0", "test", nil).
Reply("INSERT 0 1")
// Run test
err := Run(context.Background(), false, false, true, true, dbConfig, fsys, conn.Intercept)
err := Run(context.Background(), false, false, true, true, "", dbConfig, fsys, conn.Intercept)
// Check error
assert.NoError(t, err)
})
Expand All @@ -145,7 +145,7 @@ func TestPushAll(t *testing.T) {
conn.Query(migration.LIST_MIGRATION_VERSION).
Reply("SELECT 0")
// Run test
err := Run(context.Background(), false, false, true, true, dbConfig, fsys, conn.Intercept)
err := Run(context.Background(), false, false, true, true, "", dbConfig, fsys, conn.Intercept)
// Check error
assert.ErrorIs(t, err, context.Canceled)
})
Expand All @@ -161,7 +161,7 @@ func TestPushAll(t *testing.T) {
conn.Query(migration.LIST_MIGRATION_VERSION).
Reply("SELECT 0")
// Run test
err := Run(context.Background(), false, false, true, false, dbConfig, fsys, conn.Intercept)
err := Run(context.Background(), false, false, true, false, "", dbConfig, fsys, conn.Intercept)
// Check error
assert.ErrorIs(t, err, os.ErrPermission)
})
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestPushAll(t *testing.T) {
Query(migration.UPSERT_SEED_FILE, seedPath, digest).
ReplyError(pgerrcode.NotNullViolation, `null value in column "hash" of relation "seed_files"`)
// Run test
err := Run(context.Background(), false, false, false, true, dbConfig, fsys, conn.Intercept)
err := Run(context.Background(), false, false, false, true, "", dbConfig, fsys, conn.Intercept)
// Check error
assert.ErrorContains(t, err, `ERROR: null value in column "hash" of relation "seed_files" (SQLSTATE 23502)`)
})
Expand Down
Loading