Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,18 @@ var (
},
}

noSeed bool
lastVersion uint
noSeed bool
lastVersion uint
overrideSeedFile string

dbResetCmd = &cobra.Command{
Use: "reset",
Short: "Resets the local database to current migrations",
RunE: func(cmd *cobra.Command, args []string) error {
if noSeed {
utils.Config.Db.Seed.Enabled = false
} else if len(overrideSeedFile) > 0 {
Comment thread
coolusaHD marked this conversation as resolved.
utils.Config.Db.Seed.SqlPaths = []string{overrideSeedFile}
}
return reset.Run(cmd.Context(), migrationVersion, lastVersion, flags.DbConfig, afero.NewOsFs())
},
Expand Down Expand Up @@ -325,7 +328,9 @@ func init() {
resetFlags.Bool("linked", false, "Resets the linked project with local migrations.")
resetFlags.Bool("local", true, "Resets the local database with local migrations.")
resetFlags.BoolVar(&noSeed, "no-seed", false, "Skip running the seed script after reset.")
resetFlags.StringVar(&overrideSeedFile, "override-seed-file", "", "Path to a custom seed SQL file to use instead of the default.")
dbResetCmd.MarkFlagsMutuallyExclusive("db-url", "linked", "local")
dbResetCmd.MarkFlagsMutuallyExclusive("no-seed", "override-seed-file")
Comment thread
coolusaHD marked this conversation as resolved.
resetFlags.StringVar(&migrationVersion, "version", "", "Reset up to the specified version.")
resetFlags.UintVar(&lastVersion, "last", 0, "Reset up to the last n migration versions.")
dbResetCmd.MarkFlagsMutuallyExclusive("version", "last")
Expand Down
2 changes: 2 additions & 0 deletions docs/supabase/db/reset.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ Requires the local development stack to be started by running `supabase start`.

Recreates the local Postgres container and applies all local migrations found in `supabase/migrations` directory. If test data is defined in `supabase/seed.sql`, it will be seeded after the migrations are run. Any other data or schema changes made during local development will be discarded.

Use the `--no-seed` flag to skip seeding entirely. Alternatively, use the `--override-seed-file` flag to specify a custom seed file path instead of the default `supabase/seed.sql`. This is useful when you want to reset with different initial data, such as an empty state with minimal setup.

When running db reset with `--linked` or `--db-url` flag, a SQL script is executed to identify and drop all user created entities in the remote database. Since Postgres roles are cluster level entities, any custom roles created through the dashboard or `supabase/roles.sql` will not be deleted by remote reset.
Loading