@@ -9,9 +9,12 @@ import (
9
9
"github.com/docker/docker/api/types/container"
10
10
"github.com/docker/docker/api/types/network"
11
11
"github.com/go-errors/errors"
12
+ "github.com/jackc/pgx/v4"
12
13
"github.com/spf13/viper"
14
+ "github.com/supabase/cli/internal/gen/types"
13
15
"github.com/supabase/cli/internal/utils"
14
16
"github.com/supabase/cli/pkg/config"
17
+ "github.com/supabase/cli/pkg/migration"
15
18
)
16
19
17
20
var (
20
23
//go:embed templates/migra.ts
21
24
diffSchemaTypeScript string
22
25
26
+ //go:embed templates/staging-ca-2021.crt
27
+ caStaging string
28
+ //go:embed templates/prod-ca-2021.crt
29
+ caProd string
30
+
23
31
managedSchemas = []string {
24
32
// Local development
25
33
"_analytics" ,
54
62
)
55
63
56
64
// Diffs local database schema against shadow, dumps output to stdout.
57
- func DiffSchemaMigraBash (ctx context.Context , source , target string , schema []string ) (string , error ) {
65
+ func DiffSchemaMigraBash (ctx context.Context , source , target string , schema []string , options ... func (* pgx.ConnConfig )) (string , error ) {
66
+ // Load all user defined schemas
67
+ if len (schema ) == 0 {
68
+ var err error
69
+ if schema , err = loadSchema (ctx , target , options ... ); err != nil {
70
+ return "" , err
71
+ }
72
+ }
58
73
env := []string {"SOURCE=" + source , "TARGET=" + target }
59
74
// Passing in script string means command line args must be set manually, ie. "$@"
60
75
args := "set -- " + strings .Join (schema , " " ) + ";"
@@ -80,8 +95,25 @@ func DiffSchemaMigraBash(ctx context.Context, source, target string, schema []st
80
95
return out .String (), nil
81
96
}
82
97
83
- func DiffSchemaMigra (ctx context.Context , source , target string , schema []string ) (string , error ) {
98
+ func loadSchema (ctx context.Context , dbURL string , options ... func (* pgx.ConnConfig )) ([]string , error ) {
99
+ conn , err := utils .ConnectByUrl (ctx , dbURL , options ... )
100
+ if err != nil {
101
+ return nil , err
102
+ }
103
+ defer conn .Close (context .Background ())
104
+ // RLS policies in auth and storage schemas can be included with -s flag
105
+ return migration .ListUserSchemas (ctx , conn )
106
+ }
107
+
108
+ func DiffSchemaMigra (ctx context.Context , source , target string , schema []string , options ... func (* pgx.ConnConfig )) (string , error ) {
84
109
env := []string {"SOURCE=" + source , "TARGET=" + target }
110
+ // node-postgres does not support sslmode=prefer
111
+ if require , err := types .IsRequireSSL (ctx , target , options ... ); err != nil {
112
+ return "" , err
113
+ } else if require {
114
+ rootCA := caStaging + caProd
115
+ env = append (env , "SSL_CA=" + rootCA )
116
+ }
85
117
if len (schema ) > 0 {
86
118
env = append (env , "INCLUDED_SCHEMAS=" + strings .Join (schema , "," ))
87
119
} else {
0 commit comments