-
Notifications
You must be signed in to change notification settings - Fork 470
Expand file tree
/
Copy pathdrop.go
More file actions
49 lines (43 loc) · 1.06 KB
/
drop.go
File metadata and controls
49 lines (43 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package migration
import (
"context"
_ "embed"
"github.com/go-errors/errors"
"github.com/jackc/pgx/v4"
"github.com/supabase/cli/pkg/pgxv5"
)
var (
//go:embed queries/drop.sql
DropObjects string
//go:embed queries/list.sql
ListSchemas string
// Initialised by postgres image and owned by postgres role
ManagedSchemas = []string{
`information\_schema`,
`pg\_%`,
`\_analytics`,
`\_realtime`,
`\_supavisor`,
"pgbouncer",
"pgsodium",
"pgtle",
`supabase\_migrations`,
"vault",
}
)
func DropUserSchemas(ctx context.Context, conn *pgx.Conn) error {
migration := MigrationFile{}
migration.Statements = append(migration.Statements, DropObjects)
return migration.ExecBatch(ctx, conn)
}
func ListUserSchemas(ctx context.Context, conn *pgx.Conn, exclude ...string) ([]string, error) {
if len(exclude) == 0 {
exclude = ManagedSchemas
}
rows, err := conn.Query(ctx, ListSchemas, exclude)
if err != nil {
return nil, errors.Errorf("failed to list schemas: %w", err)
}
// TODO: show detail and hint from pgconn.PgError
return pgxv5.CollectStrings(rows)
}