Skip to content

Commit

Permalink
fix: account for remote config when pushing
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Dec 7, 2024
1 parent 8b60145 commit c490984
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
19 changes: 18 additions & 1 deletion internal/db/reset/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions internal/functions/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion internal/gen/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ",")

Expand Down
5 changes: 3 additions & 2 deletions internal/seed/buckets/buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
3 changes: 2 additions & 1 deletion internal/storage/cp/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c490984

Please sign in to comment.