Skip to content

Commit b674ae0

Browse files
committed
chore: use wildcard pattern and escape like operator
1 parent fdc2189 commit b674ae0

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

internal/db/diff/migra.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@ func LoadUserSchemas(ctx context.Context, conn *pgx.Conn, exclude ...string) ([]
106106
// Exclude functions because Webhooks support is early alpha
107107
"supabase_functions",
108108
"supabase_migrations",
109-
// Exclude postgres temporary schemas
110-
"pg_temp_%",
111-
"pg_toast_temp_%",
112109
}, utils.SystemSchemas...)
110+
exclude = likeEscapeSchema(exclude)
113111
}
114112
rows, err := conn.Query(ctx, LIST_SCHEMAS, exclude)
115113
if err != nil {
@@ -126,6 +124,15 @@ func LoadUserSchemas(ctx context.Context, conn *pgx.Conn, exclude ...string) ([]
126124
return schemas, nil
127125
}
128126

127+
func likeEscapeSchema(schemas []string) (result []string) {
128+
// Treat _ as literal, * as any character
129+
replacer := strings.NewReplacer("_", `\_`, "*", "%")
130+
for _, sch := range schemas {
131+
result = append(result, replacer.Replace(sch))
132+
}
133+
return result
134+
}
135+
129136
func CreateShadowDatabase(ctx context.Context) (string, error) {
130137
config := container.Config{
131138
Image: utils.DbImage,

internal/db/diff/migra_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func TestRunMigra(t *testing.T) {
108108
// Setup mock postgres
109109
conn := pgtest.NewConn()
110110
defer conn.Close(t)
111-
conn.Query("SELECT schema_name FROM information_schema.schemata WHERE NOT schema_name LIKE ANY('{pgbouncer,realtime,_realtime,supabase_functions,supabase_migrations,pg_temp_%,pg_toast_temp_%,information_schema,pg_catalog,pg_toast,cron,graphql,graphql_public,net,pgsodium,pgsodium_masks,vault}') ORDER BY schema_name").
111+
conn.Query(`SELECT schema_name FROM information_schema.schemata WHERE NOT schema_name LIKE ANY('{pgbouncer,realtime,"\\_realtime","supabase\\_functions","supabase\\_migrations","information\\_schema","pg\\_%",cron,graphql,"graphql\\_public",net,pgsodium,"pgsodium\\_masks",vault}') ORDER BY schema_name`).
112112
ReplyError(pgerrcode.DuplicateTable, `relation "test" already exists`)
113113
// Run test
114114
err := RunMigra(context.Background(), []string{}, "", "password", fsys, conn.Intercept)

internal/utils/misc.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,10 @@ var (
109109
FuncSlugPattern = regexp.MustCompile(`^[A-Za-z][A-Za-z0-9_-]*$`)
110110
ImageNamePattern = regexp.MustCompile(`\/(.*):`)
111111

112-
// These schemas are ignored from schema diffs
112+
// These schemas are ignored from db diff and db dump
113113
SystemSchemas = []string{
114114
"information_schema",
115-
"pg_catalog",
116-
"pg_toast",
115+
"pg_*", // Wildcard pattern follows pg_dump
117116
// Owned by extensions
118117
"cron",
119118
"graphql",

0 commit comments

Comments
 (0)