@@ -9,10 +9,12 @@ import (
99 "github.com/docker/docker/api/types/container"
1010 "github.com/docker/docker/api/types/network"
1111 "github.com/go-errors/errors"
12+ "github.com/jackc/pgx/v4"
1213 "github.com/spf13/viper"
1314 "github.com/supabase/cli/internal/gen/types"
1415 "github.com/supabase/cli/internal/utils"
1516 "github.com/supabase/cli/pkg/config"
17+ "github.com/supabase/cli/pkg/migration"
1618)
1719
1820var (
6062)
6163
6264// Diffs local database schema against shadow, dumps output to stdout.
63- 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+ }
6473 env := []string {"SOURCE=" + source , "TARGET=" + target }
6574 // Passing in script string means command line args must be set manually, ie. "$@"
6675 args := "set -- " + strings .Join (schema , " " ) + ";"
@@ -86,10 +95,20 @@ func DiffSchemaMigraBash(ctx context.Context, source, target string, schema []st
8695 return out .String (), nil
8796}
8897
89- 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 ) {
90109 env := []string {"SOURCE=" + source , "TARGET=" + target }
91110 // node-postgres does not support sslmode=prefer
92- if require , err := types .IsRequireSSL (ctx , target ); err != nil {
111+ if require , err := types .IsRequireSSL (ctx , target , options ... ); err != nil {
93112 return "" , err
94113 } else if require {
95114 rootCA := caStaging + caProd
0 commit comments