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
33 changes: 0 additions & 33 deletions internal/db/dump/templates/dump_data.sh

This file was deleted.

34 changes: 0 additions & 34 deletions internal/db/dump/templates/dump_role.sh

This file was deleted.

53 changes: 0 additions & 53 deletions internal/db/dump/templates/dump_schema.sh

This file was deleted.

6 changes: 4 additions & 2 deletions internal/db/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ func Run(ctx context.Context, dryRun, ignoreVersionMismatch bool, includeRoles,
return err
}
defer conn.Close(context.Background())
pending, err := up.GetPendingMigrations(ctx, ignoreVersionMismatch, conn, fsys)
if err != nil {
var pending []string
if !utils.Config.Db.Migrations.Enabled {
fmt.Fprintln(os.Stderr, "Skipping migrations because it is disabled in config.toml for project:", flags.ProjectRef)
} else if pending, err = up.GetPendingMigrations(ctx, ignoreVersionMismatch, conn, fsys); err != nil {
return err
}
var seeds []migration.SeedFile
Expand Down
15 changes: 11 additions & 4 deletions internal/migration/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ import (
)

func MigrateAndSeed(ctx context.Context, version string, conn *pgx.Conn, fsys afero.Fs) error {
migrations, err := list.LoadPartialMigrations(version, fsys)
if err != nil {
if err := applyMigrationFiles(ctx, version, conn, fsys); err != nil {
return err
}
if err := migration.ApplyMigrations(ctx, migrations, conn, afero.NewIOFS(fsys)); err != nil {
return applySeedFiles(ctx, conn, fsys)
}

func applyMigrationFiles(ctx context.Context, version string, conn *pgx.Conn, fsys afero.Fs) error {
if !utils.Config.Db.Migrations.Enabled {
return nil
}
migrations, err := list.LoadPartialMigrations(version, fsys)
if err != nil {
return err
}
return applySeedFiles(ctx, conn, fsys)
return migration.ApplyMigrations(ctx, migrations, conn, afero.NewIOFS(fsys))
}

func applySeedFiles(ctx context.Context, conn *pgx.Conn, fsys afero.Fs) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/utils/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var (

func GetCurrentTimestamp() string {
// Magic number: https://stackoverflow.com/q/45160822.
return time.Now().UTC().Format("20060102150405")
return time.Now().UTC().Format(layoutVersion)
}

func GetCurrentBranchFS(fsys afero.Fs) (string, error) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ func NewConfig(editors ...ConfigEditor) config {
EncryptionKey: "12345678901234567890123456789032",
SecretKeyBase: "EAx3IQ/wRG1v47ZD4NE4/9RzBI8Jmil3x0yhcW4V2NHBP6c2iPIzwjofi2Ep4HIG",
},
Migrations: migrations{
Enabled: true,
},
Seed: seed{
Enabled: true,
SqlPaths: []string{"seed.sql"},
Expand Down
1 change: 1 addition & 0 deletions pkg/config/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type (
}

migrations struct {
Enabled bool `toml:"enabled"`
SchemaPaths Glob `toml:"schema_paths"`
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/config/templates/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ max_client_conn = 100
# secret_key = "env(SECRET_VALUE)"

[db.migrations]
# If disabled, migrations will be skipped during a db push or reset.
enabled = true
# Specifies an ordered list of schema files that describe your database.
# Supports glob patterns relative to supabase directory: "./schemas/*.sql"
schema_paths = []
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/testdata/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ shadow_port = 54320
major_version = 17

[db.migrations]
# If disabled, migrations will be skipped during a db push or reset.
enabled = true
# Specifies an ordered list of schema files that describe your database.
# Supports glob patterns relative to supabase directory: "./schemas/*.sql"
schema_paths = ["./schemas/*.sql"]
Expand Down