@supabase/pg-delta 1.0.0-alpha.21 → 1.0.0-alpha.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/catalog.diff.js +4 -3
- package/dist/core/catalog.model.d.ts +8 -1
- package/dist/core/catalog.model.js +10 -8
- package/dist/core/expand-replace-dependencies.js +23 -0
- package/dist/core/integrations/filter/flatten.js +13 -0
- package/dist/core/objects/aggregate/aggregate.diff.js +16 -0
- package/dist/core/objects/aggregate/aggregate.model.d.ts +10 -0
- package/dist/core/objects/aggregate/aggregate.model.js +19 -1
- package/dist/core/objects/aggregate/changes/aggregate.base.d.ts +1 -1
- package/dist/core/objects/aggregate/changes/aggregate.security-label.d.ts +28 -0
- package/dist/core/objects/aggregate/changes/aggregate.security-label.js +64 -0
- package/dist/core/objects/aggregate/changes/aggregate.types.d.ts +2 -1
- package/dist/core/objects/base.model.d.ts +8 -0
- package/dist/core/objects/base.model.js +2 -0
- package/dist/core/objects/domain/changes/domain.base.d.ts +1 -1
- package/dist/core/objects/domain/changes/domain.security-label.d.ts +28 -0
- package/dist/core/objects/domain/changes/domain.security-label.js +61 -0
- package/dist/core/objects/domain/changes/domain.types.d.ts +2 -1
- package/dist/core/objects/domain/domain.diff.js +16 -0
- package/dist/core/objects/domain/domain.model.d.ts +10 -0
- package/dist/core/objects/domain/domain.model.js +19 -1
- package/dist/core/objects/event-trigger/changes/event-trigger.base.d.ts +1 -1
- package/dist/core/objects/event-trigger/changes/event-trigger.security-label.d.ts +28 -0
- package/dist/core/objects/event-trigger/changes/event-trigger.security-label.js +61 -0
- package/dist/core/objects/event-trigger/changes/event-trigger.types.d.ts +2 -1
- package/dist/core/objects/event-trigger/event-trigger.diff.js +16 -0
- package/dist/core/objects/event-trigger/event-trigger.model.d.ts +10 -0
- package/dist/core/objects/event-trigger/event-trigger.model.js +19 -1
- package/dist/core/objects/extract-with-retry.d.ts +36 -0
- package/dist/core/objects/extract-with-retry.js +51 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.base.d.ts +1 -1
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.security-label.d.ts +28 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.security-label.js +61 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.types.d.ts +2 -1
- package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.js +16 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.d.ts +22 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.js +20 -1
- package/dist/core/objects/index/index.diff.js +0 -1
- package/dist/core/objects/index/index.model.d.ts +2 -3
- package/dist/core/objects/index/index.model.js +17 -6
- package/dist/core/objects/materialized-view/changes/materialized-view.base.d.ts +1 -1
- package/dist/core/objects/materialized-view/changes/materialized-view.security-label.d.ts +28 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.security-label.js +61 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.types.d.ts +2 -1
- package/dist/core/objects/materialized-view/materialized-view.diff.js +18 -0
- package/dist/core/objects/materialized-view/materialized-view.model.d.ts +24 -1
- package/dist/core/objects/materialized-view/materialized-view.model.js +40 -5
- package/dist/core/objects/procedure/changes/procedure.base.d.ts +1 -1
- package/dist/core/objects/procedure/changes/procedure.security-label.d.ts +28 -0
- package/dist/core/objects/procedure/changes/procedure.security-label.js +69 -0
- package/dist/core/objects/procedure/changes/procedure.types.d.ts +2 -1
- package/dist/core/objects/procedure/procedure.diff.js +16 -0
- package/dist/core/objects/procedure/procedure.model.d.ts +12 -1
- package/dist/core/objects/procedure/procedure.model.js +39 -5
- package/dist/core/objects/publication/changes/publication.base.d.ts +1 -1
- package/dist/core/objects/publication/changes/publication.security-label.d.ts +28 -0
- package/dist/core/objects/publication/changes/publication.security-label.js +61 -0
- package/dist/core/objects/publication/changes/publication.types.d.ts +2 -1
- package/dist/core/objects/publication/publication.diff.js +16 -0
- package/dist/core/objects/publication/publication.model.d.ts +14 -0
- package/dist/core/objects/publication/publication.model.js +20 -1
- package/dist/core/objects/rls-policy/rls-policy.diff.js +13 -1
- package/dist/core/objects/role/changes/role.base.d.ts +1 -1
- package/dist/core/objects/role/changes/role.security-label.d.ts +28 -0
- package/dist/core/objects/role/changes/role.security-label.js +61 -0
- package/dist/core/objects/role/changes/role.types.d.ts +2 -1
- package/dist/core/objects/role/role.diff.js +16 -0
- package/dist/core/objects/role/role.model.d.ts +10 -0
- package/dist/core/objects/role/role.model.js +29 -0
- package/dist/core/objects/rule/rule.model.d.ts +2 -1
- package/dist/core/objects/rule/rule.model.js +20 -3
- package/dist/core/objects/schema/changes/schema.base.d.ts +1 -1
- package/dist/core/objects/schema/changes/schema.security-label.d.ts +28 -0
- package/dist/core/objects/schema/changes/schema.security-label.js +61 -0
- package/dist/core/objects/schema/changes/schema.types.d.ts +2 -1
- package/dist/core/objects/schema/schema.diff.js +24 -1
- package/dist/core/objects/schema/schema.model.d.ts +10 -0
- package/dist/core/objects/schema/schema.model.js +18 -1
- package/dist/core/objects/security-label.types.d.ts +20 -0
- package/dist/core/objects/security-label.types.js +46 -0
- package/dist/core/objects/sequence/changes/sequence.base.d.ts +1 -1
- package/dist/core/objects/sequence/changes/sequence.security-label.d.ts +28 -0
- package/dist/core/objects/sequence/changes/sequence.security-label.js +61 -0
- package/dist/core/objects/sequence/changes/sequence.types.d.ts +2 -1
- package/dist/core/objects/sequence/sequence.diff.d.ts +2 -1
- package/dist/core/objects/sequence/sequence.diff.js +44 -4
- package/dist/core/objects/sequence/sequence.model.d.ts +10 -0
- package/dist/core/objects/sequence/sequence.model.js +19 -1
- package/dist/core/objects/subscription/changes/subscription.base.d.ts +1 -1
- package/dist/core/objects/subscription/changes/subscription.security-label.d.ts +28 -0
- package/dist/core/objects/subscription/changes/subscription.security-label.js +61 -0
- package/dist/core/objects/subscription/changes/subscription.types.d.ts +2 -1
- package/dist/core/objects/subscription/subscription.diff.js +16 -0
- package/dist/core/objects/subscription/subscription.model.d.ts +10 -0
- package/dist/core/objects/subscription/subscription.model.js +19 -1
- package/dist/core/objects/table/changes/table.alter.d.ts +12 -1
- package/dist/core/objects/table/changes/table.alter.js +20 -2
- package/dist/core/objects/table/changes/table.base.d.ts +1 -1
- package/dist/core/objects/table/changes/table.security-label.d.ts +63 -0
- package/dist/core/objects/table/changes/table.security-label.js +134 -0
- package/dist/core/objects/table/changes/table.types.d.ts +2 -1
- package/dist/core/objects/table/table.diff.js +68 -15
- package/dist/core/objects/table/table.model.d.ts +36 -1
- package/dist/core/objects/table/table.model.js +74 -7
- package/dist/core/objects/trigger/trigger.model.d.ts +2 -1
- package/dist/core/objects/trigger/trigger.model.js +20 -4
- package/dist/core/objects/type/composite-type/changes/composite-type.base.d.ts +1 -1
- package/dist/core/objects/type/composite-type/changes/composite-type.security-label.d.ts +28 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.security-label.js +61 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.types.d.ts +2 -1
- package/dist/core/objects/type/composite-type/composite-type.diff.js +16 -0
- package/dist/core/objects/type/composite-type/composite-type.model.d.ts +22 -0
- package/dist/core/objects/type/composite-type/composite-type.model.js +22 -2
- package/dist/core/objects/type/enum/changes/enum.base.d.ts +1 -1
- package/dist/core/objects/type/enum/changes/enum.security-label.d.ts +28 -0
- package/dist/core/objects/type/enum/changes/enum.security-label.js +61 -0
- package/dist/core/objects/type/enum/changes/enum.types.d.ts +2 -1
- package/dist/core/objects/type/enum/enum.diff.js +16 -0
- package/dist/core/objects/type/enum/enum.model.d.ts +10 -0
- package/dist/core/objects/type/enum/enum.model.js +20 -1
- package/dist/core/objects/type/range/changes/range.base.d.ts +1 -1
- package/dist/core/objects/type/range/changes/range.security-label.d.ts +28 -0
- package/dist/core/objects/type/range/changes/range.security-label.js +61 -0
- package/dist/core/objects/type/range/changes/range.types.d.ts +2 -1
- package/dist/core/objects/type/range/range.diff.js +16 -0
- package/dist/core/objects/type/range/range.model.d.ts +10 -0
- package/dist/core/objects/type/range/range.model.js +19 -1
- package/dist/core/objects/utils.d.ts +2 -0
- package/dist/core/objects/utils.js +6 -0
- package/dist/core/objects/view/changes/view.base.d.ts +1 -1
- package/dist/core/objects/view/changes/view.security-label.d.ts +28 -0
- package/dist/core/objects/view/changes/view.security-label.js +61 -0
- package/dist/core/objects/view/changes/view.types.d.ts +2 -1
- package/dist/core/objects/view/view.diff.js +13 -0
- package/dist/core/objects/view/view.model.d.ts +28 -1
- package/dist/core/objects/view/view.model.js +40 -5
- package/dist/core/plan/create.js +3 -1
- package/dist/core/plan/sql-format/fixtures.js +1 -0
- package/dist/core/plan/types.d.ts +8 -0
- package/dist/core/{post-diff-cycle-breaking.d.ts → post-diff-normalization.d.ts} +8 -1
- package/dist/core/post-diff-normalization.js +202 -0
- package/dist/core/sort/cycle-breakers.js +1 -1
- package/dist/core/sort/utils.d.ts +10 -0
- package/dist/core/sort/utils.js +28 -0
- package/package.json +1 -1
- package/src/core/catalog.diff.ts +4 -2
- package/src/core/catalog.model.ts +21 -8
- package/src/core/expand-replace-dependencies.test.ts +131 -0
- package/src/core/expand-replace-dependencies.ts +24 -0
- package/src/core/integrations/filter/dsl.test.ts +27 -0
- package/src/core/integrations/filter/flatten.ts +16 -0
- package/src/core/objects/aggregate/aggregate.diff.ts +33 -0
- package/src/core/objects/aggregate/aggregate.model.ts +22 -1
- package/src/core/objects/aggregate/changes/aggregate.base.ts +5 -1
- package/src/core/objects/aggregate/changes/aggregate.security-label.ts +99 -0
- package/src/core/objects/aggregate/changes/aggregate.types.ts +3 -1
- package/src/core/objects/base.model.ts +2 -0
- package/src/core/objects/domain/changes/domain.base.ts +5 -1
- package/src/core/objects/domain/changes/domain.security-label.test.ts +56 -0
- package/src/core/objects/domain/changes/domain.security-label.ts +77 -0
- package/src/core/objects/domain/changes/domain.types.ts +3 -1
- package/src/core/objects/domain/domain.diff.ts +33 -0
- package/src/core/objects/domain/domain.model.ts +22 -1
- package/src/core/objects/event-trigger/changes/event-trigger.base.ts +1 -1
- package/src/core/objects/event-trigger/changes/event-trigger.security-label.ts +95 -0
- package/src/core/objects/event-trigger/changes/event-trigger.types.ts +3 -1
- package/src/core/objects/event-trigger/event-trigger.diff.ts +33 -0
- package/src/core/objects/event-trigger/event-trigger.model.ts +22 -1
- package/src/core/objects/extract-with-retry.test.ts +143 -0
- package/src/core/objects/extract-with-retry.ts +87 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.base.ts +5 -1
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.security-label.ts +95 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.types.ts +3 -1
- package/src/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.ts +33 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.ts +24 -1
- package/src/core/objects/index/index.diff.ts +0 -1
- package/src/core/objects/index/index.model.test.ts +37 -1
- package/src/core/objects/index/index.model.ts +25 -6
- package/src/core/objects/materialized-view/changes/materialized-view.base.ts +5 -1
- package/src/core/objects/materialized-view/changes/materialized-view.security-label.test.ts +63 -0
- package/src/core/objects/materialized-view/changes/materialized-view.security-label.ts +95 -0
- package/src/core/objects/materialized-view/changes/materialized-view.types.ts +3 -1
- package/src/core/objects/materialized-view/materialized-view.diff.ts +37 -0
- package/src/core/objects/materialized-view/materialized-view.model.test.ts +93 -0
- package/src/core/objects/materialized-view/materialized-view.model.ts +52 -8
- package/src/core/objects/procedure/changes/procedure.base.ts +5 -1
- package/src/core/objects/procedure/changes/procedure.security-label.ts +105 -0
- package/src/core/objects/procedure/changes/procedure.types.ts +3 -1
- package/src/core/objects/procedure/procedure.diff.ts +33 -0
- package/src/core/objects/procedure/procedure.model.test.ts +117 -0
- package/src/core/objects/procedure/procedure.model.ts +51 -7
- package/src/core/objects/publication/changes/publication.base.ts +1 -1
- package/src/core/objects/publication/changes/publication.security-label.ts +95 -0
- package/src/core/objects/publication/changes/publication.types.ts +3 -1
- package/src/core/objects/publication/publication.diff.ts +33 -0
- package/src/core/objects/publication/publication.model.ts +24 -1
- package/src/core/objects/rls-policy/rls-policy.diff.ts +19 -1
- package/src/core/objects/role/changes/role.base.ts +2 -1
- package/src/core/objects/role/changes/role.security-label.ts +77 -0
- package/src/core/objects/role/changes/role.types.ts +3 -1
- package/src/core/objects/role/role.diff.ts +33 -0
- package/src/core/objects/role/role.model.ts +32 -0
- package/src/core/objects/rule/rule.model.test.ts +99 -0
- package/src/core/objects/rule/rule.model.ts +28 -4
- package/src/core/objects/schema/changes/schema.alter.test.ts +1 -0
- package/src/core/objects/schema/changes/schema.base.ts +5 -1
- package/src/core/objects/schema/changes/schema.create.test.ts +1 -0
- package/src/core/objects/schema/changes/schema.drop.test.ts +1 -0
- package/src/core/objects/schema/changes/schema.security-label.test.ts +76 -0
- package/src/core/objects/schema/changes/schema.security-label.ts +77 -0
- package/src/core/objects/schema/changes/schema.types.ts +3 -1
- package/src/core/objects/schema/schema.diff.test.ts +1 -0
- package/src/core/objects/schema/schema.diff.ts +43 -1
- package/src/core/objects/schema/schema.model.ts +21 -1
- package/src/core/objects/security-label.types.test.ts +106 -0
- package/src/core/objects/security-label.types.ts +61 -0
- package/src/core/objects/sequence/changes/sequence.base.ts +5 -1
- package/src/core/objects/sequence/changes/sequence.security-label.test.ts +58 -0
- package/src/core/objects/sequence/changes/sequence.security-label.ts +92 -0
- package/src/core/objects/sequence/changes/sequence.types.ts +3 -1
- package/src/core/objects/sequence/sequence.diff.test.ts +87 -0
- package/src/core/objects/sequence/sequence.diff.ts +64 -6
- package/src/core/objects/sequence/sequence.model.ts +22 -1
- package/src/core/objects/subscription/changes/subscription.base.ts +1 -1
- package/src/core/objects/subscription/changes/subscription.security-label.ts +95 -0
- package/src/core/objects/subscription/changes/subscription.types.ts +3 -1
- package/src/core/objects/subscription/subscription.diff.ts +33 -0
- package/src/core/objects/subscription/subscription.model.ts +22 -1
- package/src/core/objects/table/changes/table.alter.test.ts +13 -21
- package/src/core/objects/table/changes/table.alter.ts +30 -3
- package/src/core/objects/table/changes/table.base.ts +5 -1
- package/src/core/objects/table/changes/table.security-label.test.ts +140 -0
- package/src/core/objects/table/changes/table.security-label.ts +183 -0
- package/src/core/objects/table/changes/table.types.ts +3 -1
- package/src/core/objects/table/table.diff.ts +111 -19
- package/src/core/objects/table/table.model.test.ts +209 -0
- package/src/core/objects/table/table.model.ts +94 -9
- package/src/core/objects/trigger/trigger.model.test.ts +113 -0
- package/src/core/objects/trigger/trigger.model.ts +28 -5
- package/src/core/objects/type/composite-type/changes/composite-type.base.ts +5 -1
- package/src/core/objects/type/composite-type/changes/composite-type.security-label.ts +95 -0
- package/src/core/objects/type/composite-type/changes/composite-type.types.ts +3 -1
- package/src/core/objects/type/composite-type/composite-type.diff.ts +33 -0
- package/src/core/objects/type/composite-type/composite-type.model.ts +26 -2
- package/src/core/objects/type/enum/changes/enum.base.ts +5 -1
- package/src/core/objects/type/enum/changes/enum.security-label.ts +77 -0
- package/src/core/objects/type/enum/changes/enum.types.ts +3 -1
- package/src/core/objects/type/enum/enum.diff.ts +33 -0
- package/src/core/objects/type/enum/enum.model.ts +25 -1
- package/src/core/objects/type/range/changes/range.base.ts +5 -1
- package/src/core/objects/type/range/changes/range.security-label.ts +77 -0
- package/src/core/objects/type/range/changes/range.types.ts +3 -1
- package/src/core/objects/type/range/range.diff.ts +33 -0
- package/src/core/objects/type/range/range.model.ts +22 -1
- package/src/core/objects/utils.ts +6 -0
- package/src/core/objects/view/changes/view.base.ts +5 -1
- package/src/core/objects/view/changes/view.security-label.test.ts +64 -0
- package/src/core/objects/view/changes/view.security-label.ts +77 -0
- package/src/core/objects/view/changes/view.types.ts +3 -1
- package/src/core/objects/view/view.diff.ts +31 -0
- package/src/core/objects/view/view.model.test.ts +90 -0
- package/src/core/objects/view/view.model.ts +53 -7
- package/src/core/plan/create.ts +3 -1
- package/src/core/plan/sql-format/fixtures.ts +1 -0
- package/src/core/plan/types.ts +8 -0
- package/src/core/{post-diff-cycle-breaking.test.ts → post-diff-normalization.test.ts} +168 -4
- package/src/core/post-diff-normalization.ts +260 -0
- package/src/core/sort/cycle-breakers.ts +1 -1
- package/src/core/sort/utils.ts +38 -0
- package/dist/core/post-diff-cycle-breaking.js +0 -100
- package/src/core/post-diff-cycle-breaking.ts +0 -138
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { diffObjects } from "../base.diff.js";
|
|
2
2
|
import { diffPrivileges, emitObjectPrivilegeChanges, } from "../base.privilege-diff.js";
|
|
3
|
+
import { diffSecurityLabels } from "../security-label.types.js";
|
|
3
4
|
import { AlterTableAlterColumnSetDefault } from "../table/changes/table.alter.js";
|
|
4
5
|
import { hasNonAlterableChanges } from "../utils.js";
|
|
5
6
|
import { AlterSequenceSetOptions, AlterSequenceSetOwnedBy, } from "./changes/sequence.alter.js";
|
|
@@ -7,6 +8,7 @@ import { CreateCommentOnSequence, DropCommentOnSequence, } from "./changes/seque
|
|
|
7
8
|
import { CreateSequence } from "./changes/sequence.create.js";
|
|
8
9
|
import { DropSequence } from "./changes/sequence.drop.js";
|
|
9
10
|
import { GrantSequencePrivileges, RevokeGrantOptionSequencePrivileges, RevokeSequencePrivileges, } from "./changes/sequence.privilege.js";
|
|
11
|
+
import { CreateSecurityLabelOnSequence, DropSecurityLabelOnSequence, } from "./changes/sequence.security-label.js";
|
|
10
12
|
/**
|
|
11
13
|
* Diff two sets of sequences from main and branch catalogs.
|
|
12
14
|
*
|
|
@@ -14,9 +16,10 @@ import { GrantSequencePrivileges, RevokeGrantOptionSequencePrivileges, RevokeSeq
|
|
|
14
16
|
* @param main - The sequences in the main catalog.
|
|
15
17
|
* @param branch - The sequences in the branch catalog.
|
|
16
18
|
* @param branchTables - The tables in the branch catalog (used to check if owning tables are being dropped).
|
|
19
|
+
* @param mainTables - The tables in the main catalog (used to detect when a same-name sequence will be cascade-dropped because its main-side owning table is going away).
|
|
17
20
|
* @returns A list of changes to apply to main to make it match branch.
|
|
18
21
|
*/
|
|
19
|
-
export function diffSequences(ctx, main, branch, branchTables = {}) {
|
|
22
|
+
export function diffSequences(ctx, main, branch, branchTables = {}, mainTables = {}) {
|
|
20
23
|
const { created, dropped, altered } = diffObjects(main, branch);
|
|
21
24
|
const changes = [];
|
|
22
25
|
for (const sequenceId of created) {
|
|
@@ -25,6 +28,12 @@ export function diffSequences(ctx, main, branch, branchTables = {}) {
|
|
|
25
28
|
if (createdSeq.comment !== null) {
|
|
26
29
|
changes.push(new CreateCommentOnSequence({ sequence: createdSeq }));
|
|
27
30
|
}
|
|
31
|
+
for (const label of createdSeq.security_labels) {
|
|
32
|
+
changes.push(new CreateSecurityLabelOnSequence({
|
|
33
|
+
sequence: createdSeq,
|
|
34
|
+
securityLabel: label,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
28
37
|
// If the created sequence is OWNED BY a column, emit an ALTER to set it
|
|
29
38
|
if (createdSeq.owned_by_schema !== null &&
|
|
30
39
|
createdSeq.owned_by_table !== null &&
|
|
@@ -89,9 +98,32 @@ export function diffSequences(ctx, main, branch, branchTables = {}) {
|
|
|
89
98
|
// These require dropping and recreating the sequence
|
|
90
99
|
const NON_ALTERABLE_FIELDS = ["persistence"];
|
|
91
100
|
const nonAlterablePropsChanged = hasNonAlterableChanges(mainSequence, branchSequence, NON_ALTERABLE_FIELDS);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
// A sequence kept the same name (so it's "altered" in catalog terms),
|
|
102
|
+
// but its main-side owning table is going away from the plan (renamed
|
|
103
|
+
// away or simply dropped). PostgreSQL will cascade-drop the sequence
|
|
104
|
+
// alongside the table, leaving any later CREATE TABLE / column-default
|
|
105
|
+
// that depends on the sequence name pointing at nothing. Treat this
|
|
106
|
+
// like a non-alterable change so we recreate the sequence after the
|
|
107
|
+
// owning table is dropped.
|
|
108
|
+
const mainOwnedByTableId = mainSequence.owned_by_schema && mainSequence.owned_by_table
|
|
109
|
+
? `table:${mainSequence.owned_by_schema}.${mainSequence.owned_by_table}`
|
|
110
|
+
: null;
|
|
111
|
+
const cascadeOrphanedByOwningTable = mainOwnedByTableId !== null &&
|
|
112
|
+
mainTables[mainOwnedByTableId] !== undefined &&
|
|
113
|
+
branchTables[mainOwnedByTableId] === undefined;
|
|
114
|
+
if (nonAlterablePropsChanged || cascadeOrphanedByOwningTable) {
|
|
115
|
+
// When the owning table is going away in this plan, PostgreSQL will
|
|
116
|
+
// cascade-drop the sequence as part of the DROP TABLE. Emitting an
|
|
117
|
+
// explicit DROP SEQUENCE here would (a) introduce an unbreakable
|
|
118
|
+
// DropSequence ↔ DropTable cycle on the catalog edges between the
|
|
119
|
+
// sequence and the dropped column, and (b) be redundant with the
|
|
120
|
+
// cascade. The CreateSequence below restores the sequence under its
|
|
121
|
+
// original name so any same-name reference in a later CREATE TABLE
|
|
122
|
+
// resolves correctly.
|
|
123
|
+
if (!cascadeOrphanedByOwningTable) {
|
|
124
|
+
changes.push(new DropSequence({ sequence: mainSequence }));
|
|
125
|
+
}
|
|
126
|
+
changes.push(new CreateSequence({ sequence: branchSequence }));
|
|
95
127
|
// Re-apply OWNED BY if present on branch
|
|
96
128
|
if (branchSequence.owned_by_schema !== null &&
|
|
97
129
|
branchSequence.owned_by_table !== null &&
|
|
@@ -205,6 +237,14 @@ export function diffSequences(ctx, main, branch, branchTables = {}) {
|
|
|
205
237
|
changes.push(new CreateCommentOnSequence({ sequence: branchSequence }));
|
|
206
238
|
}
|
|
207
239
|
}
|
|
240
|
+
// SECURITY LABELS
|
|
241
|
+
changes.push(...diffSecurityLabels(mainSequence.security_labels, branchSequence.security_labels, (securityLabel) => new CreateSecurityLabelOnSequence({
|
|
242
|
+
sequence: branchSequence,
|
|
243
|
+
securityLabel,
|
|
244
|
+
}), (securityLabel) => new DropSecurityLabelOnSequence({
|
|
245
|
+
sequence: mainSequence,
|
|
246
|
+
securityLabel,
|
|
247
|
+
})));
|
|
208
248
|
// PRIVILEGES
|
|
209
249
|
// Filter out owner privileges - owner always has ALL privileges implicitly
|
|
210
250
|
// and shouldn't be compared. Use branch owner as the reference.
|
|
@@ -2,6 +2,7 @@ import type { Pool } from "pg";
|
|
|
2
2
|
import z from "zod";
|
|
3
3
|
import { BasePgModel } from "../base.model.ts";
|
|
4
4
|
import { type PrivilegeProps } from "../base.privilege-diff.ts";
|
|
5
|
+
import { type SecurityLabelProps } from "../security-label.types.ts";
|
|
5
6
|
declare const sequencePropsSchema: z.ZodObject<{
|
|
6
7
|
schema: z.ZodString;
|
|
7
8
|
name: z.ZodString;
|
|
@@ -24,6 +25,10 @@ declare const sequencePropsSchema: z.ZodObject<{
|
|
|
24
25
|
columns: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
25
26
|
}, z.z.core.$strip>>;
|
|
26
27
|
owner: z.ZodString;
|
|
28
|
+
security_labels: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
29
|
+
provider: z.ZodString;
|
|
30
|
+
label: z.ZodString;
|
|
31
|
+
}, z.z.core.$strip>>>>;
|
|
27
32
|
}, z.z.core.$strip>;
|
|
28
33
|
type SequencePrivilegeProps = PrivilegeProps;
|
|
29
34
|
export type SequenceProps = z.infer<typeof sequencePropsSchema>;
|
|
@@ -44,6 +49,7 @@ export declare class Sequence extends BasePgModel {
|
|
|
44
49
|
readonly comment: SequenceProps["comment"];
|
|
45
50
|
readonly privileges: SequencePrivilegeProps[];
|
|
46
51
|
readonly owner: SequenceProps["owner"];
|
|
52
|
+
readonly security_labels: SecurityLabelProps[];
|
|
47
53
|
constructor(props: SequenceProps);
|
|
48
54
|
get stableId(): `sequence:${string}`;
|
|
49
55
|
get identityFields(): {
|
|
@@ -70,6 +76,10 @@ export declare class Sequence extends BasePgModel {
|
|
|
70
76
|
columns?: string[] | null | undefined;
|
|
71
77
|
}[];
|
|
72
78
|
owner: string;
|
|
79
|
+
security_labels: {
|
|
80
|
+
provider: string;
|
|
81
|
+
label: string;
|
|
82
|
+
}[];
|
|
73
83
|
};
|
|
74
84
|
}
|
|
75
85
|
export declare function extractSequences(pool: Pool): Promise<Sequence[]>;
|
|
@@ -2,6 +2,7 @@ import { sql } from "@ts-safeql/sql-tag";
|
|
|
2
2
|
import z from "zod";
|
|
3
3
|
import { BasePgModel } from "../base.model.js";
|
|
4
4
|
import { privilegePropsSchema, } from "../base.privilege-diff.js";
|
|
5
|
+
import { securityLabelPropsSchema, } from "../security-label.types.js";
|
|
5
6
|
const sequencePropsSchema = z.object({
|
|
6
7
|
schema: z.string(),
|
|
7
8
|
name: z.string(),
|
|
@@ -19,6 +20,7 @@ const sequencePropsSchema = z.object({
|
|
|
19
20
|
comment: z.string().nullable(),
|
|
20
21
|
privileges: z.array(privilegePropsSchema),
|
|
21
22
|
owner: z.string(),
|
|
23
|
+
security_labels: z.array(securityLabelPropsSchema).default([]).optional(),
|
|
22
24
|
});
|
|
23
25
|
export class Sequence extends BasePgModel {
|
|
24
26
|
schema;
|
|
@@ -37,6 +39,7 @@ export class Sequence extends BasePgModel {
|
|
|
37
39
|
comment;
|
|
38
40
|
privileges;
|
|
39
41
|
owner;
|
|
42
|
+
security_labels;
|
|
40
43
|
constructor(props) {
|
|
41
44
|
super();
|
|
42
45
|
// Identity fields
|
|
@@ -57,6 +60,7 @@ export class Sequence extends BasePgModel {
|
|
|
57
60
|
this.comment = props.comment;
|
|
58
61
|
this.privileges = props.privileges;
|
|
59
62
|
this.owner = props.owner;
|
|
63
|
+
this.security_labels = props.security_labels ?? [];
|
|
60
64
|
}
|
|
61
65
|
get stableId() {
|
|
62
66
|
return `sequence:${this.schema}.${this.name}`;
|
|
@@ -83,6 +87,7 @@ export class Sequence extends BasePgModel {
|
|
|
83
87
|
comment: this.comment,
|
|
84
88
|
privileges: this.privileges,
|
|
85
89
|
owner: this.owner,
|
|
90
|
+
security_labels: this.security_labels,
|
|
86
91
|
};
|
|
87
92
|
}
|
|
88
93
|
}
|
|
@@ -135,7 +140,20 @@ select
|
|
|
135
140
|
from lateral aclexplode(COALESCE(c.relacl, acldefault('S', c.relowner))) as x(grantor, grantee, privilege_type, is_grantable)
|
|
136
141
|
), '[]'
|
|
137
142
|
) as privileges,
|
|
138
|
-
c.relowner::regrole::text as owner
|
|
143
|
+
c.relowner::regrole::text as owner,
|
|
144
|
+
coalesce(
|
|
145
|
+
(
|
|
146
|
+
select json_agg(
|
|
147
|
+
json_build_object('provider', sl.provider, 'label', sl.label)
|
|
148
|
+
order by sl.provider
|
|
149
|
+
)
|
|
150
|
+
from pg_catalog.pg_seclabel sl
|
|
151
|
+
where sl.objoid = c.oid
|
|
152
|
+
and sl.classoid = 'pg_class'::regclass
|
|
153
|
+
and sl.objsubid = 0
|
|
154
|
+
),
|
|
155
|
+
'[]'::json
|
|
156
|
+
) as security_labels
|
|
139
157
|
from
|
|
140
158
|
pg_catalog.pg_class c
|
|
141
159
|
inner join pg_catalog.pg_sequence s on s.seqrelid = c.oid
|
|
@@ -2,7 +2,7 @@ import { BaseChange } from "../../base.change.ts";
|
|
|
2
2
|
import type { Subscription } from "../subscription.model.ts";
|
|
3
3
|
declare abstract class BaseSubscriptionChange extends BaseChange {
|
|
4
4
|
abstract readonly subscription: Subscription;
|
|
5
|
-
abstract readonly scope: "object" | "comment";
|
|
5
|
+
abstract readonly scope: "object" | "comment" | "security_label";
|
|
6
6
|
readonly objectType: "subscription";
|
|
7
7
|
}
|
|
8
8
|
export declare abstract class CreateSubscriptionChange extends BaseSubscriptionChange {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { SecurityLabelProps } from "../../security-label.types.ts";
|
|
2
|
+
import type { Subscription } from "../subscription.model.ts";
|
|
3
|
+
import { CreateSubscriptionChange, DropSubscriptionChange } from "./subscription.base.ts";
|
|
4
|
+
export type SecurityLabelSubscription = CreateSecurityLabelOnSubscription | DropSecurityLabelOnSubscription;
|
|
5
|
+
export declare class CreateSecurityLabelOnSubscription extends CreateSubscriptionChange {
|
|
6
|
+
readonly subscription: Subscription;
|
|
7
|
+
readonly securityLabel: SecurityLabelProps;
|
|
8
|
+
readonly scope: "security_label";
|
|
9
|
+
constructor(props: {
|
|
10
|
+
subscription: Subscription;
|
|
11
|
+
securityLabel: SecurityLabelProps;
|
|
12
|
+
});
|
|
13
|
+
get creates(): `securityLabel:${string}::provider:${string}`[];
|
|
14
|
+
get requires(): `subscription:${string}`[];
|
|
15
|
+
serialize(): string;
|
|
16
|
+
}
|
|
17
|
+
export declare class DropSecurityLabelOnSubscription extends DropSubscriptionChange {
|
|
18
|
+
readonly subscription: Subscription;
|
|
19
|
+
readonly securityLabel: SecurityLabelProps;
|
|
20
|
+
readonly scope: "security_label";
|
|
21
|
+
constructor(props: {
|
|
22
|
+
subscription: Subscription;
|
|
23
|
+
securityLabel: SecurityLabelProps;
|
|
24
|
+
});
|
|
25
|
+
get drops(): `securityLabel:${string}::provider:${string}`[];
|
|
26
|
+
get requires(): (`securityLabel:${string}::provider:${string}` | `subscription:${string}`)[];
|
|
27
|
+
serialize(): string;
|
|
28
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { quoteLiteral } from "../../base.change.js";
|
|
2
|
+
import { stableId } from "../../utils.js";
|
|
3
|
+
import { CreateSubscriptionChange, DropSubscriptionChange, } from "./subscription.base.js";
|
|
4
|
+
export class CreateSecurityLabelOnSubscription extends CreateSubscriptionChange {
|
|
5
|
+
subscription;
|
|
6
|
+
securityLabel;
|
|
7
|
+
scope = "security_label";
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super();
|
|
10
|
+
this.subscription = props.subscription;
|
|
11
|
+
this.securityLabel = props.securityLabel;
|
|
12
|
+
}
|
|
13
|
+
get creates() {
|
|
14
|
+
return [
|
|
15
|
+
stableId.securityLabel(this.subscription.stableId, this.securityLabel.provider),
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
get requires() {
|
|
19
|
+
return [this.subscription.stableId];
|
|
20
|
+
}
|
|
21
|
+
serialize() {
|
|
22
|
+
return [
|
|
23
|
+
"SECURITY LABEL FOR",
|
|
24
|
+
this.securityLabel.provider,
|
|
25
|
+
"ON SUBSCRIPTION",
|
|
26
|
+
this.subscription.name,
|
|
27
|
+
"IS",
|
|
28
|
+
quoteLiteral(this.securityLabel.label),
|
|
29
|
+
].join(" ");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class DropSecurityLabelOnSubscription extends DropSubscriptionChange {
|
|
33
|
+
subscription;
|
|
34
|
+
securityLabel;
|
|
35
|
+
scope = "security_label";
|
|
36
|
+
constructor(props) {
|
|
37
|
+
super();
|
|
38
|
+
this.subscription = props.subscription;
|
|
39
|
+
this.securityLabel = props.securityLabel;
|
|
40
|
+
}
|
|
41
|
+
get drops() {
|
|
42
|
+
return [
|
|
43
|
+
stableId.securityLabel(this.subscription.stableId, this.securityLabel.provider),
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
get requires() {
|
|
47
|
+
return [
|
|
48
|
+
stableId.securityLabel(this.subscription.stableId, this.securityLabel.provider),
|
|
49
|
+
this.subscription.stableId,
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
serialize() {
|
|
53
|
+
return [
|
|
54
|
+
"SECURITY LABEL FOR",
|
|
55
|
+
this.securityLabel.provider,
|
|
56
|
+
"ON SUBSCRIPTION",
|
|
57
|
+
this.subscription.name,
|
|
58
|
+
"IS NULL",
|
|
59
|
+
].join(" ");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -2,5 +2,6 @@ import type { AlterSubscriptionDisable, AlterSubscriptionEnable, AlterSubscripti
|
|
|
2
2
|
import type { CommentSubscription } from "./subscription.comment.ts";
|
|
3
3
|
import type { CreateSubscription } from "./subscription.create.ts";
|
|
4
4
|
import type { DropSubscription } from "./subscription.drop.ts";
|
|
5
|
+
import type { SecurityLabelSubscription } from "./subscription.security-label.ts";
|
|
5
6
|
/** Union of all subscription-related change variants (`objectType: "subscription"`). @category Change Types */
|
|
6
|
-
export type SubscriptionChange = CreateSubscription | DropSubscription | AlterSubscriptionSetConnection | AlterSubscriptionSetPublication | AlterSubscriptionEnable | AlterSubscriptionDisable | AlterSubscriptionSetOptions | AlterSubscriptionSetOwner | CommentSubscription;
|
|
7
|
+
export type SubscriptionChange = CreateSubscription | DropSubscription | AlterSubscriptionSetConnection | AlterSubscriptionSetPublication | AlterSubscriptionEnable | AlterSubscriptionDisable | AlterSubscriptionSetOptions | AlterSubscriptionSetOwner | CommentSubscription | SecurityLabelSubscription;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { diffObjects } from "../base.diff.js";
|
|
2
|
+
import { diffSecurityLabels } from "../security-label.types.js";
|
|
2
3
|
import { hasNonAlterableChanges } from "../utils.js";
|
|
3
4
|
import { AlterSubscriptionDisable, AlterSubscriptionEnable, AlterSubscriptionSetConnection, AlterSubscriptionSetOptions, AlterSubscriptionSetOwner, AlterSubscriptionSetPublication, } from "./changes/subscription.alter.js";
|
|
4
5
|
import { CreateCommentOnSubscription, DropCommentOnSubscription, } from "./changes/subscription.comment.js";
|
|
5
6
|
import { CreateSubscription } from "./changes/subscription.create.js";
|
|
6
7
|
import { DropSubscription } from "./changes/subscription.drop.js";
|
|
8
|
+
import { CreateSecurityLabelOnSubscription, DropSecurityLabelOnSubscription, } from "./changes/subscription.security-label.js";
|
|
7
9
|
const NON_ALTERABLE_FIELDS = [
|
|
8
10
|
"two_phase",
|
|
9
11
|
];
|
|
@@ -35,6 +37,12 @@ export function diffSubscriptions(ctx, main, branch) {
|
|
|
35
37
|
if (subscription.comment !== null) {
|
|
36
38
|
changes.push(new CreateCommentOnSubscription({ subscription }));
|
|
37
39
|
}
|
|
40
|
+
for (const label of subscription.security_labels) {
|
|
41
|
+
changes.push(new CreateSecurityLabelOnSubscription({
|
|
42
|
+
subscription,
|
|
43
|
+
securityLabel: label,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
38
46
|
}
|
|
39
47
|
for (const id of dropped) {
|
|
40
48
|
changes.push(new DropSubscription({ subscription: main[id] }));
|
|
@@ -162,6 +170,14 @@ export function diffSubscriptions(ctx, main, branch) {
|
|
|
162
170
|
}));
|
|
163
171
|
}
|
|
164
172
|
}
|
|
173
|
+
// SECURITY LABELS
|
|
174
|
+
changes.push(...diffSecurityLabels(mainSubscription.security_labels, branchSubscription.security_labels, (securityLabel) => new CreateSecurityLabelOnSubscription({
|
|
175
|
+
subscription: branchSubscription,
|
|
176
|
+
securityLabel,
|
|
177
|
+
}), (securityLabel) => new DropSecurityLabelOnSubscription({
|
|
178
|
+
subscription: mainSubscription,
|
|
179
|
+
securityLabel,
|
|
180
|
+
})));
|
|
165
181
|
}
|
|
166
182
|
return changes;
|
|
167
183
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Pool } from "pg";
|
|
2
2
|
import z from "zod";
|
|
3
3
|
import { BasePgModel } from "../base.model.ts";
|
|
4
|
+
import { type SecurityLabelProps } from "../security-label.types.ts";
|
|
4
5
|
declare const subscriptionPropsSchema: z.ZodObject<{
|
|
5
6
|
name: z.ZodString;
|
|
6
7
|
raw_name: z.ZodString;
|
|
@@ -28,6 +29,10 @@ declare const subscriptionPropsSchema: z.ZodObject<{
|
|
|
28
29
|
any: "any";
|
|
29
30
|
none: "none";
|
|
30
31
|
}>;
|
|
32
|
+
security_labels: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
33
|
+
provider: z.ZodString;
|
|
34
|
+
label: z.ZodString;
|
|
35
|
+
}, z.z.core.$strip>>>>;
|
|
31
36
|
}, z.z.core.$strip>;
|
|
32
37
|
export type SubscriptionProps = z.infer<typeof subscriptionPropsSchema>;
|
|
33
38
|
export declare class Subscription extends BasePgModel {
|
|
@@ -50,6 +55,7 @@ export declare class Subscription extends BasePgModel {
|
|
|
50
55
|
readonly synchronous_commit: SubscriptionProps["synchronous_commit"];
|
|
51
56
|
readonly publications: SubscriptionProps["publications"];
|
|
52
57
|
readonly origin: SubscriptionProps["origin"];
|
|
58
|
+
readonly security_labels: SecurityLabelProps[];
|
|
53
59
|
constructor(props: SubscriptionProps);
|
|
54
60
|
get stableId(): `subscription:${string}`;
|
|
55
61
|
get identityFields(): {
|
|
@@ -74,6 +80,10 @@ export declare class Subscription extends BasePgModel {
|
|
|
74
80
|
synchronous_commit: string;
|
|
75
81
|
publications: string[];
|
|
76
82
|
origin: "any" | "none";
|
|
83
|
+
security_labels: {
|
|
84
|
+
provider: string;
|
|
85
|
+
label: string;
|
|
86
|
+
}[];
|
|
77
87
|
};
|
|
78
88
|
}
|
|
79
89
|
export declare function extractSubscriptions(pool: Pool): Promise<Subscription[]>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
2
|
import { extractVersion } from "../../context.js";
|
|
3
3
|
import { BasePgModel } from "../base.model.js";
|
|
4
|
+
import { securityLabelPropsSchema, } from "../security-label.types.js";
|
|
4
5
|
const subscriptionPropsSchema = z.object({
|
|
5
6
|
name: z.string(),
|
|
6
7
|
raw_name: z.string(),
|
|
@@ -21,6 +22,7 @@ const subscriptionPropsSchema = z.object({
|
|
|
21
22
|
synchronous_commit: z.string(),
|
|
22
23
|
publications: z.array(z.string()),
|
|
23
24
|
origin: z.enum(["any", "none"]),
|
|
25
|
+
security_labels: z.array(securityLabelPropsSchema).default([]).optional(),
|
|
24
26
|
});
|
|
25
27
|
export class Subscription extends BasePgModel {
|
|
26
28
|
name;
|
|
@@ -42,6 +44,7 @@ export class Subscription extends BasePgModel {
|
|
|
42
44
|
synchronous_commit;
|
|
43
45
|
publications;
|
|
44
46
|
origin;
|
|
47
|
+
security_labels;
|
|
45
48
|
constructor(props) {
|
|
46
49
|
super();
|
|
47
50
|
this.name = props.name;
|
|
@@ -63,6 +66,7 @@ export class Subscription extends BasePgModel {
|
|
|
63
66
|
this.synchronous_commit = props.synchronous_commit;
|
|
64
67
|
this.publications = [...props.publications].sort((a, b) => a.localeCompare(b));
|
|
65
68
|
this.origin = props.origin;
|
|
69
|
+
this.security_labels = props.security_labels ?? [];
|
|
66
70
|
}
|
|
67
71
|
get stableId() {
|
|
68
72
|
return `subscription:${this.name}`;
|
|
@@ -92,6 +96,7 @@ export class Subscription extends BasePgModel {
|
|
|
92
96
|
synchronous_commit: this.synchronous_commit,
|
|
93
97
|
publications: this.publications,
|
|
94
98
|
origin: this.origin,
|
|
99
|
+
security_labels: this.security_labels,
|
|
95
100
|
};
|
|
96
101
|
}
|
|
97
102
|
}
|
|
@@ -156,7 +161,20 @@ export async function extractSubscriptions(pool) {
|
|
|
156
161
|
),
|
|
157
162
|
'[]'::json
|
|
158
163
|
) as publications,
|
|
159
|
-
${originExpr} as origin
|
|
164
|
+
${originExpr} as origin,
|
|
165
|
+
coalesce(
|
|
166
|
+
(
|
|
167
|
+
select json_agg(
|
|
168
|
+
json_build_object('provider', sl.provider, 'label', sl.label)
|
|
169
|
+
order by sl.provider
|
|
170
|
+
)
|
|
171
|
+
from pg_catalog.pg_seclabel sl
|
|
172
|
+
where sl.objoid = s.oid
|
|
173
|
+
and sl.classoid = 'pg_subscription'::regclass
|
|
174
|
+
and sl.objsubid = 0
|
|
175
|
+
),
|
|
176
|
+
'[]'::json
|
|
177
|
+
) as security_labels
|
|
160
178
|
from scoped_subscriptions s
|
|
161
179
|
left join pg_replication_slots r
|
|
162
180
|
on r.slot_name = s.subslotname
|
|
@@ -216,16 +216,27 @@ export declare class AlterTableValidateConstraint extends AlterTableChange {
|
|
|
216
216
|
}
|
|
217
217
|
/**
|
|
218
218
|
* ALTER TABLE ... REPLICA IDENTITY ...
|
|
219
|
+
*
|
|
220
|
+
* When `mode === "i"` (USING INDEX), `indexName` is the name of the index to
|
|
221
|
+
* use. The extractor populates `Table.replica_identity_index` from
|
|
222
|
+
* `pg_index.indisreplident` whenever `Table.replica_identity` is `'i'`, so
|
|
223
|
+
* callers that source their props from a `Table` instance can rely on the
|
|
224
|
+
* pair being consistent. The non-null assertions in `requires` / `serialize`
|
|
225
|
+
* below are justified by that data invariant — the same pattern the FK
|
|
226
|
+
* branch of `AlterTableAddConstraint` uses for `foreign_key_columns!` /
|
|
227
|
+
* `foreign_key_table!` / `foreign_key_schema!`.
|
|
219
228
|
*/
|
|
220
229
|
export declare class AlterTableSetReplicaIdentity extends AlterTableChange {
|
|
221
230
|
readonly table: Table;
|
|
222
231
|
readonly mode: "d" | "n" | "f" | "i";
|
|
232
|
+
readonly indexName: string | null;
|
|
223
233
|
readonly scope: "object";
|
|
224
234
|
constructor(props: {
|
|
225
235
|
table: Table;
|
|
226
236
|
mode: "d" | "n" | "f" | "i";
|
|
237
|
+
indexName?: string | null;
|
|
227
238
|
});
|
|
228
|
-
get requires():
|
|
239
|
+
get requires(): string[];
|
|
229
240
|
serialize(_options?: SerializeOptions): string;
|
|
230
241
|
}
|
|
231
242
|
/**
|
|
@@ -302,18 +302,35 @@ export class AlterTableValidateConstraint extends AlterTableChange {
|
|
|
302
302
|
}
|
|
303
303
|
/**
|
|
304
304
|
* ALTER TABLE ... REPLICA IDENTITY ...
|
|
305
|
+
*
|
|
306
|
+
* When `mode === "i"` (USING INDEX), `indexName` is the name of the index to
|
|
307
|
+
* use. The extractor populates `Table.replica_identity_index` from
|
|
308
|
+
* `pg_index.indisreplident` whenever `Table.replica_identity` is `'i'`, so
|
|
309
|
+
* callers that source their props from a `Table` instance can rely on the
|
|
310
|
+
* pair being consistent. The non-null assertions in `requires` / `serialize`
|
|
311
|
+
* below are justified by that data invariant — the same pattern the FK
|
|
312
|
+
* branch of `AlterTableAddConstraint` uses for `foreign_key_columns!` /
|
|
313
|
+
* `foreign_key_table!` / `foreign_key_schema!`.
|
|
305
314
|
*/
|
|
306
315
|
export class AlterTableSetReplicaIdentity extends AlterTableChange {
|
|
307
316
|
table;
|
|
308
317
|
mode;
|
|
318
|
+
indexName;
|
|
309
319
|
scope = "object";
|
|
310
320
|
constructor(props) {
|
|
311
321
|
super();
|
|
312
322
|
this.table = props.table;
|
|
313
323
|
this.mode = props.mode;
|
|
324
|
+
this.indexName = props.indexName ?? null;
|
|
314
325
|
}
|
|
315
326
|
get requires() {
|
|
316
|
-
|
|
327
|
+
const reqs = [this.table.stableId];
|
|
328
|
+
if (this.mode === "i") {
|
|
329
|
+
reqs.push(stableId.index(this.table.schema, this.table.name,
|
|
330
|
+
// biome-ignore lint/style/noNonNullAssertion: mode 'i' implies the extractor populated replica_identity_index
|
|
331
|
+
this.indexName));
|
|
332
|
+
}
|
|
333
|
+
return reqs;
|
|
317
334
|
}
|
|
318
335
|
serialize(_options) {
|
|
319
336
|
const clause = this.mode === "d"
|
|
@@ -322,7 +339,8 @@ export class AlterTableSetReplicaIdentity extends AlterTableChange {
|
|
|
322
339
|
? "NOTHING"
|
|
323
340
|
: this.mode === "f"
|
|
324
341
|
? "FULL"
|
|
325
|
-
:
|
|
342
|
+
: // biome-ignore lint/style/noNonNullAssertion: mode 'i' implies the extractor populated replica_identity_index
|
|
343
|
+
`USING INDEX ${this.indexName}`;
|
|
326
344
|
return [
|
|
327
345
|
"ALTER TABLE",
|
|
328
346
|
`${this.table.schema}.${this.table.name}`,
|
|
@@ -2,7 +2,7 @@ import { BaseChange } from "../../base.change.ts";
|
|
|
2
2
|
import type { Table } from "../table.model.ts";
|
|
3
3
|
declare abstract class BaseTableChange extends BaseChange {
|
|
4
4
|
abstract readonly table: Table;
|
|
5
|
-
abstract readonly scope: "object" | "comment" | "privilege";
|
|
5
|
+
abstract readonly scope: "object" | "comment" | "privilege" | "security_label";
|
|
6
6
|
readonly objectType: "table";
|
|
7
7
|
}
|
|
8
8
|
export declare abstract class CreateTableChange extends BaseTableChange {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ColumnProps } from "../../base.model.ts";
|
|
2
|
+
import type { SecurityLabelProps } from "../../security-label.types.ts";
|
|
3
|
+
import type { Table } from "../table.model.ts";
|
|
4
|
+
import { CreateTableChange, DropTableChange } from "./table.base.ts";
|
|
5
|
+
export type SecurityLabelTable = CreateSecurityLabelOnTable | DropSecurityLabelOnTable | CreateSecurityLabelOnColumn | DropSecurityLabelOnColumn;
|
|
6
|
+
/**
|
|
7
|
+
* SECURITY LABEL FOR <provider> ON TABLE <schema>.<table> IS <literal>
|
|
8
|
+
*/
|
|
9
|
+
export declare class CreateSecurityLabelOnTable extends CreateTableChange {
|
|
10
|
+
readonly table: Table;
|
|
11
|
+
readonly securityLabel: SecurityLabelProps;
|
|
12
|
+
readonly scope: "security_label";
|
|
13
|
+
constructor(props: {
|
|
14
|
+
table: Table;
|
|
15
|
+
securityLabel: SecurityLabelProps;
|
|
16
|
+
});
|
|
17
|
+
get creates(): `securityLabel:${string}::provider:${string}`[];
|
|
18
|
+
get requires(): `table:${string}`[];
|
|
19
|
+
serialize(): string;
|
|
20
|
+
}
|
|
21
|
+
export declare class DropSecurityLabelOnTable extends DropTableChange {
|
|
22
|
+
readonly table: Table;
|
|
23
|
+
readonly securityLabel: SecurityLabelProps;
|
|
24
|
+
readonly scope: "security_label";
|
|
25
|
+
constructor(props: {
|
|
26
|
+
table: Table;
|
|
27
|
+
securityLabel: SecurityLabelProps;
|
|
28
|
+
});
|
|
29
|
+
get drops(): `securityLabel:${string}::provider:${string}`[];
|
|
30
|
+
get requires(): (`securityLabel:${string}::provider:${string}` | `table:${string}`)[];
|
|
31
|
+
serialize(): string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* SECURITY LABEL FOR <provider> ON COLUMN <schema>.<table>.<column> IS <literal>
|
|
35
|
+
*/
|
|
36
|
+
export declare class CreateSecurityLabelOnColumn extends CreateTableChange {
|
|
37
|
+
readonly table: Table;
|
|
38
|
+
readonly column: ColumnProps;
|
|
39
|
+
readonly securityLabel: SecurityLabelProps;
|
|
40
|
+
readonly scope: "security_label";
|
|
41
|
+
constructor(props: {
|
|
42
|
+
table: Table;
|
|
43
|
+
column: ColumnProps;
|
|
44
|
+
securityLabel: SecurityLabelProps;
|
|
45
|
+
});
|
|
46
|
+
get creates(): `securityLabel:${string}::provider:${string}`[];
|
|
47
|
+
get requires(): `column:${string}.${string}.${string}`[];
|
|
48
|
+
serialize(): string;
|
|
49
|
+
}
|
|
50
|
+
export declare class DropSecurityLabelOnColumn extends DropTableChange {
|
|
51
|
+
readonly table: Table;
|
|
52
|
+
readonly column: ColumnProps;
|
|
53
|
+
readonly securityLabel: SecurityLabelProps;
|
|
54
|
+
readonly scope: "security_label";
|
|
55
|
+
constructor(props: {
|
|
56
|
+
table: Table;
|
|
57
|
+
column: ColumnProps;
|
|
58
|
+
securityLabel: SecurityLabelProps;
|
|
59
|
+
});
|
|
60
|
+
get drops(): `securityLabel:${string}::provider:${string}`[];
|
|
61
|
+
get requires(): (`column:${string}.${string}.${string}` | `securityLabel:${string}::provider:${string}`)[];
|
|
62
|
+
serialize(): string;
|
|
63
|
+
}
|