diff --git a/cmd/db.go b/cmd/db.go index 5367436df..a9bb6c1e3 100644 --- a/cmd/db.go +++ b/cmd/db.go @@ -193,8 +193,9 @@ var ( }, } - noSeed bool - lastVersion uint + noSeed bool + lastVersion uint + overrideSeedFile string dbResetCmd = &cobra.Command{ Use: "reset", @@ -202,6 +203,8 @@ var ( RunE: func(cmd *cobra.Command, args []string) error { if noSeed { utils.Config.Db.Seed.Enabled = false + } else if len(overrideSeedFile) > 0 { + utils.Config.Db.Seed.SqlPaths = []string{overrideSeedFile} } return reset.Run(cmd.Context(), migrationVersion, lastVersion, flags.DbConfig, afero.NewOsFs()) }, @@ -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") 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") diff --git a/docs/supabase/db/reset.md b/docs/supabase/db/reset.md index acb9b9832..9bf33af9e 100644 --- a/docs/supabase/db/reset.md +++ b/docs/supabase/db/reset.md @@ -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.