From c490984f4f83306c6c27938f02cdde3d5a4308ee Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Sat, 7 Dec 2024 18:32:52 +0800 Subject: [PATCH] fix: account for remote config when pushing --- internal/db/reset/reset.go | 19 ++++++++++++++++++- internal/functions/deploy/deploy.go | 7 +++++-- internal/gen/types/types.go | 3 ++- internal/seed/buckets/buckets.go | 5 +++-- internal/storage/cp/cp.go | 3 ++- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/internal/db/reset/reset.go b/internal/db/reset/reset.go index a475ca80d..efcf26e11 100644 --- a/internal/db/reset/reset.go +++ b/internal/db/reset/reset.go @@ -23,9 +23,11 @@ import ( "github.com/supabase/cli/internal/db/start" "github.com/supabase/cli/internal/gen/keys" "github.com/supabase/cli/internal/migration/apply" + "github.com/supabase/cli/internal/migration/list" "github.com/supabase/cli/internal/migration/repair" "github.com/supabase/cli/internal/seed/buckets" "github.com/supabase/cli/internal/utils" + "github.com/supabase/cli/internal/utils/flags" "github.com/supabase/cli/pkg/migration" ) @@ -241,7 +243,22 @@ func resetRemote(ctx context.Context, version string, config pgconn.Config, fsys if err := migration.DropUserSchemas(ctx, conn); err != nil { return err } - return apply.MigrateAndSeed(ctx, version, conn, fsys) + migrations, err := list.LoadPartialMigrations(version, fsys) + if err != nil { + return err + } + if err := migration.ApplyMigrations(ctx, migrations, conn, afero.NewIOFS(fsys)); err != nil { + return err + } + remote, _ := utils.Config.GetRemoteByProjectRef(flags.ProjectRef) + if !utils.Config.Db.Seed.Enabled || !remote.Db.Seed.Enabled { + return nil + } + seeds, err := migration.GetPendingSeeds(ctx, remote.Db.Seed.SqlPaths, conn, afero.NewIOFS(fsys)) + if err != nil { + return err + } + return migration.SeedData(ctx, seeds, conn, afero.NewIOFS(fsys)) } func LikeEscapeSchema(schemas []string) (result []string) { diff --git a/internal/functions/deploy/deploy.go b/internal/functions/deploy/deploy.go index 6713d47d3..529b78976 100644 --- a/internal/functions/deploy/deploy.go +++ b/internal/functions/deploy/deploy.go @@ -10,6 +10,7 @@ import ( "github.com/go-errors/errors" "github.com/spf13/afero" "github.com/supabase/cli/internal/utils" + "github.com/supabase/cli/internal/utils/flags" "github.com/supabase/cli/pkg/cast" "github.com/supabase/cli/pkg/config" "github.com/supabase/cli/pkg/function" @@ -59,7 +60,8 @@ func GetFunctionSlugs(fsys afero.Fs) (slugs []string, err error) { } } // Add all function slugs declared in config file - for slug := range utils.Config.Functions { + remote, _ := utils.Config.GetRemoteByProjectRef(flags.ProjectRef) + for slug := range remote.Functions { slugs = append(slugs, slug) } return slugs, nil @@ -78,9 +80,10 @@ func GetFunctionConfig(slugs []string, importMapPath string, noVerifyJWT *bool, if len(importMapPath) > 0 && !filepath.IsAbs(importMapPath) { importMapPath = filepath.Join(utils.CurrentDirAbs, importMapPath) } + remote, _ := utils.Config.GetRemoteByProjectRef(flags.ProjectRef) functionConfig := make(config.FunctionConfig, len(slugs)) for _, name := range slugs { - function := utils.Config.Functions[name] + function := remote.Functions[name] // Precedence order: flag > config > fallback functionDir := filepath.Join(utils.FunctionsDir, name) if len(function.Entrypoint) == 0 { diff --git a/internal/gen/types/types.go b/internal/gen/types/types.go index 9ffc7dc72..b399cfb5c 100644 --- a/internal/gen/types/types.go +++ b/internal/gen/types/types.go @@ -31,7 +31,8 @@ func Run(ctx context.Context, projectId string, dbConfig pgconn.Config, lang str originalURL := utils.ToPostgresURL(dbConfig) // Add default schemas if --schema flag is not specified if len(schemas) == 0 { - schemas = utils.RemoveDuplicates(append([]string{"public"}, utils.Config.Api.Schemas...)) + remote, _ := utils.Config.GetRemoteByProjectRef(projectId) + schemas = utils.RemoveDuplicates(append([]string{"public"}, remote.Api.Schemas...)) } included := strings.Join(schemas, ",") diff --git a/internal/seed/buckets/buckets.go b/internal/seed/buckets/buckets.go index 365c3a395..b460fdc79 100644 --- a/internal/seed/buckets/buckets.go +++ b/internal/seed/buckets/buckets.go @@ -26,8 +26,9 @@ func Run(ctx context.Context, projectRef string, interactive bool, fsys afero.Fs } return shouldOverwrite } - if err := api.UpsertBuckets(ctx, utils.Config.Storage.Buckets, filter); err != nil { + remote, _ := utils.Config.GetRemoteByProjectRef(projectRef) + if err := api.UpsertBuckets(ctx, remote.Storage.Buckets, filter); err != nil { return err } - return api.UpsertObjects(ctx, utils.Config.Storage.Buckets, utils.NewRootFS(fsys)) + return api.UpsertObjects(ctx, remote.Storage.Buckets, utils.NewRootFS(fsys)) } diff --git a/internal/storage/cp/cp.go b/internal/storage/cp/cp.go index 8aed7a6fa..e55120a1c 100644 --- a/internal/storage/cp/cp.go +++ b/internal/storage/cp/cp.go @@ -115,6 +115,7 @@ func UploadStorageObjectAll(ctx context.Context, api storage.StorageAPI, remoteP return err } } + remote, _ := utils.Config.GetRemoteByProjectRef(flags.ProjectRef) // Overwrites existing object when using --recursive flag opts = append(opts, func(fo *storage.FileOptions) { fo.Overwrite = true @@ -153,7 +154,7 @@ func UploadStorageObjectAll(ctx context.Context, api storage.StorageAPI, remoteP // Retry after creating bucket if bucket, prefix := client.SplitBucketPrefix(dstPath); len(prefix) > 0 { body := storage.CreateBucketRequest{Name: bucket} - if config, ok := utils.Config.Storage.Buckets[bucket]; ok { + if config, ok := remote.Storage.Buckets[bucket]; ok { body.Public = config.Public body.FileSizeLimit = int64(config.FileSizeLimit) body.AllowedMimeTypes = config.AllowedMimeTypes