From c22a03eafc2234707b810ccd6775a4ae5f9aabfc Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Thu, 21 Sep 2023 00:47:34 +0800 Subject: [PATCH 01/11] fix: disable keyring on wsl (#1509) --- internal/utils/credentials/store.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/internal/utils/credentials/store.go b/internal/utils/credentials/store.go index 98a954e40..70ad37286 100644 --- a/internal/utils/credentials/store.go +++ b/internal/utils/credentials/store.go @@ -1,6 +1,10 @@ package credentials import ( + "bytes" + "errors" + "os" + "github.com/zalando/go-keyring" ) @@ -8,15 +12,32 @@ const namespace = "Supabase CLI" // Retrieves the stored password of a project and username func Get(project string) (string, error) { + if err := assertKeyringSupported(); err != nil { + return "", err + } return keyring.Get(namespace, project) } // Stores the password of a project and username func Set(project, password string) error { + if err := assertKeyringSupported(); err != nil { + return err + } return keyring.Set(namespace, project, password) } // Erases the stored password of a project and username func Delete(project string) error { + if err := assertKeyringSupported(); err != nil { + return err + } return keyring.Delete(namespace, project) } + +func assertKeyringSupported() error { + // Suggested check: https://github.com/microsoft/WSL/issues/423 + if f, err := os.ReadFile("/proc/sys/kernel/osrelease"); err == nil && bytes.Contains(f, []byte("WSL")) { + return errors.New("Keyring is not supported on WSL") + } + return nil +} From 9a5eb4814b543e0c8eeb7cd0b129cda05cc76b64 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Thu, 21 Sep 2023 15:34:02 +0800 Subject: [PATCH 02/11] fix(pooler): pin pgbouncer image to an immutable tag (#1511) --- internal/start/start.go | 6 ++++-- internal/utils/misc.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/start/start.go b/internal/start/start.go index aba17b99f..3a5ab6bb1 100644 --- a/internal/start/start.go +++ b/internal/start/start.go @@ -770,10 +770,12 @@ EOF Image: utils.PgbouncerImage, Env: []string{ "POSTGRESQL_HOST=" + dbConfig.Host, - "POSTGRESQL_NAME=" + dbConfig.Database, - "POSTGRESQL_USER=" + dbConfig.User, fmt.Sprintf("POSTGRESQL_PORT=%d", dbConfig.Port), + "POSTGRESQL_USERNAME=pgbouncer", "POSTGRESQL_PASSWORD=" + dbConfig.Password, + "POSTGRESQL_DATABASE=" + dbConfig.Database, + "PGBOUNCER_AUTH_USER=pgbouncer", + "PGBOUNCER_AUTH_QUERY=SELECT * FROM pgbouncer.get_auth($1)", fmt.Sprintf("PGBOUNCER_POOL_MODE=%s", utils.Config.Db.Pooler.PoolMode), fmt.Sprintf("PGBOUNCER_DEFAULT_POOL_SIZE=%d", utils.Config.Db.Pooler.DefaultPoolSize), fmt.Sprintf("PGBOUNCER_MAX_CLIENT_CONN=%d", utils.Config.Db.Pooler.MaxClientConn), diff --git a/internal/utils/misc.go b/internal/utils/misc.go index 1894c2e0b..278e115f2 100644 --- a/internal/utils/misc.go +++ b/internal/utils/misc.go @@ -35,7 +35,7 @@ const ( ImageProxyImage = "darthsim/imgproxy:v3.8.0" EdgeRuntimeImage = "supabase/edge-runtime:v1.18.1" VectorImage = "timberio/vector:0.28.1-alpine" - PgbouncerImage = "bitnami/pgbouncer:1.20.1" + PgbouncerImage = "bitnami/pgbouncer:1.20.1-debian-11-r39" GotrueImage = "supabase/gotrue:v2.92.1" RealtimeImage = "supabase/realtime:v2.10.1" StorageImage = "supabase/storage-api:v0.40.4" From f6c64d71a36a64f6a2ce0616094dbcbb1eab9e38 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Sep 2023 04:42:02 +0000 Subject: [PATCH 03/11] chore(deps): bump google.golang.org/grpc from 1.58.1 to 1.58.2 (#1516) Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.58.1 to 1.58.2. - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.58.1...v1.58.2) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index abe2c0244..60933497b 100644 --- a/go.mod +++ b/go.mod @@ -174,7 +174,7 @@ require ( golang.org/x/sys v0.12.0 // indirect golang.org/x/term v0.12.0 golang.org/x/text v0.13.0 // indirect - google.golang.org/grpc v1.58.1 + google.golang.org/grpc v1.58.2 google.golang.org/protobuf v1.31.0 // indirect gopkg.in/h2non/gock.v1 v1.1.2 gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/go.sum b/go.sum index 60432ab97..b8c753bb3 100644 --- a/go.sum +++ b/go.sum @@ -1067,8 +1067,8 @@ google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.58.1 h1:OL+Vz23DTtrrldqHK49FUOPHyY75rvFqJfXC84NYW58= -google.golang.org/grpc v1.58.1/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= +google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= From 19047ef1827376ab42c3382b5ea0a4c1d4504b17 Mon Sep 17 00:00:00 2001 From: Joshen Lim Date: Fri, 22 Sep 2023 16:50:08 +0800 Subject: [PATCH 04/11] fix(studio): bump studio image to 20230921 (#1517) --- internal/utils/misc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/utils/misc.go b/internal/utils/misc.go index 278e115f2..6dccdd06a 100644 --- a/internal/utils/misc.go +++ b/internal/utils/misc.go @@ -31,7 +31,7 @@ const ( DifferImage = "supabase/pgadmin-schema-diff:cli-0.0.5" MigraImage = "djrobstep/migra:3.0.1621480950" PgmetaImage = "supabase/postgres-meta:v0.68.0" - StudioImage = "supabase/studio:20230912-748fd33" + StudioImage = "supabase/studio:20230921-d657f29" ImageProxyImage = "darthsim/imgproxy:v3.8.0" EdgeRuntimeImage = "supabase/edge-runtime:v1.18.1" VectorImage = "timberio/vector:0.28.1-alpine" From d22289b82a244b2379e2534808c13294173ebb78 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Fri, 22 Sep 2023 02:51:12 -0600 Subject: [PATCH 05/11] fix(db): bump PG15 to 15.1.0.117 (#1512) * chore: bump pg15 to 15.1.0.118 * chore: bump pg15 to 15.1.0.117 instead --- internal/utils/misc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/utils/misc.go b/internal/utils/misc.go index 6dccdd06a..124c200cb 100644 --- a/internal/utils/misc.go +++ b/internal/utils/misc.go @@ -23,7 +23,7 @@ var Version string const ( Pg13Image = "supabase/postgres:13.3.0" Pg14Image = "supabase/postgres:14.1.0.89" - Pg15Image = "supabase/postgres:15.1.0.103" + Pg15Image = "supabase/postgres:15.1.0.117" // Append to ServiceImages when adding new dependencies below KongImage = "library/kong:2.8.1" InbucketImage = "inbucket/inbucket:3.0.3" From 52e825ad9ad360a41f20f202a10de7360606c4de Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Mon, 25 Sep 2023 09:07:45 +0800 Subject: [PATCH 06/11] fix(db): use idempotent statements when dumping triggers (#1522) --- internal/db/dump/templates/dump_schema.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/db/dump/templates/dump_schema.sh b/internal/db/dump/templates/dump_schema.sh index 3f1265c9c..72b3e6f46 100755 --- a/internal/db/dump/templates/dump_schema.sh +++ b/internal/db/dump/templates/dump_schema.sh @@ -26,6 +26,7 @@ pg_dump \ | sed -E 's/^CREATE SEQUENCE "/CREATE SEQUENCE IF NOT EXISTS "/' \ | sed -E 's/^CREATE VIEW "/CREATE OR REPLACE VIEW "/' \ | sed -E 's/^CREATE FUNCTION "/CREATE OR REPLACE FUNCTION "/' \ +| sed -E 's/^CREATE TRIGGER "/CREATE OR REPLACE TRIGGER "/' \ | sed -E 's/^ALTER DEFAULT PRIVILEGES FOR ROLE "supabase_admin"/-- &/' \ | sed -E "s/^GRANT (.+) ON (.+) \"(${EXCLUDED_SCHEMAS:-})\"/-- &/" \ | sed -E "s/^REVOKE (.+) ON (.+) \"(${EXCLUDED_SCHEMAS:-})\"/-- &/" \ From 752ff375ad3c0f6c7329017e3aa1ed73d043b681 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Sep 2023 04:11:21 +0000 Subject: [PATCH 07/11] chore(deps): bump github.com/spf13/afero from 1.9.5 to 1.10.0 (#1523) Bumps [github.com/spf13/afero](https://github.com/spf13/afero) from 1.9.5 to 1.10.0. - [Release notes](https://github.com/spf13/afero/releases) - [Commits](https://github.com/spf13/afero/compare/v1.9.5...v1.10.0) --- updated-dependencies: - dependency-name: github.com/spf13/afero dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 60933497b..e907fdc4d 100644 --- a/go.mod +++ b/go.mod @@ -160,7 +160,7 @@ require ( github.com/rivo/uniseg v0.4.4 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/slack-go/slack v0.12.3 - github.com/spf13/afero v1.9.5 + github.com/spf13/afero v1.10.0 github.com/spf13/cast v1.5.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index b8c753bb3..12d591e4f 100644 --- a/go.sum +++ b/go.sum @@ -614,8 +614,8 @@ github.com/skeema/knownhosts v1.2.0 h1:h9r9cf0+u7wSE+M183ZtMGgOJKiL96brpaz5ekfJC github.com/skeema/knownhosts v1.2.0/go.mod h1:g4fPeYpque7P0xefxtGzV81ihjC8sX2IqpAoNkjxbMo= github.com/slack-go/slack v0.12.3 h1:92/dfFU8Q5XP6Wp5rr5/T5JHLM5c5Smtn53fhToAP88= github.com/slack-go/slack v0.12.3/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw= -github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= -github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= +github.com/spf13/afero v1.10.0 h1:EaGW2JJh15aKOejeuJ+wpFSHnbd7GE6Wvp3TsNhb6LY= +github.com/spf13/afero v1.10.0/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spf13/cast v0.0.0-20150508191742-4d07383ffe94/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgKEg= github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= From f18ad1683402f4c3c3faeba50d96ea1979895803 Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Fri, 29 Sep 2023 15:22:41 +0800 Subject: [PATCH 08/11] fix: use npm proxy config for node fetch --- package.json | 2 +- scripts/postinstall.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 6170e9748..324646a38 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "dependencies": { "bin-links": "^4.0.1", "node-fetch": "^3.2.10", - "proxy-agent": "^6.3.1", + "https-proxy-agent": "^7.0.2", "tar": "6.2.0" }, "release": { diff --git a/scripts/postinstall.js b/scripts/postinstall.js index 8d026666b..c3d64e00b 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -8,7 +8,7 @@ import binLinks from "bin-links"; import { createHash } from "crypto"; import fs from "fs"; import fetch from "node-fetch"; -import { ProxyAgent } from "proxy-agent"; +import { HttpsProxyAgent } from "https-proxy-agent"; import path from "path"; import tar from "tar"; import zlib from "zlib"; @@ -124,7 +124,11 @@ async function main() { const untar = tar.x({ cwd: binDir }, [binName]); console.info("Downloading", url); - const agent = new ProxyAgent(); + const proxyUrl = + process.env.npm_config_https_proxy || + process.env.npm_config_http_proxy || + process.env.npm_config_proxy; + const agent = proxyUrl ? new HttpsProxyAgent(proxyUrl) : undefined; const resp = await fetch(url, { agent }); const hash = createHash("sha256"); From bb1ccde7a81f88bc4db16fec7d277ffd933edcb2 Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Fri, 29 Sep 2023 16:32:52 +0800 Subject: [PATCH 09/11] chore: update ci scripts --- .github/workflows/codeql-analysis.yml | 5 +---- .github/workflows/install.yml | 3 +++ scripts/postinstall.js | 0 3 files changed, 4 insertions(+), 4 deletions(-) mode change 100644 => 100755 scripts/postinstall.js diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 38ba0e98a..65b6f563a 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -12,11 +12,8 @@ name: "CodeQL" on: - push: - branches: - - main pull_request: - # The branches below must be a subset of the branches above + push: branches: - main diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index 9c035a75d..5605acd6b 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -7,6 +7,8 @@ on: - 'package.json' - 'scripts/**' push: + branches: + - main paths: - '.github/workflows/install.yml' - 'package.json' @@ -31,6 +33,7 @@ jobs: install: needs: pack strategy: + fail-fast: false matrix: pm: [npm, yarn, pnpm] os: [ubuntu-latest, macos-latest, windows-latest] diff --git a/scripts/postinstall.js b/scripts/postinstall.js old mode 100644 new mode 100755 From e59da80c98ea16ed5e6c129698622d14c8e617d8 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Mon, 2 Oct 2023 11:58:20 +0800 Subject: [PATCH 10/11] feat: sync database version with remote pg15 project (#1535) --- internal/link/link.go | 25 +++++++++++++--- internal/link/link_test.go | 51 +++++++++++++++++++++++++-------- internal/utils/config.go | 4 +++ internal/utils/misc.go | 1 + internal/utils/tenant/client.go | 4 +-- 5 files changed, 67 insertions(+), 18 deletions(-) diff --git a/internal/link/link.go b/internal/link/link.go index dee5e84c1..881c730f6 100644 --- a/internal/link/link.go +++ b/internal/link/link.go @@ -2,7 +2,6 @@ package link import ( "context" - "errors" "fmt" "io" "os" @@ -16,6 +15,7 @@ import ( "github.com/jackc/pgx/v4" "github.com/spf13/afero" "github.com/supabase/cli/internal/migration/repair" + "github.com/supabase/cli/internal/services" "github.com/supabase/cli/internal/utils" "github.com/supabase/cli/internal/utils/credentials" "github.com/supabase/cli/internal/utils/tenant" @@ -87,7 +87,13 @@ func PostRun(projectRef string, stdout io.Writer, fsys afero.Fs) error { func linkServices(ctx context.Context, projectRef string, fsys afero.Fs) { // Ignore non-fatal errors linking services var wg sync.WaitGroup - wg.Add(4) + wg.Add(5) + go func() { + defer wg.Done() + if err := linkDatabaseVersion(ctx, projectRef, fsys); err != nil { + fmt.Fprintln(os.Stderr, err) + } + }() go func() { defer wg.Done() if err := linkPostgrest(ctx, projectRef); err != nil { @@ -121,7 +127,7 @@ func linkPostgrest(ctx context.Context, projectRef string) error { return err } if resp.JSON200 == nil { - return errors.New("Authorization failed for the access token and project ref pair: " + string(resp.Body)) + return fmt.Errorf("%w: %s", tenant.ErrAuthToken, string(resp.Body)) } updateApiConfig(*resp.JSON200) return nil @@ -185,6 +191,17 @@ func linkDatabase(ctx context.Context, config pgconn.Config, options ...func(*pg return repair.CreateMigrationTable(ctx, conn) } +func linkDatabaseVersion(ctx context.Context, projectRef string, fsys afero.Fs) error { + version, err := services.GetDatabaseVersion(ctx, projectRef) + if err != nil { + return err + } + if err := utils.MkdirIfNotExistFS(fsys, filepath.Dir(utils.PostgresVersionPath)); err != nil { + return err + } + return afero.WriteFile(fsys, utils.PostgresVersionPath, []byte(version), 0644) +} + func updatePostgresConfig(conn *pgx.Conn) { serverVersion := conn.PgConn().ParameterStatus("server_version") // Safe to assume that supported Postgres version is 10.0 <= n < 100.0 @@ -207,7 +224,7 @@ func linkPooler(ctx context.Context, projectRef string) error { return err } if resp.JSON200 == nil { - return errors.New("Authorization failed for the access token and project ref pair: " + string(resp.Body)) + return fmt.Errorf("%w: %s", tenant.ErrAuthToken, string(resp.Body)) } updatePoolerConfig(*resp.JSON200) return nil diff --git a/internal/link/link_test.go b/internal/link/link_test.go index 1b4ff7d87..ae57248ce 100644 --- a/internal/link/link_test.go +++ b/internal/link/link_test.go @@ -3,7 +3,6 @@ package link import ( "context" "errors" - "fmt" "os" "strings" "testing" @@ -134,6 +133,11 @@ func TestLinkCommand(t *testing.T) { Reply("ALTER TABLE") // Flush pending mocks after test execution defer gock.OffAll() + gock.New(utils.DefaultApiHost). + Get("/v1/projects/" + project + "/api-keys"). + Reply(200). + JSON([]api.ApiKeyResponse{{Name: "anon", ApiKey: "anon-key"}}) + // Link configs gock.New(utils.DefaultApiHost). Get("/v1/projects/" + project + "/postgrest"). Reply(200). @@ -142,20 +146,34 @@ func TestLinkCommand(t *testing.T) { Get("/v1/projects/" + project + "/config/database/pgbouncer"). Reply(200). JSON(api.V1PgbouncerConfigResponse{}) - gock.New(utils.DefaultApiHost). - Get("/v1/projects/" + project + "/api-keys"). - Reply(200). - JSON([]api.ApiKeyResponse{{Name: "anon", ApiKey: "anon-key"}}) + // Link versions rest := tenant.SwaggerResponse{Info: tenant.SwaggerInfo{Version: "11.1.0"}} - gock.New(fmt.Sprintf("https://%s.supabase.co", project)). + gock.New("https://" + utils.GetSupabaseHost(project)). Get("/rest/v1/"). Reply(200). JSON(rest) auth := tenant.HealthResponse{Version: "v2.74.2"} - gock.New(fmt.Sprintf("https://%s.supabase.co", project)). + gock.New("https://" + utils.GetSupabaseHost(project)). Get("/auth/v1/health"). Reply(200). JSON(auth) + postgres := api.DatabaseResponse{ + Host: utils.GetSupabaseDbHost(project), + Version: "15.1.0.117", + } + gock.New(utils.DefaultApiHost). + Get("/v1/projects"). + Reply(200). + JSON([]api.ProjectResponse{ + { + Id: project, + Database: &postgres, + OrganizationId: "combined-fuchsia-lion", + Name: "Test Project", + Region: "us-west-1", + CreatedAt: "2022-04-25T02:14:55.906498Z", + }, + }) // Run test err := Run(context.Background(), project, dbConfig.Password, fsys, conn.Intercept) // Check error @@ -171,6 +189,9 @@ func TestLinkCommand(t *testing.T) { authVersion, err := afero.ReadFile(fsys, utils.GotrueVersionPath) assert.NoError(t, err) assert.Equal(t, []byte(auth.Version), authVersion) + postgresVersion, err := afero.ReadFile(fsys, utils.PostgresVersionPath) + assert.NoError(t, err) + assert.Equal(t, []byte(postgres.Version), postgresVersion) }) t.Run("throws error on network failure", func(t *testing.T) { @@ -206,12 +227,15 @@ func TestLinkCommand(t *testing.T) { Get("/v1/projects/" + project + "/config/database/pgbouncer"). ReplyError(errors.New("network error")) // Link versions - gock.New(fmt.Sprintf("https://%s.supabase.co", project)). + gock.New("https://" + utils.GetSupabaseHost(project)). Get("/auth/v1/health"). ReplyError(errors.New("network error")) - gock.New(fmt.Sprintf("https://%s.supabase.co", project)). + gock.New("https://" + utils.GetSupabaseHost(project)). Get("/rest/v1/"). ReplyError(errors.New("network error")) + gock.New(utils.DefaultApiHost). + Get("/v1/projects"). + ReplyError(errors.New("network error")) // Run test err := Run(context.Background(), project, dbConfig.Password, fsys, func(cc *pgx.ConnConfig) { cc.LookupFunc = func(ctx context.Context, host string) (addrs []string, err error) { @@ -241,12 +265,15 @@ func TestLinkCommand(t *testing.T) { Get("/v1/projects/" + project + "/config/database/pgbouncer"). ReplyError(errors.New("network error")) // Link versions - gock.New(fmt.Sprintf("https://%s.supabase.co", project)). + gock.New("https://" + utils.GetSupabaseHost(project)). Get("/auth/v1/health"). ReplyError(errors.New("network error")) - gock.New(fmt.Sprintf("https://%s.supabase.co", project)). + gock.New("https://" + utils.GetSupabaseHost(project)). Get("/rest/v1/"). ReplyError(errors.New("network error")) + gock.New(utils.DefaultApiHost). + Get("/v1/projects"). + ReplyError(errors.New("network error")) // Run test err := Run(context.Background(), project, "", fsys) // Check error @@ -331,7 +358,7 @@ func TestLinkPostgrest(t *testing.T) { // Run test err := linkPostgrest(context.Background(), project) // Validate api - assert.ErrorContains(t, err, `Authorization failed for the access token and project ref pair: {"message":"unavailable"}`) + assert.ErrorIs(t, err, tenant.ErrAuthToken) assert.Empty(t, apitest.ListUnmatchedRequests()) }) } diff --git a/internal/utils/config.go b/internal/utils/config.go index f2e72241c..e1d1c31a1 100644 --- a/internal/utils/config.go +++ b/internal/utils/config.go @@ -400,6 +400,10 @@ func LoadConfigFS(fsys afero.Fs) error { Config.Db.Image = Pg14Image InitialSchemaSql = InitialSchemaPg14Sql case 15: + if version, err := afero.ReadFile(fsys, PostgresVersionPath); err == nil && len(version) > 0 { + index := strings.IndexByte(Pg15Image, ':') + Config.Db.Image = Pg15Image[:index+1] + string(version) + } default: return fmt.Errorf("Failed reading config: Invalid %s: %v.", Aqua("db.major_version"), Config.Db.MajorVersion) } diff --git a/internal/utils/misc.go b/internal/utils/misc.go index 124c200cb..b760b178c 100644 --- a/internal/utils/misc.go +++ b/internal/utils/misc.go @@ -166,6 +166,7 @@ var ( ImportMapsDir = filepath.Join(SupabaseDirPath, TempDir, "import_maps") ProjectRefPath = filepath.Join(SupabaseDirPath, TempDir, "project-ref") RemoteDbPath = filepath.Join(SupabaseDirPath, TempDir, "remote-db-url") + PostgresVersionPath = filepath.Join(SupabaseDirPath, TempDir, "postgres-version") GotrueVersionPath = filepath.Join(SupabaseDirPath, TempDir, "gotrue-version") RestVersionPath = filepath.Join(SupabaseDirPath, TempDir, "rest-version") CurrBranchPath = filepath.Join(SupabaseDirPath, ".branches", "_current_branch") diff --git a/internal/utils/tenant/client.go b/internal/utils/tenant/client.go index 9397ea8fd..9434d34cf 100644 --- a/internal/utils/tenant/client.go +++ b/internal/utils/tenant/client.go @@ -16,7 +16,7 @@ var ( apiKey ApiKey keyOnce sync.Once - errAuthToken = errors.New("Authorization failed for the access token and project ref pair") + ErrAuthToken = errors.New("Authorization failed for the access token and project ref pair") errMissingKey = errors.New("Anon key not found.") ) @@ -38,7 +38,7 @@ func GetApiKeys(ctx context.Context, projectRef string) (ApiKey, error) { return } if resp.JSON200 == nil { - errKey = fmt.Errorf("%w: %s", errAuthToken, string(resp.Body)) + errKey = fmt.Errorf("%w: %s", ErrAuthToken, string(resp.Body)) return } for _, key := range *resp.JSON200 { From 064d7eb2893d4e7f1b1840d95a558731d60764a2 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Mon, 2 Oct 2023 16:29:22 +0800 Subject: [PATCH 11/11] fix: include more schemas in data only dump (#1540) --- internal/db/dump/dump.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/internal/db/dump/dump.go b/internal/db/dump/dump.go index aeb7c07b1..4a3add848 100644 --- a/internal/db/dump/dump.go +++ b/internal/db/dump/dump.go @@ -64,7 +64,25 @@ func DumpSchema(ctx context.Context, config pgconn.Config, schema []string, keep func dumpData(ctx context.Context, config pgconn.Config, schema []string, useCopy, dryRun bool, stdout io.Writer) error { // We want to dump user data in auth, storage, etc. for migrating to new project - excludedSchemas := append([]string{ + excludedSchemas := []string{ + "information_schema", + "pg_*", // Wildcard pattern follows pg_dump + // Owned by extensions + // "cron", + "graphql", + "graphql_public", + // "net", + // "pgsodium", + // "pgsodium_masks", + "pgtle", + "repack", + "tiger", + "tiger_data", + "timescaledb_*", + "_timescaledb_*", + "topology", + // "vault", + // Managed by Supabase // "auth", "extensions", "pgbouncer", @@ -74,7 +92,7 @@ func dumpData(ctx context.Context, config pgconn.Config, schema []string, useCop "_analytics", // "supabase_functions", "supabase_migrations", - }, utils.SystemSchemas...) + } env := []string{"EXCLUDED_SCHEMAS=" + strings.Join(excludedSchemas, "|")} if len(schema) > 0 { env[0] = "INCLUDED_SCHEMAS=" + strings.Join(schema, "|")