Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ jobs:
owner: ${{ github.repository_owner }}
repositories: |
supabase
cli
- run: go run tools/changelog/main.go ${{ secrets.SLACK_CHANNEL }}
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
Expand Down
2 changes: 1 addition & 1 deletion internal/branches/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Run(ctx context.Context, fsys afero.Fs) error {
Branches: branches,
})
case utils.OutputEnv:
return errors.Errorf("--output env flag is not supported")
return errors.New(utils.ErrEnvNotSupported)
}

return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, branches)
Expand Down
1 change: 0 additions & 1 deletion internal/db/reset/reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func TestResetCommand(t *testing.T) {

t.Run("seeds storage after reset", func(t *testing.T) {
utils.DbId = "test-reset"
utils.ConfigId = "test-config"
utils.Config.Db.MajorVersion = 15
// Setup in-memory fs
fsys := afero.NewMemMapFs()
Expand Down
1 change: 0 additions & 1 deletion internal/db/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func NewHostConfig() container.HostConfig {
RestartPolicy: container.RestartPolicy{Name: "always"},
Binds: []string{
utils.DbId + ":/var/lib/postgresql/data",
utils.ConfigId + ":/etc/postgresql-custom",
},
}
if utils.Config.Db.MajorVersion <= 14 {
Expand Down
3 changes: 0 additions & 3 deletions internal/db/start/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func TestStartDatabase(t *testing.T) {
t.Run("initialize main branch", func(t *testing.T) {
utils.Config.Db.MajorVersion = 15
utils.DbId = "supabase_db_test"
utils.ConfigId = "supabase_config_test"
utils.Config.Db.Port = 5432
// Setup in-memory fs
fsys := afero.NewMemMapFs()
Expand Down Expand Up @@ -103,7 +102,6 @@ func TestStartDatabase(t *testing.T) {
t.Run("recover from backup volume", func(t *testing.T) {
utils.Config.Db.MajorVersion = 14
utils.DbId = "supabase_db_test"
utils.ConfigId = "supabase_config_test"
utils.Config.Db.Port = 5432
// Setup in-memory fs
fsys := afero.NewMemMapFs()
Expand Down Expand Up @@ -316,7 +314,6 @@ func TestStartDatabaseWithCustomSettings(t *testing.T) {
// Setup
utils.Config.Db.MajorVersion = 15
utils.DbId = "supabase_db_test"
utils.ConfigId = "supabase_config_test"
utils.Config.Db.Port = 5432
utils.Config.Db.Settings.MaxConnections = cast.Ptr(uint(50))

Expand Down
2 changes: 1 addition & 1 deletion internal/functions/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Run(ctx context.Context, projectRef string, fsys afero.Fs) error {
Functions: *resp.JSON200,
})
case utils.OutputEnv:
return errors.Errorf("--output env flag is not supported")
return errors.New(utils.ErrEnvNotSupported)
}

return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, *resp.JSON200)
Expand Down
1 change: 1 addition & 0 deletions internal/migration/squash/squash.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func Run(ctx context.Context, version string, config pgconn.Config, fsys afero.F
}
// 2. Update migration history
if utils.IsLocalDatabase(config) {
utils.CmdSuggestion = fmt.Sprintf("Run %s to update your remote migration history table.", utils.Aqua("supabase migration repair --status applied"))
return nil
}
if shouldUpdate, err := utils.NewConsole().PromptYesNo(ctx, "Update remote migration history table?", true); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/orgs/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Run(ctx context.Context) error {
Organizations: *resp.JSON200,
})
case utils.OutputEnv:
return errors.Errorf("--output env flag is not supported")
return errors.New(utils.ErrEnvNotSupported)
}

return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, *resp.JSON200)
Expand Down
2 changes: 1 addition & 1 deletion internal/projects/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func Run(ctx context.Context, fsys afero.Fs) error {
Projects: projects,
})
case utils.OutputEnv:
return errors.Errorf("--output env flag is not supported")
return errors.New(utils.ErrEnvNotSupported)
}

return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, projects)
Expand Down
2 changes: 1 addition & 1 deletion internal/secrets/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Run(ctx context.Context, projectRef string, fsys afero.Fs) error {
Secrets: secrets,
})
case utils.OutputEnv:
return errors.Errorf("--output env flag is not supported")
return errors.New(utils.ErrEnvNotSupported)
}

return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, secrets)
Expand Down
2 changes: 2 additions & 0 deletions internal/seed/buckets/buckets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public = false`
bucketPath := filepath.Join(utils.SupabaseDirPath, "images")
require.NoError(t, fsys.Mkdir(bucketPath, 0755))
// Setup mock api
defer gock.OffAll()
gock.New(utils.Config.Api.ExternalUrl).
Get("/storage/v1/bucket").
Reply(http.StatusOK).
Expand All @@ -54,6 +55,7 @@ public = false`

t.Run("ignores unconfigured buckets", func(t *testing.T) {
// Setup mock api
defer gock.OffAll()
gock.New(utils.Config.Api.ExternalUrl).
Get("/storage/v1/bucket").
Reply(http.StatusOK).
Expand Down
23 changes: 15 additions & 8 deletions internal/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/internal/utils/tenant"
"github.com/supabase/cli/pkg/config"
"github.com/supabase/cli/pkg/queue"
)

Expand Down Expand Up @@ -43,7 +44,7 @@ func Run(ctx context.Context, fsys afero.Fs) error {
Services: serviceImages,
})
case utils.OutputEnv:
return errors.Errorf("--output env flag is not supported")
return errors.New(utils.ErrEnvNotSupported)
}

return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, serviceImages)
Expand Down Expand Up @@ -76,39 +77,39 @@ func CheckVersions(ctx context.Context, fsys afero.Fs) []imageVersion {
}

func listRemoteImages(ctx context.Context, projectRef string) map[string]string {
linked := map[string]string{}
keys, err := tenant.GetApiKeys(ctx, projectRef)
if err != nil {
return linked
return nil
}
linked := config.NewConfig()
jq := queue.NewJobQueue(5)
api := tenant.NewTenantAPI(ctx, projectRef, keys.ServiceRole)
jobs := []func() error{
func() error {
version, err := tenant.GetDatabaseVersion(ctx, projectRef)
if err == nil {
linked[utils.Config.Db.Image] = version
linked.Db.Image = version
}
return nil
},
func() error {
version, err := api.GetGotrueVersion(ctx)
if err == nil {
linked[utils.Config.Auth.Image] = version
linked.Auth.Image = version
}
return nil
},
func() error {
version, err := api.GetPostgrestVersion(ctx)
if err == nil {
linked[utils.Config.Api.Image] = version
linked.Api.Image = version
}
return nil
},
func() error {
version, err := api.GetStorageVersion(ctx)
if err == nil {
linked[utils.Config.Storage.Image] = version
linked.Storage.Image = version
}
return err
},
Expand All @@ -123,7 +124,13 @@ func listRemoteImages(ctx context.Context, projectRef string) map[string]string
if err := jq.Collect(); err != nil {
fmt.Fprintln(logger, err)
}
return linked
// Convert to map last to avoid race condition
return map[string]string{
utils.Config.Db.Image: linked.Db.Image,
utils.Config.Auth.Image: linked.Auth.Image,
utils.Config.Api.Image: linked.Api.Image,
utils.Config.Storage.Image: linked.Storage.Image,
}
}

func suggestUpdateCmd(serviceImages map[string]string) string {
Expand Down
139 changes: 139 additions & 0 deletions internal/services/services_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package services

import (
"context"
"net/http"
"testing"

"github.com/h2non/gock"
"github.com/oapi-codegen/nullable"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/supabase/cli/internal/testing/apitest"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/internal/utils/tenant"
"github.com/supabase/cli/pkg/api"
)

func TestServicesCommand(t *testing.T) {
t.Run("output pretty", func(t *testing.T) {
utils.OutputFormat.Value = utils.OutputPretty
// Run test
err := Run(context.Background(), afero.NewMemMapFs())
// Check error
assert.NoError(t, err)
})

t.Run("output toml", func(t *testing.T) {
utils.OutputFormat.Value = utils.OutputToml
// Run test
err := Run(context.Background(), afero.NewMemMapFs())
// Check error
assert.NoError(t, err)
})

t.Run("output json", func(t *testing.T) {
utils.OutputFormat.Value = utils.OutputJson
// Run test
err := Run(context.Background(), afero.NewMemMapFs())
// Check error
assert.NoError(t, err)
})

t.Run("output env", func(t *testing.T) {
utils.OutputFormat.Value = utils.OutputEnv
// Run test
err := Run(context.Background(), afero.NewMemMapFs())
// Check error
assert.ErrorIs(t, err, utils.ErrEnvNotSupported)
})
}

func TestCheckVersions(t *testing.T) {
// Setup valid access token
token := apitest.RandomAccessToken(t)
t.Setenv("SUPABASE_ACCESS_TOKEN", string(token))
// Setup valid project ref
flags.ProjectRef = apitest.RandomProjectRef()
projectHost := "https://" + utils.GetSupabaseHost(flags.ProjectRef)
// Setup mock project
mockProject := api.V1ProjectWithDatabaseResponse{}
mockProject.Database.Version = "14.1.0.99"

t.Run("diff service versions", func(t *testing.T) {
// Setup mock api
defer gock.OffAll()
gock.New(utils.DefaultApiHost).
Get("/v1/projects/" + flags.ProjectRef + "/api-keys").
Reply(http.StatusOK).
JSON([]api.ApiKeyResponse{{
Name: "service_role",
ApiKey: nullable.NewNullableWithValue("service-key"),
}})
gock.New(utils.DefaultApiHost).
Get("/v1/projects/" + flags.ProjectRef).
Reply(http.StatusOK).
JSON(mockProject)
// Mock service versions
gock.New(projectHost).
Get("/auth/v1/health").
Reply(http.StatusOK).
JSON(tenant.HealthResponse{Version: "v2.74.2"})
gock.New(projectHost).
Get("/rest/v1/").
Reply(http.StatusOK).
JSON(tenant.SwaggerResponse{Info: tenant.SwaggerInfo{Version: "11.1.0"}})
gock.New(projectHost).
Get("/storage/v1/version").
Reply(http.StatusOK).
BodyString("1.28.0")
// Run test
images := CheckVersions(context.Background(), afero.NewMemMapFs())
// Check error
assert.Equal(t, len(images), 10)
for _, img := range images {
assert.NotEqual(t, img.Local, img.Remote)
}
assert.Empty(t, apitest.ListUnmatchedRequests())
})

t.Run("list remote images", func(t *testing.T) {
// Setup mock api
defer gock.OffAll()
gock.New(utils.DefaultApiHost).
Get("/v1/projects/" + flags.ProjectRef + "/api-keys").
Reply(http.StatusOK).
JSON([]api.ApiKeyResponse{{
Name: "service_role",
ApiKey: nullable.NewNullableWithValue("service-key"),
}})
gock.New(utils.DefaultApiHost).
Get("/v1/projects/" + flags.ProjectRef).
Reply(http.StatusOK).
JSON(mockProject)
// Mock service versions
gock.New(projectHost).
Get("/auth/v1/health").
Reply(http.StatusOK).
JSON(tenant.HealthResponse{Version: "v2.74.2"})
gock.New(projectHost).
Get("/rest/v1/").
Reply(http.StatusOK).
JSON(tenant.SwaggerResponse{Info: tenant.SwaggerInfo{Version: "11.1.0"}})
gock.New(projectHost).
Get("/storage/v1/version").
Reply(http.StatusOK).
BodyString("1.28.0")
// Run test
images := listRemoteImages(context.Background(), flags.ProjectRef)
// Check error
assert.Equal(t, images, map[string]string{
utils.Config.Db.Image: "14.1.0.99",
utils.Config.Auth.Image: "v2.74.2",
utils.Config.Api.Image: "v11.1.0",
utils.Config.Storage.Image: "v1.28.0",
})
assert.Empty(t, apitest.ListUnmatchedRequests())
})
}
2 changes: 1 addition & 1 deletion internal/snippets/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Run(ctx context.Context, fsys afero.Fs) error {
}
return utils.RenderTable(table)
case utils.OutputEnv:
return errors.Errorf("--output env flag is not supported")
return errors.New(utils.ErrEnvNotSupported)
}

return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, *resp.JSON200)
Expand Down
2 changes: 1 addition & 1 deletion internal/sso/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Run(ctx context.Context, ref, providerId, format string) error {
case utils.OutputPretty:
return render.SingleMarkdown(*resp.JSON200)
case utils.OutputEnv:
return errors.Errorf("--output env flag is not supported")
return errors.New(utils.ErrEnvNotSupported)
default:
return utils.EncodeOutput(format, os.Stdout, resp.JSON200)
}
Expand Down
2 changes: 0 additions & 2 deletions internal/start/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func TestDatabaseStart(t *testing.T) {
}
// Start postgres
utils.DbId = "test-postgres"
utils.ConfigId = "test-config"
utils.Config.Db.Port = 54322
utils.Config.Db.MajorVersion = 15
gock.New(utils.Docker.DaemonHost()).
Expand Down Expand Up @@ -230,7 +229,6 @@ func TestDatabaseStart(t *testing.T) {
JSON(image.InspectResponse{})
// Start postgres
utils.DbId = "test-postgres"
utils.ConfigId = "test-config"
utils.Config.Db.Port = 54322
utils.Config.Db.MajorVersion = 15
gock.New(utils.Docker.DaemonHost()).
Expand Down
2 changes: 0 additions & 2 deletions internal/stop/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ func TestStopServices(t *testing.T) {

t.Run("removes data volumes", func(t *testing.T) {
utils.DbId = "test-db"
utils.ConfigId = "test-config"
utils.StorageId = "test-storage"
utils.EdgeRuntimeId = "test-functions"
utils.InbucketId = "test-inbucket"
Expand All @@ -208,7 +207,6 @@ func TestStopServices(t *testing.T) {

t.Run("skips all filter when removing data volumes with Docker version pre-v1.42", func(t *testing.T) {
utils.DbId = "test-db"
utils.ConfigId = "test-config"
utils.StorageId = "test-storage"
utils.EdgeRuntimeId = "test-functions"
utils.InbucketId = "test-inbucket"
Expand Down
Loading