Skip to content

fix: skip rename when schema, role or policy name is unchanged - #1153

Open
breken-ai wants to merge 1 commit into
supabase:masterfrom
breken-ai:fix/skip-same-name-renames
Open

breken-ai wants to merge 1 commit into
supabase:masterfrom
breken-ai:fix/skip-same-name-renames

Conversation

@breken-ai

Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

If you PATCH a schema, role or policy and include the name it already has, the whole update fails. The endpoints are PATCH /schemas/:id, PATCH /roles/:id and PATCH /policies/:id. This happens, for example, when a form sends every field back unchanged and only edits the owner, can_login or the policy definition.

update() always emits a rename when name is set, and Postgres rejects a rename to the current name:

ALTER SCHEMA s RENAME TO s;           -- ERROR: schema "s" already exists
ALTER ROLE r RENAME TO r;             -- ERROR: role "r" already exists
ALTER POLICY p ON t RENAME TO p;      -- ERROR: policy "p" for table "t" already exists

The rename is in the same transaction as the other changes, so they are rolled back as well. The API returns that error.

Tables, columns, triggers, functions and publications already skip the rename when the name is unchanged (#44 did this for tables and columns).

What is the new behavior?

PostgresMetaSchemas.update, PostgresMetaRoles.update and PostgresMetaPolicies.update only emit the rename when name differs from the current name. This is the same check used in PostgresMetaTables.

Additional context

I added an update with name unchanged test to test/lib/schemas.ts, test/lib/roles.ts and test/lib/policies.ts. Each one sends the same name together with another change.

  • On master, all 3 fail with the errors above. For example, "message": "role \"r_same_name\" already exists".
  • With the fix, test/index.test.ts passes 150/150 against the test/db image (supabase/postgres:14.1.0).
  • npm run check and prettier -c are clean.

This PR was prepared with an AI coding assistant (Claude Code). I reproduced the failure and ran the tests against a real Postgres.

🤖 Generated with Claude Code

Postgres rejects a rename to the current name ("schema/role already exists",
"policy ... already exists"), which rolled back the whole update when a
client sent the unchanged name with other fields. Tables, columns, triggers
and functions already skip the no-op rename (supabase#44).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@breken-ai
breken-ai requested review from a team, avallete and soedirgo as code owners September 26, 2026 03:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant