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
20 changes: 10 additions & 10 deletions internal/db/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,28 @@ func Run(ctx context.Context, path string, config pgconn.Config, schema, exclude
if dryRun {
fmt.Fprintln(os.Stderr, "DRY RUN: *only* printing the pg_dump script to console.")
}
db := "remote"
if utils.IsLocalDatabase(config) {
db = "local"
}
if dataOnly {
fmt.Fprintln(os.Stderr, "Dumping data from remote database...")
fmt.Fprintf(os.Stderr, "Dumping data from %s database...\n", db)
return dumpData(ctx, config, schema, excludeTable, useCopy, dryRun, outStream)
} else if roleOnly {
fmt.Fprintln(os.Stderr, "Dumping roles from remote database...")
fmt.Fprintf(os.Stderr, "Dumping roles from %s database...\n", db)
return dumpRole(ctx, config, keepComments, dryRun, outStream)
}
fmt.Fprintln(os.Stderr, "Dumping schemas from remote database...")
fmt.Fprintf(os.Stderr, "Dumping schemas from %s database...\n", db)
return DumpSchema(ctx, config, schema, keepComments, dryRun, outStream)
}

func DumpSchema(ctx context.Context, config pgconn.Config, schema []string, keepComments, dryRun bool, stdout io.Writer) error {
var env []string
if len(schema) > 0 {
env = append(env, "INCLUDED_SCHEMAS="+strings.Join(schema, "|"))
// Must append flag because empty string results in error
env = append(env, "EXTRA_FLAGS=--schema="+strings.Join(schema, "|"))
} else {
env = append(env,
"EXCLUDED_SCHEMAS="+strings.Join(utils.InternalSchemas, "|"),
"INCLUDED_SCHEMAS=*",
// Must append flag because empty string results in error
"EXTRA_FLAGS=--extension=*",
)
env = append(env, "EXCLUDED_SCHEMAS="+strings.Join(utils.InternalSchemas, "|"))
}
if !keepComments {
env = append(env, "EXTRA_SED=/^--/d")
Expand Down
8 changes: 7 additions & 1 deletion internal/db/dump/templates/dump_schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@ export PGDATABASE="$PGDATABASE"
# - do not alter superuser role "supabase_admin"
# - do not include ACL changes on internal schemas
# - do not include RLS policies on cron extension schema
# - do not include event triggers
# - do not include creating publication "supabase_realtime"
pg_dump \
--schema-only \
--quote-all-identifier \
--exclude-schema "${EXCLUDED_SCHEMAS:-}" \
--schema "${INCLUDED_SCHEMAS:-}" \
${EXTRA_FLAGS:-} \
| sed -E 's/^CREATE SCHEMA "/CREATE SCHEMA IF NOT EXISTS "/' \
| sed -E 's/^CREATE TABLE "/CREATE TABLE IF NOT EXISTS "/' \
| sed -E 's/^CREATE SEQUENCE "/CREATE SEQUENCE IF NOT EXISTS "/' \
| sed -E 's/^CREATE VIEW "/CREATE OR REPLACE VIEW "/' \
| sed -E 's/^CREATE FUNCTION "/CREATE OR REPLACE FUNCTION "/' \
| sed -E 's/^CREATE TRIGGER "/CREATE OR REPLACE TRIGGER "/' \
| sed -E 's/^CREATE PUBLICATION "supabase_realtime"/-- &/' \
| sed -E 's/^CREATE EVENT TRIGGER /-- &/' \
| sed -E 's/^ WHEN TAG IN /-- &/' \
| sed -E 's/^ EXECUTE FUNCTION /-- &/' \
| sed -E 's/^ALTER EVENT TRIGGER /-- &/' \
| sed -E 's/^ALTER DEFAULT PRIVILEGES FOR ROLE "supabase_admin"/-- &/' \
| sed -E "s/^GRANT (.+) ON (.+) \"(${EXCLUDED_SCHEMAS:-})\"/-- &/" \
| sed -E "s/^REVOKE (.+) ON (.+) \"(${EXCLUDED_SCHEMAS:-})\"/-- &/" \
Expand Down
4 changes: 4 additions & 0 deletions internal/migration/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/jackc/pgerrcode"
"github.com/jackc/pgx/v4"
"github.com/spf13/afero"
"github.com/spf13/viper"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/pgxv5"
)
Expand Down Expand Up @@ -73,6 +74,9 @@ const (
func formatTimestamp(version string) string {
timestamp, err := time.Parse(layoutVersion, version)
if err != nil {
if viper.GetBool("DEBUG") {
fmt.Fprintln(os.Stderr, err)
}
return version
}
return timestamp.Format(layoutHuman)
Expand Down