-
-
Notifications
You must be signed in to change notification settings - Fork 17
fix(pg-delta): order view drops before column type rewrites #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
avallete
merged 10 commits into
supabase:main
from
xmh1011:fix/pg-delta-column-rewrite-cascade
Jun 10, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
695590d
test(pg-delta): add regression for view-dependent column rewrite
xmh1011 5c661cd
fix(pg-delta): order view drops before column type rewrites
xmh1011 935e50e
test(pg-delta): add metadata regression for view-dependent column rew…
xmh1011 4610673
fix(pg-delta): preserve view metadata during column rewrite replacement
xmh1011 aa83174
test(pg-delta): add materialized view metadata rewrite regression
xmh1011 5fa96aa
fix(pg-delta): preserve materialized view metadata during replacement
xmh1011 f82dea8
refactor(pg-delta): model column rewrites as invalidations
xmh1011 8dea6e7
chore(pg-delta): address column rewrite review feedback
xmh1011 4d9c29d
test(pg-delta): cover view replacement privilege filtering
xmh1011 4e8172e
fix(pg-delta): preserve replacement privilege revokes
xmh1011 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@supabase/pg-delta": patch | ||
| --- | ||
|
|
||
| Order dependent view drops before column type rewrites, and preserve view or materialized-view metadata, including ACL adjustments, when those dependents are dropped and recreated during replacement. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { diffCatalogs } from "./catalog.diff.ts"; | ||
| import { Catalog, createEmptyCatalog } from "./catalog.model.ts"; | ||
| import { Role, type RoleProps } from "./objects/role/role.model.ts"; | ||
| import { | ||
| GrantViewPrivileges, | ||
| RevokeViewPrivileges, | ||
| } from "./objects/view/changes/view.privilege.ts"; | ||
| import { View, type ViewProps } from "./objects/view/view.model.ts"; | ||
|
|
||
| const idColumn: ViewProps["columns"][number] = { | ||
| name: "id", | ||
| position: 1, | ||
| data_type: "integer", | ||
| data_type_str: "integer", | ||
| is_custom_type: false, | ||
| custom_type_type: null, | ||
| custom_type_category: null, | ||
| custom_type_schema: null, | ||
| custom_type_name: null, | ||
| not_null: false, | ||
| is_identity: false, | ||
| is_identity_always: false, | ||
| is_generated: false, | ||
| collation: null, | ||
| default: null, | ||
| comment: null, | ||
| }; | ||
|
|
||
| const nameColumn: ViewProps["columns"][number] = { | ||
| name: "name", | ||
| position: 2, | ||
| data_type: "text", | ||
| data_type_str: "text", | ||
| is_custom_type: false, | ||
| custom_type_type: null, | ||
| custom_type_category: null, | ||
| custom_type_schema: null, | ||
| custom_type_name: null, | ||
| not_null: false, | ||
| is_identity: false, | ||
| is_identity_always: false, | ||
| is_generated: false, | ||
| collation: null, | ||
| default: null, | ||
| comment: null, | ||
| }; | ||
|
|
||
| const baseView: ViewProps = { | ||
| schema: "public", | ||
| name: "replaced_view", | ||
| definition: "SELECT id FROM source_table", | ||
| row_security: false, | ||
| force_row_security: false, | ||
| has_indexes: false, | ||
| has_rules: false, | ||
| has_triggers: false, | ||
| has_subclasses: false, | ||
| is_populated: true, | ||
| replica_identity: "d", | ||
| is_partition: false, | ||
| options: null, | ||
| partition_bound: null, | ||
| owner: "postgres", | ||
| comment: null, | ||
| columns: [idColumn], | ||
| privileges: [], | ||
| }; | ||
|
|
||
| const makeView = (override: Partial<ViewProps> = {}) => | ||
| new View({ | ||
| ...baseView, | ||
| ...override, | ||
| columns: override.columns ?? [...baseView.columns], | ||
| privileges: override.privileges ?? [...baseView.privileges], | ||
| }); | ||
|
|
||
| const makeRole = (name: string, override: Partial<RoleProps> = {}) => | ||
| new Role({ | ||
| name, | ||
| is_superuser: false, | ||
| can_inherit: true, | ||
| can_create_roles: false, | ||
| can_create_databases: false, | ||
| can_login: true, | ||
| can_replicate: false, | ||
| connection_limit: null, | ||
| can_bypass_rls: false, | ||
| config: null, | ||
| comment: null, | ||
| members: [], | ||
| default_privileges: [], | ||
| security_labels: [], | ||
| ...override, | ||
| }); | ||
|
|
||
| describe("catalog.diff", () => { | ||
| test("keeps replacement-created view grants through dropped-target privilege filtering", async () => { | ||
| const baseline = await createEmptyCatalog(170000, "postgres"); | ||
| const mainView = makeView(); | ||
| const branchView = makeView({ | ||
| definition: "SELECT id, name FROM source_table", | ||
| columns: [...mainView.columns, nameColumn], | ||
| privileges: [ | ||
| { grantee: "view_reader", privilege: "SELECT", grantable: false }, | ||
| ], | ||
| }); | ||
|
|
||
| const main = new Catalog({ | ||
| // oxlint-disable-next-line typescript/no-misused-spread | ||
| ...baseline, | ||
| views: { [mainView.stableId]: mainView }, | ||
| }); | ||
| const branch = new Catalog({ | ||
| // oxlint-disable-next-line typescript/no-misused-spread | ||
| ...baseline, | ||
| views: { [branchView.stableId]: branchView }, | ||
| }); | ||
|
|
||
| const changes = diffCatalogs(main, branch); | ||
|
|
||
| expect( | ||
| changes.some((change) => change instanceof GrantViewPrivileges), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("keeps replacement-created view revokes through dropped-target privilege filtering", async () => { | ||
| const baseline = await createEmptyCatalog(170000, "postgres"); | ||
| const mainView = makeView(); | ||
| const branchView = makeView({ | ||
| definition: "SELECT id, name FROM source_table", | ||
| columns: [...mainView.columns, nameColumn], | ||
| }); | ||
| const postgres = makeRole("postgres", { | ||
| default_privileges: [ | ||
| { | ||
| in_schema: "public", | ||
| objtype: "r", | ||
| grantee: "view_reader", | ||
| privileges: [{ privilege: "SELECT", grantable: false }], | ||
| is_implicit: false, | ||
| }, | ||
| ], | ||
| }); | ||
| const viewReader = makeRole("view_reader"); | ||
|
|
||
| const roles = { | ||
| [postgres.stableId]: postgres, | ||
| [viewReader.stableId]: viewReader, | ||
| }; | ||
| const main = new Catalog({ | ||
| // oxlint-disable-next-line typescript/no-misused-spread | ||
| ...baseline, | ||
| roles, | ||
| views: { [mainView.stableId]: mainView }, | ||
| }); | ||
| const branch = new Catalog({ | ||
| // oxlint-disable-next-line typescript/no-misused-spread | ||
| ...baseline, | ||
| roles, | ||
| views: { [branchView.stableId]: branchView }, | ||
| }); | ||
|
|
||
| // The recreated view inherits SELECT from default privileges, but the | ||
| // branch model wants no explicit reader ACL. The replacement filter must | ||
| // keep the generated REVOKE even though the old view stable id is dropped. | ||
| const changes = diffCatalogs(main, branch); | ||
|
|
||
| expect( | ||
| changes.some((change) => change instanceof RevokeViewPrivileges), | ||
| ).toBe(true); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.