From 65c258d3520f4f0e472b3718c8ac76027b3b243a Mon Sep 17 00:00:00 2001 From: Srinivas A <56465971+srini-abhiram@users.noreply.github.com> Date: Wed, 17 Sep 2025 09:00:46 +0530 Subject: [PATCH 1/2] fix(db): Exclude extensions schema from db pull When running db pull, the schema diff was incorrectly including functions from the extensions schema, such as grant_pg_cron_access. This would generate a migration file that fails to apply locally due to permission errors, as these functions are owned by system roles. By adding extensions to the list of managed schemas, the CLI's diffing logic now correctly handles these objects, preventing it from generating migrations for platform-level functions. This resolves the local must be owner error. --- internal/db/pull/pull.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/db/pull/pull.go b/internal/db/pull/pull.go index feffe2ce2..ccf0a5728 100644 --- a/internal/db/pull/pull.go +++ b/internal/db/pull/pull.go @@ -28,7 +28,7 @@ var ( errMissing = errors.New("No migrations found") errInSync = errors.New("No schema changes found") errConflict = errors.Errorf("The remote database's migration history does not match local files in %s directory.", utils.MigrationsDir) - managedSchemas = []string{"auth", "storage", "realtime"} + managedSchemas = []string{"auth", "storage", "realtime", "extensions"} ) func Run(ctx context.Context, schema []string, config pgconn.Config, name string, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error { From 3ddde0edb5aa56a38a921219ad02f28734ee6332 Mon Sep 17 00:00:00 2001 From: Srinivas A <56465971+srini-abhiram@users.noreply.github.com> Date: Wed, 17 Sep 2025 10:48:04 +0530 Subject: [PATCH 2/2] fix(db): Exclude grant functions from migra diff When running supabase db pull, migra generates CREATE OR REPLACE statements for the extensions.grant_pg_cron_access() and extensions.grant_pg_net_access() functions. These statements cause errors when running the migration locally, as the local postgres user is not the owner of these functions. This change filters the output of the migra diff to remove these two specific function definitions. This prevents the ownership errors while still allowing user-created entities in the extensions schema to be diffed and tracked in migrations. --- internal/db/diff/migra.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/db/diff/migra.go b/internal/db/diff/migra.go index f79c4ae16..cbed35f4a 100644 --- a/internal/db/diff/migra.go +++ b/internal/db/diff/migra.go @@ -5,6 +5,7 @@ import ( "context" _ "embed" "strings" + "regexp" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/network" @@ -147,5 +148,12 @@ EOF ); err != nil && !strings.HasPrefix(stderr.String(), "main worker has been destroyed") { return "", errors.Errorf("error diffing schema: %w:\n%s", err, stderr.String()) } - return out.String(), nil + // TODO: migra does not support ignoring functions yet + return filterFunctionBody(out.String()), nil +} + +var grantFuncPattern = regexp.MustCompile(`(?s)CREATE OR REPLACE FUNCTION extensions.grant_pg_(cron|net)_access.+?END;\$function\$;`) + +func filterFunctionBody(diff string) string { + return grantFuncPattern.ReplaceAllString(diff, "") }