Skip to content
Merged
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
22 changes: 13 additions & 9 deletions cmd/db_schema_declarative.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,21 @@ var (
// so in the rest of the code we can know that we're running pg-delta logic.
if viper.GetBool("EXPERIMENTAL") && !utils.IsPgDeltaEnabled() {
utils.Config.Experimental.PgDelta = &config.PgDeltaConfig{Enabled: true}
return nil
}
if utils.IsPgDeltaEnabled() {
return nil
if !utils.IsPgDeltaEnabled() {
utils.CmdSuggestion = fmt.Sprintf("Either pass %s or add %s with %s to %s",
utils.Aqua("--experimental"),
utils.Aqua("[experimental.pgdelta]"),
utils.Aqua("enabled = true"),
utils.Bold(utils.ConfigPath))
return errors.New("declarative commands require --experimental flag or pg-delta enabled in config")
}
utils.CmdSuggestion = fmt.Sprintf("Either pass %s or add %s with %s to %s",
utils.Aqua("--experimental"),
utils.Aqua("[experimental.pgdelta]"),
utils.Aqua("enabled = true"),
utils.Bold(utils.ConfigPath))
return errors.New("declarative commands require --experimental flag or pg-delta enabled in config")
// If the config.toml has [experimental.pgdelta] enabled = true, set the EXPERIMENTAL flag to true
// so the follow-up PersistentPreRunE can run the pg-delta logic.
if utils.Config.Experimental.PgDelta.Enabled {
viper.Set("EXPERIMENTAL", true)
}
return cmd.Root().PersistentPreRunE(cmd, args)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

note

This needs to be called so the telemetry can capture this command runs.

},
}

Expand Down
2 changes: 1 addition & 1 deletion docs/templates/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ supabase-db-schema-declarative-sync:
Reset local database to match migrations first? (local data will be lost) [y/N] y
Resetting database...
...
Declarative schema written to supabase/declarative
Declarative schema written to supabase/database
Finished supabase db schema declarative generate.
supabase-test-db:
- id: basic-usage
Expand Down
2 changes: 1 addition & 1 deletion internal/db/declarative/declarative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestWriteDeclarativeSchemas(t *testing.T) {

cfg, err := afero.ReadFile(fsys, utils.ConfigPath)
require.NoError(t, err)
assert.Contains(t, string(cfg), `"declarative"`)
assert.Contains(t, string(cfg), `"database"`)
}

func TestTryCacheMigrationsCatalogWritesPrefixedCache(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/utils/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var (
CurrBranchPath = filepath.Join(SupabaseDirPath, ".branches", "_current_branch")
// DeclarativeDir is the canonical location for pg-delta declarative schema
// files generated or synced by `supabase db schema declarative` commands.
DeclarativeDir = filepath.Join(SupabaseDirPath, "declarative")
DeclarativeDir = filepath.Join(SupabaseDirPath, "database")
ClusterDir = filepath.Join(SupabaseDirPath, "cluster")
SchemasDir = filepath.Join(SupabaseDirPath, "schemas")
MigrationsDir = filepath.Join(SupabaseDirPath, "migrations")
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/templates/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,6 @@ s3_secret_key = "env(S3_SECRET_KEY)"
# When enabled, pg-delta becomes the active engine for supported schema flows.
# enabled = false
# Directory under `supabase/` where declarative files are written.
# declarative_schema_path = "./declarative"
# declarative_schema_path = "./database"
# JSON string passed through to pg-delta SQL formatting.
# format_options = "{\"keywordCase\":\"upper\",\"indent\":2,\"maxWidth\":80,\"commaStyle\":\"trailing\"}"
Loading