Skip to content

Commit 2faacf1

Browse files
authored
fix(decalrative): change default declarative/ folder to database/ (#5057)
* fix(decalrative): change default declarative/ folder to database/ * fix: rename from database to schemas * fix: capture declarative cmds telemetry * Revert "fix: rename from database to schemas" This reverts commit 90d022c.
1 parent a362ed7 commit 2faacf1

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

cmd/db_schema_declarative.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,21 @@ var (
5353
// so in the rest of the code we can know that we're running pg-delta logic.
5454
if viper.GetBool("EXPERIMENTAL") && !utils.IsPgDeltaEnabled() {
5555
utils.Config.Experimental.PgDelta = &config.PgDeltaConfig{Enabled: true}
56-
return nil
5756
}
58-
if utils.IsPgDeltaEnabled() {
59-
return nil
57+
if !utils.IsPgDeltaEnabled() {
58+
utils.CmdSuggestion = fmt.Sprintf("Either pass %s or add %s with %s to %s",
59+
utils.Aqua("--experimental"),
60+
utils.Aqua("[experimental.pgdelta]"),
61+
utils.Aqua("enabled = true"),
62+
utils.Bold(utils.ConfigPath))
63+
return errors.New("declarative commands require --experimental flag or pg-delta enabled in config")
6064
}
61-
utils.CmdSuggestion = fmt.Sprintf("Either pass %s or add %s with %s to %s",
62-
utils.Aqua("--experimental"),
63-
utils.Aqua("[experimental.pgdelta]"),
64-
utils.Aqua("enabled = true"),
65-
utils.Bold(utils.ConfigPath))
66-
return errors.New("declarative commands require --experimental flag or pg-delta enabled in config")
65+
// If the config.toml has [experimental.pgdelta] enabled = true, set the EXPERIMENTAL flag to true
66+
// so the follow-up PersistentPreRunE can run the pg-delta logic.
67+
if utils.Config.Experimental.PgDelta.Enabled {
68+
viper.Set("EXPERIMENTAL", true)
69+
}
70+
return cmd.Root().PersistentPreRunE(cmd, args)
6771
},
6872
}
6973

docs/templates/examples.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ supabase-db-schema-declarative-sync:
310310
Reset local database to match migrations first? (local data will be lost) [y/N] y
311311
Resetting database...
312312
...
313-
Declarative schema written to supabase/declarative
313+
Declarative schema written to supabase/database
314314
Finished supabase db schema declarative generate.
315315
supabase-test-db:
316316
- id: basic-usage

internal/db/declarative/declarative_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestWriteDeclarativeSchemas(t *testing.T) {
4545

4646
cfg, err := afero.ReadFile(fsys, utils.ConfigPath)
4747
require.NoError(t, err)
48-
assert.Contains(t, string(cfg), `"declarative"`)
48+
assert.Contains(t, string(cfg), `"database"`)
4949
}
5050

5151
func TestTryCacheMigrationsCatalogWritesPrefixedCache(t *testing.T) {

internal/utils/misc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ var (
8080
CurrBranchPath = filepath.Join(SupabaseDirPath, ".branches", "_current_branch")
8181
// DeclarativeDir is the canonical location for pg-delta declarative schema
8282
// files generated or synced by `supabase db schema declarative` commands.
83-
DeclarativeDir = filepath.Join(SupabaseDirPath, "declarative")
83+
DeclarativeDir = filepath.Join(SupabaseDirPath, "database")
8484
ClusterDir = filepath.Join(SupabaseDirPath, "cluster")
8585
SchemasDir = filepath.Join(SupabaseDirPath, "schemas")
8686
MigrationsDir = filepath.Join(SupabaseDirPath, "migrations")

pkg/config/templates/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,6 @@ s3_secret_key = "env(S3_SECRET_KEY)"
398398
# When enabled, pg-delta becomes the active engine for supported schema flows.
399399
# enabled = false
400400
# Directory under `supabase/` where declarative files are written.
401-
# declarative_schema_path = "./declarative"
401+
# declarative_schema_path = "./database"
402402
# JSON string passed through to pg-delta SQL formatting.
403403
# format_options = "{\"keywordCase\":\"upper\",\"indent\":2,\"maxWidth\":80,\"commaStyle\":\"trailing\"}"

0 commit comments

Comments
 (0)