@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,6 +1,6 @@
|
|
|
1
1
|
import debug from "debug";
|
|
2
2
|
import { expandReplaceDependencies } from "./expand-replace-dependencies.js";
|
|
3
|
-
import {
|
|
3
|
+
import { normalizePostDiffChanges } from "./post-diff-normalization.js";
|
|
4
4
|
const debugCatalog = debug("pg-delta:catalog");
|
|
5
5
|
import { diffAggregates } from "./objects/aggregate/aggregate.diff.js";
|
|
6
6
|
import { DefaultPrivilegeState } from "./objects/base.default-privileges.js";
|
|
@@ -126,7 +126,7 @@ export function diffCatalogs(main, branch, options) {
|
|
|
126
126
|
changes.push(...diffProcedures(diffContext, main.procedures, branch.procedures));
|
|
127
127
|
changes.push(...diffRlsPolicies(main.rlsPolicies, branch.rlsPolicies));
|
|
128
128
|
changes.push(...diffSchemas(diffContext, main.schemas, branch.schemas));
|
|
129
|
-
changes.push(...diffSequences(diffContext, main.sequences, branch.sequences, branch.tables));
|
|
129
|
+
changes.push(...diffSequences(diffContext, main.sequences, branch.sequences, branch.tables, main.tables));
|
|
130
130
|
changes.push(...diffTables(diffContext, main.tables, branch.tables));
|
|
131
131
|
changes.push(...diffTriggers(main.triggers, branch.triggers, branch.indexableObjects));
|
|
132
132
|
changes.push(...diffEventTriggers(diffContext, main.eventTriggers, branch.eventTriggers));
|
|
@@ -159,9 +159,10 @@ export function diffCatalogs(main, branch, options) {
|
|
|
159
159
|
mainCatalog: main,
|
|
160
160
|
branchCatalog: branch,
|
|
161
161
|
});
|
|
162
|
-
filteredChanges =
|
|
162
|
+
filteredChanges = normalizePostDiffChanges({
|
|
163
163
|
changes: expandedDependencies.changes,
|
|
164
164
|
replacedTableIds: expandedDependencies.replacedTableIds,
|
|
165
|
+
branchTables: branch.tables,
|
|
165
166
|
});
|
|
166
167
|
debugCatalog("changes catalog diff: %O", stringifyWithBigInt(filteredChanges, 2));
|
|
167
168
|
return filteredChanges;
|
|
@@ -102,5 +102,12 @@ export declare class Catalog {
|
|
|
102
102
|
* to `createPlan`.
|
|
103
103
|
*/
|
|
104
104
|
export declare function createEmptyCatalog(version: number, currentUser: string): Promise<Catalog>;
|
|
105
|
-
|
|
105
|
+
interface ExtractCatalogOptions {
|
|
106
|
+
/**
|
|
107
|
+
* Number of retry attempts for catalog extractors when `pg_get_*def()`
|
|
108
|
+
* returns NULL for at least one row. See `ExtractRetryOptions.retries`.
|
|
109
|
+
*/
|
|
110
|
+
extractRetries?: number;
|
|
111
|
+
}
|
|
112
|
+
export declare function extractCatalog(pool: Pool, options?: ExtractCatalogOptions): Promise<Catalog>;
|
|
106
113
|
export {};
|
|
@@ -157,6 +157,7 @@ export async function createEmptyCatalog(version, currentUser) {
|
|
|
157
157
|
owner: currentUser,
|
|
158
158
|
comment: "standard public schema",
|
|
159
159
|
privileges: [],
|
|
160
|
+
security_labels: [],
|
|
160
161
|
});
|
|
161
162
|
return new Catalog({
|
|
162
163
|
aggregates: {},
|
|
@@ -190,7 +191,8 @@ export async function createEmptyCatalog(version, currentUser) {
|
|
|
190
191
|
currentUser,
|
|
191
192
|
});
|
|
192
193
|
}
|
|
193
|
-
export async function extractCatalog(pool) {
|
|
194
|
+
export async function extractCatalog(pool, options = {}) {
|
|
195
|
+
const retryOptions = { retries: options.extractRetries };
|
|
194
196
|
const [aggregates, collations, compositeTypes, domains, enums, extensions, indexes, materializedViews, subscriptions, publications, procedures, rlsPolicies, roles, schemas, sequences, tables, triggers, eventTriggers, rules, ranges, views, foreignDataWrappers, servers, userMappings, foreignTables, depends, version, currentUser,] = await Promise.all([
|
|
195
197
|
extractAggregates(pool).then(listToRecord),
|
|
196
198
|
extractCollations(pool).then(listToRecord),
|
|
@@ -198,21 +200,21 @@ export async function extractCatalog(pool) {
|
|
|
198
200
|
extractDomains(pool).then(listToRecord),
|
|
199
201
|
extractEnums(pool).then(listToRecord),
|
|
200
202
|
extractExtensions(pool).then(listToRecord),
|
|
201
|
-
extractIndexes(pool).then(listToRecord),
|
|
202
|
-
extractMaterializedViews(pool).then(listToRecord),
|
|
203
|
+
extractIndexes(pool, retryOptions).then(listToRecord),
|
|
204
|
+
extractMaterializedViews(pool, retryOptions).then(listToRecord),
|
|
203
205
|
extractSubscriptions(pool).then(listToRecord),
|
|
204
206
|
extractPublications(pool).then(listToRecord),
|
|
205
|
-
extractProcedures(pool).then(listToRecord),
|
|
207
|
+
extractProcedures(pool, retryOptions).then(listToRecord),
|
|
206
208
|
extractRlsPolicies(pool).then(listToRecord),
|
|
207
209
|
extractRoles(pool).then(listToRecord),
|
|
208
210
|
extractSchemas(pool).then(listToRecord),
|
|
209
211
|
extractSequences(pool).then(listToRecord),
|
|
210
|
-
extractTables(pool).then(listToRecord),
|
|
211
|
-
extractTriggers(pool).then(listToRecord),
|
|
212
|
+
extractTables(pool, retryOptions).then(listToRecord),
|
|
213
|
+
extractTriggers(pool, retryOptions).then(listToRecord),
|
|
212
214
|
extractEventTriggers(pool).then(listToRecord),
|
|
213
|
-
extractRules(pool).then(listToRecord),
|
|
215
|
+
extractRules(pool, retryOptions).then(listToRecord),
|
|
214
216
|
extractRanges(pool).then(listToRecord),
|
|
215
|
-
extractViews(pool).then(listToRecord),
|
|
217
|
+
extractViews(pool, retryOptions).then(listToRecord),
|
|
216
218
|
extractForeignDataWrappers(pool).then(listToRecord),
|
|
217
219
|
extractServers(pool).then(listToRecord),
|
|
218
220
|
extractUserMappings(pool).then(listToRecord),
|
|
@@ -53,6 +53,29 @@ export function expandReplaceDependencies({ changes, mainCatalog, branchCatalog,
|
|
|
53
53
|
replaceRoots.add(id);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
// Drop-only objects (no matching create — typically a renamed-away table or
|
|
57
|
+
// type) are also expansion roots: anything in main that depends on them via
|
|
58
|
+
// pg_depend must drop before the parent does. Without this seed, a renamed
|
|
59
|
+
// table whose dependent view stays in the branch catalog (with an updated
|
|
60
|
+
// definition that no longer references the old name) would still try to
|
|
61
|
+
// run DROP TABLE old_name while old_name is referenced by the view, which
|
|
62
|
+
// PostgreSQL refuses without CASCADE. The walk below promotes the surviving
|
|
63
|
+
// dependent to DROP+CREATE so its drop is sequenced before the parent drop.
|
|
64
|
+
for (const id of droppedIds) {
|
|
65
|
+
if (createdIds.has(id))
|
|
66
|
+
continue;
|
|
67
|
+
if (replaceRoots.has(id))
|
|
68
|
+
continue;
|
|
69
|
+
// Only seed for object kinds that can have catalog dependents we know
|
|
70
|
+
// how to recreate via buildReplaceChanges.
|
|
71
|
+
if (id.startsWith("table:") ||
|
|
72
|
+
id.startsWith("view:") ||
|
|
73
|
+
id.startsWith("materializedView:") ||
|
|
74
|
+
id.startsWith("type:") ||
|
|
75
|
+
id.startsWith("domain:")) {
|
|
76
|
+
replaceRoots.add(id);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
56
79
|
if (replaceRoots.size === 0) {
|
|
57
80
|
return {
|
|
58
81
|
changes,
|
|
@@ -75,6 +75,19 @@ export function flattenChange(change) {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
+
else if (key === "securityLabel" &&
|
|
79
|
+
value &&
|
|
80
|
+
typeof value === "object" &&
|
|
81
|
+
!Array.isArray(value)) {
|
|
82
|
+
// Security labels are change-level metadata, so expose provider/label as
|
|
83
|
+
// bare keys for filters like { scope: "security_label", provider: "..." }.
|
|
84
|
+
for (const [subKey, subValue] of Object.entries(value)) {
|
|
85
|
+
const flatVal = toFlatValue(subValue);
|
|
86
|
+
if (flatVal !== undefined) {
|
|
87
|
+
flat[subKey] = flatVal;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
78
91
|
else {
|
|
79
92
|
const flatVal = toFlatValue(value);
|
|
80
93
|
if (flatVal !== undefined) {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { diffObjects } from "../base.diff.js";
|
|
2
2
|
import { diffPrivileges, emitObjectPrivilegeChanges, filterPublicBuiltInDefaults, } from "../base.privilege-diff.js";
|
|
3
|
+
import { diffSecurityLabels } from "../security-label.types.js";
|
|
3
4
|
import { deepEqual, hasNonAlterableChanges } from "../utils.js";
|
|
4
5
|
import { AlterAggregateChangeOwner } from "./changes/aggregate.alter.js";
|
|
5
6
|
import { CreateCommentOnAggregate, DropCommentOnAggregate, } from "./changes/aggregate.comment.js";
|
|
6
7
|
import { CreateAggregate } from "./changes/aggregate.create.js";
|
|
7
8
|
import { DropAggregate } from "./changes/aggregate.drop.js";
|
|
8
9
|
import { GrantAggregatePrivileges, RevokeAggregatePrivileges, RevokeGrantOptionAggregatePrivileges, } from "./changes/aggregate.privilege.js";
|
|
10
|
+
import { CreateSecurityLabelOnAggregate, DropSecurityLabelOnAggregate, } from "./changes/aggregate.security-label.js";
|
|
9
11
|
export function diffAggregates(ctx, main, branch) {
|
|
10
12
|
const { created, dropped, altered } = diffObjects(main, branch);
|
|
11
13
|
const changes = [];
|
|
@@ -23,6 +25,12 @@ export function diffAggregates(ctx, main, branch) {
|
|
|
23
25
|
if (aggregate.comment !== null) {
|
|
24
26
|
changes.push(new CreateCommentOnAggregate({ aggregate }));
|
|
25
27
|
}
|
|
28
|
+
for (const label of aggregate.security_labels) {
|
|
29
|
+
changes.push(new CreateSecurityLabelOnAggregate({
|
|
30
|
+
aggregate,
|
|
31
|
+
securityLabel: label,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
26
34
|
// PRIVILEGES: For created objects, compare against default privileges state
|
|
27
35
|
// The migration script will run ALTER DEFAULT PRIVILEGES before CREATE (via constraint spec),
|
|
28
36
|
// so objects are created with the default privileges state in effect.
|
|
@@ -113,6 +121,14 @@ export function diffAggregates(ctx, main, branch) {
|
|
|
113
121
|
changes.push(new CreateCommentOnAggregate({ aggregate: branchAggregate }));
|
|
114
122
|
}
|
|
115
123
|
}
|
|
124
|
+
// SECURITY LABELS
|
|
125
|
+
changes.push(...diffSecurityLabels(mainAggregate.security_labels, branchAggregate.security_labels, (securityLabel) => new CreateSecurityLabelOnAggregate({
|
|
126
|
+
aggregate: branchAggregate,
|
|
127
|
+
securityLabel,
|
|
128
|
+
}), (securityLabel) => new DropSecurityLabelOnAggregate({
|
|
129
|
+
aggregate: mainAggregate,
|
|
130
|
+
securityLabel,
|
|
131
|
+
})));
|
|
116
132
|
// PRIVILEGES
|
|
117
133
|
// Filter out PUBLIC's built-in default EXECUTE privilege from main catalog
|
|
118
134
|
// (PostgreSQL grants it automatically, so we shouldn't compare it)
|
|
@@ -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 aggregatePropsSchema: z.ZodObject<{
|
|
6
7
|
schema: z.ZodString;
|
|
7
8
|
name: z.ZodString;
|
|
@@ -71,6 +72,10 @@ declare const aggregatePropsSchema: z.ZodObject<{
|
|
|
71
72
|
grantable: z.ZodBoolean;
|
|
72
73
|
columns: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
73
74
|
}, z.z.core.$strip>>;
|
|
75
|
+
security_labels: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
76
|
+
provider: z.ZodString;
|
|
77
|
+
label: z.ZodString;
|
|
78
|
+
}, z.z.core.$strip>>>>;
|
|
74
79
|
}, z.z.core.$strip>;
|
|
75
80
|
type AggregatePrivilegeProps = PrivilegeProps;
|
|
76
81
|
type AggregateProps = z.infer<typeof aggregatePropsSchema>;
|
|
@@ -116,6 +121,7 @@ export declare class Aggregate extends BasePgModel {
|
|
|
116
121
|
readonly owner: AggregateProps["owner"];
|
|
117
122
|
readonly comment: AggregateProps["comment"];
|
|
118
123
|
readonly privileges: AggregatePrivilegeProps[];
|
|
124
|
+
readonly security_labels: SecurityLabelProps[];
|
|
119
125
|
constructor(props: AggregateProps);
|
|
120
126
|
get stableId(): `aggregate:${string}`;
|
|
121
127
|
get identityFields(): {
|
|
@@ -168,6 +174,10 @@ export declare class Aggregate extends BasePgModel {
|
|
|
168
174
|
grantable: boolean;
|
|
169
175
|
columns?: string[] | null | undefined;
|
|
170
176
|
}[];
|
|
177
|
+
security_labels: {
|
|
178
|
+
provider: string;
|
|
179
|
+
label: string;
|
|
180
|
+
}[];
|
|
171
181
|
};
|
|
172
182
|
}
|
|
173
183
|
export declare function extractAggregates(pool: Pool): Promise<Aggregate[]>;
|
|
@@ -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 AggregateKindSchema = z.enum([
|
|
6
7
|
"n", // normal aggregate
|
|
7
8
|
"o", // ordered-set aggregate
|
|
@@ -66,6 +67,7 @@ const aggregatePropsSchema = z.object({
|
|
|
66
67
|
owner: z.string(),
|
|
67
68
|
comment: z.string().nullable(),
|
|
68
69
|
privileges: z.array(privilegePropsSchema),
|
|
70
|
+
security_labels: z.array(securityLabelPropsSchema).default([]).optional(),
|
|
69
71
|
});
|
|
70
72
|
export class Aggregate extends BasePgModel {
|
|
71
73
|
schema;
|
|
@@ -109,6 +111,7 @@ export class Aggregate extends BasePgModel {
|
|
|
109
111
|
owner;
|
|
110
112
|
comment;
|
|
111
113
|
privileges;
|
|
114
|
+
security_labels;
|
|
112
115
|
constructor(props) {
|
|
113
116
|
super();
|
|
114
117
|
this.schema = props.schema;
|
|
@@ -153,6 +156,7 @@ export class Aggregate extends BasePgModel {
|
|
|
153
156
|
this.owner = props.owner;
|
|
154
157
|
this.comment = props.comment;
|
|
155
158
|
this.privileges = props.privileges;
|
|
159
|
+
this.security_labels = props.security_labels ?? [];
|
|
156
160
|
}
|
|
157
161
|
get stableId() {
|
|
158
162
|
const normalized = this.identityArguments;
|
|
@@ -206,6 +210,7 @@ export class Aggregate extends BasePgModel {
|
|
|
206
210
|
owner: this.owner,
|
|
207
211
|
comment: this.comment,
|
|
208
212
|
privileges: this.privileges,
|
|
213
|
+
security_labels: this.security_labels,
|
|
209
214
|
};
|
|
210
215
|
}
|
|
211
216
|
}
|
|
@@ -275,7 +280,20 @@ select
|
|
|
275
280
|
)
|
|
276
281
|
from lateral aclexplode(COALESCE(p.proacl, acldefault('f', p.proowner))) as x(grantor, grantee, privilege_type, is_grantable)
|
|
277
282
|
), '[]'
|
|
278
|
-
) as privileges
|
|
283
|
+
) as privileges,
|
|
284
|
+
coalesce(
|
|
285
|
+
(
|
|
286
|
+
select json_agg(
|
|
287
|
+
json_build_object('provider', sl.provider, 'label', sl.label)
|
|
288
|
+
order by sl.provider
|
|
289
|
+
)
|
|
290
|
+
from pg_catalog.pg_seclabel sl
|
|
291
|
+
where sl.objoid = p.oid
|
|
292
|
+
and sl.classoid = 'pg_proc'::regclass
|
|
293
|
+
and sl.objsubid = 0
|
|
294
|
+
),
|
|
295
|
+
'[]'::json
|
|
296
|
+
) as security_labels
|
|
279
297
|
from
|
|
280
298
|
pg_catalog.pg_proc p
|
|
281
299
|
inner join pg_catalog.pg_aggregate a on a.aggfnoid = p.oid
|
|
@@ -2,7 +2,7 @@ import { BaseChange } from "../../base.change.ts";
|
|
|
2
2
|
import type { Aggregate } from "../aggregate.model.ts";
|
|
3
3
|
declare abstract class BaseAggregateChange extends BaseChange {
|
|
4
4
|
abstract readonly aggregate: Aggregate;
|
|
5
|
-
abstract readonly scope: "object" | "comment" | "privilege";
|
|
5
|
+
abstract readonly scope: "object" | "comment" | "privilege" | "security_label";
|
|
6
6
|
readonly objectType: "aggregate";
|
|
7
7
|
}
|
|
8
8
|
export declare abstract class CreateAggregateChange extends BaseAggregateChange {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { SecurityLabelProps } from "../../security-label.types.ts";
|
|
2
|
+
import type { Aggregate } from "../aggregate.model.ts";
|
|
3
|
+
import { CreateAggregateChange, DropAggregateChange } from "./aggregate.base.ts";
|
|
4
|
+
export type SecurityLabelAggregate = CreateSecurityLabelOnAggregate | DropSecurityLabelOnAggregate;
|
|
5
|
+
export declare class CreateSecurityLabelOnAggregate extends CreateAggregateChange {
|
|
6
|
+
readonly aggregate: Aggregate;
|
|
7
|
+
readonly securityLabel: SecurityLabelProps;
|
|
8
|
+
readonly scope: "security_label";
|
|
9
|
+
constructor(props: {
|
|
10
|
+
aggregate: Aggregate;
|
|
11
|
+
securityLabel: SecurityLabelProps;
|
|
12
|
+
});
|
|
13
|
+
get creates(): `securityLabel:${string}::provider:${string}`[];
|
|
14
|
+
get requires(): `aggregate:${string}`[];
|
|
15
|
+
serialize(): string;
|
|
16
|
+
}
|
|
17
|
+
export declare class DropSecurityLabelOnAggregate extends DropAggregateChange {
|
|
18
|
+
readonly aggregate: Aggregate;
|
|
19
|
+
readonly securityLabel: SecurityLabelProps;
|
|
20
|
+
readonly scope: "security_label";
|
|
21
|
+
constructor(props: {
|
|
22
|
+
aggregate: Aggregate;
|
|
23
|
+
securityLabel: SecurityLabelProps;
|
|
24
|
+
});
|
|
25
|
+
get drops(): `securityLabel:${string}::provider:${string}`[];
|
|
26
|
+
get requires(): (`securityLabel:${string}::provider:${string}` | `aggregate:${string}`)[];
|
|
27
|
+
serialize(): string;
|
|
28
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { quoteLiteral } from "../../base.change.js";
|
|
2
|
+
import { stableId } from "../../utils.js";
|
|
3
|
+
import { CreateAggregateChange, DropAggregateChange, } from "./aggregate.base.js";
|
|
4
|
+
function aggregateIdentity(a) {
|
|
5
|
+
return `${a.schema}.${a.name}(${a.identityArguments})`;
|
|
6
|
+
}
|
|
7
|
+
export class CreateSecurityLabelOnAggregate extends CreateAggregateChange {
|
|
8
|
+
aggregate;
|
|
9
|
+
securityLabel;
|
|
10
|
+
scope = "security_label";
|
|
11
|
+
constructor(props) {
|
|
12
|
+
super();
|
|
13
|
+
this.aggregate = props.aggregate;
|
|
14
|
+
this.securityLabel = props.securityLabel;
|
|
15
|
+
}
|
|
16
|
+
get creates() {
|
|
17
|
+
return [
|
|
18
|
+
stableId.securityLabel(this.aggregate.stableId, this.securityLabel.provider),
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
get requires() {
|
|
22
|
+
return [this.aggregate.stableId];
|
|
23
|
+
}
|
|
24
|
+
serialize() {
|
|
25
|
+
return [
|
|
26
|
+
"SECURITY LABEL FOR",
|
|
27
|
+
this.securityLabel.provider,
|
|
28
|
+
"ON AGGREGATE",
|
|
29
|
+
aggregateIdentity(this.aggregate),
|
|
30
|
+
"IS",
|
|
31
|
+
quoteLiteral(this.securityLabel.label),
|
|
32
|
+
].join(" ");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class DropSecurityLabelOnAggregate extends DropAggregateChange {
|
|
36
|
+
aggregate;
|
|
37
|
+
securityLabel;
|
|
38
|
+
scope = "security_label";
|
|
39
|
+
constructor(props) {
|
|
40
|
+
super();
|
|
41
|
+
this.aggregate = props.aggregate;
|
|
42
|
+
this.securityLabel = props.securityLabel;
|
|
43
|
+
}
|
|
44
|
+
get drops() {
|
|
45
|
+
return [
|
|
46
|
+
stableId.securityLabel(this.aggregate.stableId, this.securityLabel.provider),
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
get requires() {
|
|
50
|
+
return [
|
|
51
|
+
stableId.securityLabel(this.aggregate.stableId, this.securityLabel.provider),
|
|
52
|
+
this.aggregate.stableId,
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
serialize() {
|
|
56
|
+
return [
|
|
57
|
+
"SECURITY LABEL FOR",
|
|
58
|
+
this.securityLabel.provider,
|
|
59
|
+
"ON AGGREGATE",
|
|
60
|
+
aggregateIdentity(this.aggregate),
|
|
61
|
+
"IS NULL",
|
|
62
|
+
].join(" ");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -3,5 +3,6 @@ import type { CommentAggregate } from "./aggregate.comment.ts";
|
|
|
3
3
|
import type { CreateAggregate } from "./aggregate.create.ts";
|
|
4
4
|
import type { DropAggregate } from "./aggregate.drop.ts";
|
|
5
5
|
import type { AggregatePrivilege } from "./aggregate.privilege.ts";
|
|
6
|
+
import type { SecurityLabelAggregate } from "./aggregate.security-label.ts";
|
|
6
7
|
/** Union of all aggregate-related change variants (`objectType: "aggregate"`). @category Change Types */
|
|
7
|
-
export type AggregateChange = AlterAggregate | CommentAggregate | CreateAggregate | DropAggregate | AggregatePrivilege;
|
|
8
|
+
export type AggregateChange = AlterAggregate | CommentAggregate | CreateAggregate | DropAggregate | AggregatePrivilege | SecurityLabelAggregate;
|
|
@@ -16,6 +16,10 @@ export declare const columnPropsSchema: z.ZodObject<{
|
|
|
16
16
|
collation: z.ZodNullable<z.ZodString>;
|
|
17
17
|
default: z.ZodNullable<z.ZodString>;
|
|
18
18
|
comment: z.ZodNullable<z.ZodString>;
|
|
19
|
+
security_labels: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
20
|
+
provider: z.ZodString;
|
|
21
|
+
label: z.ZodString;
|
|
22
|
+
}, z.z.core.$strip>>>;
|
|
19
23
|
}, z.z.core.$strip>;
|
|
20
24
|
export type ColumnProps = z.infer<typeof columnPropsSchema>;
|
|
21
25
|
export declare function normalizeColumns(columns: ColumnProps[]): {
|
|
@@ -34,6 +38,10 @@ export declare function normalizeColumns(columns: ColumnProps[]): {
|
|
|
34
38
|
collation: string | null;
|
|
35
39
|
default: string | null;
|
|
36
40
|
comment: string | null;
|
|
41
|
+
security_labels?: {
|
|
42
|
+
provider: string;
|
|
43
|
+
label: string;
|
|
44
|
+
}[] | undefined;
|
|
37
45
|
}[];
|
|
38
46
|
/**
|
|
39
47
|
* Interface for table-like objects that have columns (tables, views, materialized views).
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
+
import { securityLabelPropsSchema } from "./security-label.types.js";
|
|
2
3
|
import { deepEqual } from "./utils.js";
|
|
3
4
|
export const columnPropsSchema = z.object({
|
|
4
5
|
name: z.string(),
|
|
@@ -17,6 +18,7 @@ export const columnPropsSchema = z.object({
|
|
|
17
18
|
collation: z.string().nullable(),
|
|
18
19
|
default: z.string().nullable(),
|
|
19
20
|
comment: z.string().nullable(),
|
|
21
|
+
security_labels: z.array(securityLabelPropsSchema).optional(),
|
|
20
22
|
});
|
|
21
23
|
export function normalizeColumns(columns) {
|
|
22
24
|
return columns
|
|
@@ -2,7 +2,7 @@ import { BaseChange } from "../../base.change.ts";
|
|
|
2
2
|
import type { Domain } from "../domain.model.ts";
|
|
3
3
|
declare abstract class BaseDomainChange extends BaseChange {
|
|
4
4
|
abstract readonly domain: Domain;
|
|
5
|
-
abstract readonly scope: "object" | "comment" | "privilege";
|
|
5
|
+
abstract readonly scope: "object" | "comment" | "privilege" | "security_label";
|
|
6
6
|
readonly objectType: "domain";
|
|
7
7
|
}
|
|
8
8
|
export declare abstract class CreateDomainChange extends BaseDomainChange {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { SecurityLabelProps } from "../../security-label.types.ts";
|
|
2
|
+
import type { Domain } from "../domain.model.ts";
|
|
3
|
+
import { CreateDomainChange, DropDomainChange } from "./domain.base.ts";
|
|
4
|
+
export type SecurityLabelDomain = CreateSecurityLabelOnDomain | DropSecurityLabelOnDomain;
|
|
5
|
+
export declare class CreateSecurityLabelOnDomain extends CreateDomainChange {
|
|
6
|
+
readonly domain: Domain;
|
|
7
|
+
readonly securityLabel: SecurityLabelProps;
|
|
8
|
+
readonly scope: "security_label";
|
|
9
|
+
constructor(props: {
|
|
10
|
+
domain: Domain;
|
|
11
|
+
securityLabel: SecurityLabelProps;
|
|
12
|
+
});
|
|
13
|
+
get creates(): `securityLabel:${string}::provider:${string}`[];
|
|
14
|
+
get requires(): `domain:${string}`[];
|
|
15
|
+
serialize(): string;
|
|
16
|
+
}
|
|
17
|
+
export declare class DropSecurityLabelOnDomain extends DropDomainChange {
|
|
18
|
+
readonly domain: Domain;
|
|
19
|
+
readonly securityLabel: SecurityLabelProps;
|
|
20
|
+
readonly scope: "security_label";
|
|
21
|
+
constructor(props: {
|
|
22
|
+
domain: Domain;
|
|
23
|
+
securityLabel: SecurityLabelProps;
|
|
24
|
+
});
|
|
25
|
+
get drops(): `securityLabel:${string}::provider:${string}`[];
|
|
26
|
+
get requires(): (`securityLabel:${string}::provider:${string}` | `domain:${string}`)[];
|
|
27
|
+
serialize(): string;
|
|
28
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { quoteLiteral } from "../../base.change.js";
|
|
2
|
+
import { stableId } from "../../utils.js";
|
|
3
|
+
import { CreateDomainChange, DropDomainChange } from "./domain.base.js";
|
|
4
|
+
export class CreateSecurityLabelOnDomain extends CreateDomainChange {
|
|
5
|
+
domain;
|
|
6
|
+
securityLabel;
|
|
7
|
+
scope = "security_label";
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super();
|
|
10
|
+
this.domain = props.domain;
|
|
11
|
+
this.securityLabel = props.securityLabel;
|
|
12
|
+
}
|
|
13
|
+
get creates() {
|
|
14
|
+
return [
|
|
15
|
+
stableId.securityLabel(this.domain.stableId, this.securityLabel.provider),
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
get requires() {
|
|
19
|
+
return [this.domain.stableId];
|
|
20
|
+
}
|
|
21
|
+
serialize() {
|
|
22
|
+
return [
|
|
23
|
+
"SECURITY LABEL FOR",
|
|
24
|
+
this.securityLabel.provider,
|
|
25
|
+
"ON DOMAIN",
|
|
26
|
+
`${this.domain.schema}.${this.domain.name}`,
|
|
27
|
+
"IS",
|
|
28
|
+
quoteLiteral(this.securityLabel.label),
|
|
29
|
+
].join(" ");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class DropSecurityLabelOnDomain extends DropDomainChange {
|
|
33
|
+
domain;
|
|
34
|
+
securityLabel;
|
|
35
|
+
scope = "security_label";
|
|
36
|
+
constructor(props) {
|
|
37
|
+
super();
|
|
38
|
+
this.domain = props.domain;
|
|
39
|
+
this.securityLabel = props.securityLabel;
|
|
40
|
+
}
|
|
41
|
+
get drops() {
|
|
42
|
+
return [
|
|
43
|
+
stableId.securityLabel(this.domain.stableId, this.securityLabel.provider),
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
get requires() {
|
|
47
|
+
return [
|
|
48
|
+
stableId.securityLabel(this.domain.stableId, this.securityLabel.provider),
|
|
49
|
+
this.domain.stableId,
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
serialize() {
|
|
53
|
+
return [
|
|
54
|
+
"SECURITY LABEL FOR",
|
|
55
|
+
this.securityLabel.provider,
|
|
56
|
+
"ON DOMAIN",
|
|
57
|
+
`${this.domain.schema}.${this.domain.name}`,
|
|
58
|
+
"IS NULL",
|
|
59
|
+
].join(" ");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -3,5 +3,6 @@ import type { CommentDomain } from "./domain.comment.ts";
|
|
|
3
3
|
import type { CreateDomain } from "./domain.create.ts";
|
|
4
4
|
import type { DropDomain } from "./domain.drop.ts";
|
|
5
5
|
import type { DomainPrivilege } from "./domain.privilege.ts";
|
|
6
|
+
import type { SecurityLabelDomain } from "./domain.security-label.ts";
|
|
6
7
|
/** Union of all domain-related change variants (`objectType: "domain"`). @category Change Types */
|
|
7
|
-
export type DomainChange = AlterDomain | CommentDomain | CreateDomain | DropDomain | DomainPrivilege;
|
|
8
|
+
export type DomainChange = AlterDomain | CommentDomain | CreateDomain | DropDomain | DomainPrivilege | SecurityLabelDomain;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { diffObjects } from "../base.diff.js";
|
|
2
2
|
import { diffPrivileges, emitObjectPrivilegeChanges, filterPublicBuiltInDefaults, } from "../base.privilege-diff.js";
|
|
3
|
+
import { diffSecurityLabels } from "../security-label.types.js";
|
|
3
4
|
import { AlterDomainAddConstraint, AlterDomainChangeOwner, AlterDomainDropConstraint, AlterDomainDropDefault, AlterDomainDropNotNull, AlterDomainSetDefault, AlterDomainSetNotNull, AlterDomainValidateConstraint, } from "./changes/domain.alter.js";
|
|
4
5
|
import { CreateCommentOnDomain, DropCommentOnDomain, } from "./changes/domain.comment.js";
|
|
5
6
|
import { CreateDomain } from "./changes/domain.create.js";
|
|
6
7
|
import { DropDomain } from "./changes/domain.drop.js";
|
|
7
8
|
import { GrantDomainPrivileges, RevokeDomainPrivileges, RevokeGrantOptionDomainPrivileges, } from "./changes/domain.privilege.js";
|
|
9
|
+
import { CreateSecurityLabelOnDomain, DropSecurityLabelOnDomain, } from "./changes/domain.security-label.js";
|
|
8
10
|
/**
|
|
9
11
|
* Diff two sets of domains from main and branch catalogs.
|
|
10
12
|
*
|
|
@@ -30,6 +32,12 @@ export function diffDomains(ctx, main, branch) {
|
|
|
30
32
|
if (newDomain.comment !== null) {
|
|
31
33
|
changes.push(new CreateCommentOnDomain({ domain: newDomain }));
|
|
32
34
|
}
|
|
35
|
+
for (const label of newDomain.security_labels) {
|
|
36
|
+
changes.push(new CreateSecurityLabelOnDomain({
|
|
37
|
+
domain: newDomain,
|
|
38
|
+
securityLabel: label,
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
33
41
|
// For unvalidated constraints, CREATE DOMAIN cannot specify NOT VALID.
|
|
34
42
|
// Add them after creation and validate to match branch state semantics.
|
|
35
43
|
// For already validated constraints, they are emitted inline in CREATE DOMAIN.
|
|
@@ -164,6 +172,14 @@ export function diffDomains(ctx, main, branch) {
|
|
|
164
172
|
changes.push(new CreateCommentOnDomain({ domain: branchDomain }));
|
|
165
173
|
}
|
|
166
174
|
}
|
|
175
|
+
// SECURITY LABELS
|
|
176
|
+
changes.push(...diffSecurityLabels(mainDomain.security_labels, branchDomain.security_labels, (securityLabel) => new CreateSecurityLabelOnDomain({
|
|
177
|
+
domain: branchDomain,
|
|
178
|
+
securityLabel,
|
|
179
|
+
}), (securityLabel) => new DropSecurityLabelOnDomain({
|
|
180
|
+
domain: mainDomain,
|
|
181
|
+
securityLabel,
|
|
182
|
+
})));
|
|
167
183
|
// PRIVILEGES
|
|
168
184
|
// Filter out PUBLIC's built-in default USAGE privilege from main catalog
|
|
169
185
|
// (PostgreSQL grants it automatically, so we shouldn't compare it)
|
|
@@ -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 domainConstraintPropsSchema: z.ZodObject<{
|
|
6
7
|
name: z.ZodString;
|
|
7
8
|
validated: z.ZodBoolean;
|
|
@@ -36,6 +37,10 @@ declare const domainPropsSchema: z.ZodObject<{
|
|
|
36
37
|
grantable: z.ZodBoolean;
|
|
37
38
|
columns: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
38
39
|
}, z.z.core.$strip>>;
|
|
40
|
+
security_labels: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
41
|
+
provider: z.ZodString;
|
|
42
|
+
label: z.ZodString;
|
|
43
|
+
}, z.z.core.$strip>>>>;
|
|
39
44
|
}, z.z.core.$strip>;
|
|
40
45
|
export type DomainConstraintProps = z.infer<typeof domainConstraintPropsSchema>;
|
|
41
46
|
type DomainPrivilegeProps = PrivilegeProps;
|
|
@@ -61,6 +66,7 @@ export declare class Domain extends BasePgModel {
|
|
|
61
66
|
readonly comment: DomainProps["comment"];
|
|
62
67
|
readonly constraints: DomainConstraintProps[];
|
|
63
68
|
readonly privileges: DomainPrivilegeProps[];
|
|
69
|
+
readonly security_labels: SecurityLabelProps[];
|
|
64
70
|
constructor(props: DomainProps);
|
|
65
71
|
get stableId(): `domain:${string}`;
|
|
66
72
|
get identityFields(): {
|
|
@@ -91,6 +97,10 @@ export declare class Domain extends BasePgModel {
|
|
|
91
97
|
grantable: boolean;
|
|
92
98
|
columns?: string[] | null | undefined;
|
|
93
99
|
}[];
|
|
100
|
+
security_labels: {
|
|
101
|
+
provider: string;
|
|
102
|
+
label: string;
|
|
103
|
+
}[];
|
|
94
104
|
};
|
|
95
105
|
}
|
|
96
106
|
/**
|