@supabase/pg-delta 1.0.0-alpha.22 → 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.model.js +1 -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/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/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 +22 -0
- package/dist/core/objects/materialized-view/materialized-view.model.js +20 -1
- 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 +10 -0
- package/dist/core/objects/procedure/procedure.model.js +19 -1
- 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/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/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.js +16 -0
- 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.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 +49 -0
- package/dist/core/objects/table/table.model.d.ts +30 -0
- package/dist/core/objects/table/table.model.js +34 -2
- 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 +1 -0
- package/dist/core/objects/utils.js +3 -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 +26 -0
- package/dist/core/objects/view/view.model.js +20 -1
- package/dist/core/plan/sql-format/fixtures.js +1 -0
- package/package.json +1 -1
- package/src/core/catalog.model.ts +1 -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/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/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.ts +25 -4
- 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.ts +23 -2
- 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/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/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.ts +33 -0
- 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.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 +87 -0
- package/src/core/objects/table/table.model.ts +42 -2
- 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 +3 -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.ts +25 -2
- package/src/core/plan/sql-format/fixtures.ts +1 -0
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { diffObjects } from "../base.diff.js";
|
|
2
2
|
import { diffPrivileges, emitColumnPrivilegeChanges, } from "../base.privilege-diff.js";
|
|
3
|
+
import { diffSecurityLabels } from "../security-label.types.js";
|
|
3
4
|
import { deepEqual } from "../utils.js";
|
|
4
5
|
import { AlterTableAddColumn, AlterTableAddConstraint, AlterTableAlterColumnAddIdentity, AlterTableAlterColumnDropDefault, AlterTableAlterColumnDropIdentity, AlterTableAlterColumnDropNotNull, AlterTableAlterColumnSetDefault, AlterTableAlterColumnSetGenerated, AlterTableAlterColumnSetNotNull, AlterTableAlterColumnType, AlterTableAttachPartition, AlterTableChangeOwner, AlterTableDetachPartition, AlterTableDisableRowLevelSecurity, AlterTableDropColumn, AlterTableDropConstraint, AlterTableEnableRowLevelSecurity, AlterTableForceRowLevelSecurity, AlterTableNoForceRowLevelSecurity, AlterTableResetStorageParams, AlterTableSetLogged, AlterTableSetReplicaIdentity, AlterTableSetStorageParams, AlterTableSetUnlogged, AlterTableValidateConstraint, } from "./changes/table.alter.js";
|
|
5
6
|
import { CreateCommentOnColumn, CreateCommentOnConstraint, CreateCommentOnTable, DropCommentOnColumn, DropCommentOnConstraint, DropCommentOnTable, } from "./changes/table.comment.js";
|
|
6
7
|
import { CreateTable } from "./changes/table.create.js";
|
|
7
8
|
import { DropTable } from "./changes/table.drop.js";
|
|
8
9
|
import { GrantTablePrivileges, RevokeGrantOptionTablePrivileges, RevokeTablePrivileges, } from "./changes/table.privilege.js";
|
|
10
|
+
import { CreateSecurityLabelOnColumn, CreateSecurityLabelOnTable, DropSecurityLabelOnColumn, DropSecurityLabelOnTable, } from "./changes/table.security-label.js";
|
|
9
11
|
import { Table } from "./table.model.js";
|
|
10
12
|
function createAlterConstraintChange(mainTable, branchTable) {
|
|
11
13
|
const changes = [];
|
|
@@ -174,6 +176,23 @@ export function diffTables(ctx, main, branch) {
|
|
|
174
176
|
changes.push(new CreateCommentOnColumn({ table: branchTable, column: col }));
|
|
175
177
|
}
|
|
176
178
|
}
|
|
179
|
+
// Table security labels on creation
|
|
180
|
+
for (const label of branchTable.security_labels) {
|
|
181
|
+
changes.push(new CreateSecurityLabelOnTable({
|
|
182
|
+
table: branchTable,
|
|
183
|
+
securityLabel: label,
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
// Column security labels on creation
|
|
187
|
+
for (const col of branchTable.columns) {
|
|
188
|
+
for (const label of col.security_labels ?? []) {
|
|
189
|
+
changes.push(new CreateSecurityLabelOnColumn({
|
|
190
|
+
table: branchTable,
|
|
191
|
+
column: col,
|
|
192
|
+
securityLabel: label,
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
177
196
|
// PRIVILEGES: For created objects, compare against default privileges state
|
|
178
197
|
// The migration script will run ALTER DEFAULT PRIVILEGES before CREATE (via constraint spec),
|
|
179
198
|
// so objects are created with the default privileges state in effect.
|
|
@@ -290,6 +309,14 @@ export function diffTables(ctx, main, branch) {
|
|
|
290
309
|
changes.push(new CreateCommentOnTable({ table: branchTable }));
|
|
291
310
|
}
|
|
292
311
|
}
|
|
312
|
+
// TABLE SECURITY LABELS
|
|
313
|
+
changes.push(...diffSecurityLabels(mainTable.security_labels, branchTable.security_labels, (securityLabel) => new CreateSecurityLabelOnTable({
|
|
314
|
+
table: branchTable,
|
|
315
|
+
securityLabel,
|
|
316
|
+
}), (securityLabel) => new DropSecurityLabelOnTable({
|
|
317
|
+
table: mainTable,
|
|
318
|
+
securityLabel,
|
|
319
|
+
})));
|
|
293
320
|
// PARTITION ATTACH/DETACH
|
|
294
321
|
const mainIsPartition = Boolean(mainTable.parent_schema && mainTable.parent_name);
|
|
295
322
|
const branchIsPartition = Boolean(branchTable.parent_schema && branchTable.parent_name);
|
|
@@ -596,6 +623,28 @@ export function diffTables(ctx, main, branch) {
|
|
|
596
623
|
}));
|
|
597
624
|
}
|
|
598
625
|
}
|
|
626
|
+
// SECURITY LABELS on column
|
|
627
|
+
changes.push(...diffSecurityLabels(mainCol.security_labels ?? [], branchCol.security_labels ?? [], (securityLabel) => new CreateSecurityLabelOnColumn({
|
|
628
|
+
table: branchTable,
|
|
629
|
+
column: branchCol,
|
|
630
|
+
securityLabel,
|
|
631
|
+
}), (securityLabel) => new DropSecurityLabelOnColumn({
|
|
632
|
+
table: mainTable,
|
|
633
|
+
column: mainCol,
|
|
634
|
+
securityLabel,
|
|
635
|
+
})));
|
|
636
|
+
}
|
|
637
|
+
// Added columns with security labels (for created columns on existing tables)
|
|
638
|
+
for (const [name, col] of branchCols) {
|
|
639
|
+
if (!mainCols.has(name)) {
|
|
640
|
+
for (const label of col.security_labels ?? []) {
|
|
641
|
+
changes.push(new CreateSecurityLabelOnColumn({
|
|
642
|
+
table: branchTable,
|
|
643
|
+
column: col,
|
|
644
|
+
securityLabel: label,
|
|
645
|
+
}));
|
|
646
|
+
}
|
|
647
|
+
}
|
|
599
648
|
}
|
|
600
649
|
// PRIVILEGES (unified object and column privileges)
|
|
601
650
|
// Filter out owner privileges - owner always has ALL privileges implicitly
|
|
@@ -3,6 +3,7 @@ import z from "zod";
|
|
|
3
3
|
import { BasePgModel, type TableLikeObject } from "../base.model.ts";
|
|
4
4
|
import { type PrivilegeProps } from "../base.privilege-diff.ts";
|
|
5
5
|
import { type ExtractRetryOptions } from "../extract-with-retry.ts";
|
|
6
|
+
import { type SecurityLabelProps } from "../security-label.types.ts";
|
|
6
7
|
export declare const ReplicaIdentitySchema: z.ZodEnum<{
|
|
7
8
|
n: "n";
|
|
8
9
|
i: "i";
|
|
@@ -112,6 +113,10 @@ declare const tablePropsSchema: z.ZodObject<{
|
|
|
112
113
|
collation: z.ZodNullable<z.ZodString>;
|
|
113
114
|
default: z.ZodNullable<z.ZodString>;
|
|
114
115
|
comment: z.ZodNullable<z.ZodString>;
|
|
116
|
+
security_labels: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
117
|
+
provider: z.ZodString;
|
|
118
|
+
label: z.ZodString;
|
|
119
|
+
}, z.z.core.$strip>>>;
|
|
115
120
|
}, z.z.core.$strip>>;
|
|
116
121
|
constraints: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
117
122
|
name: z.ZodString;
|
|
@@ -174,8 +179,16 @@ declare const tablePropsSchema: z.ZodObject<{
|
|
|
174
179
|
grantable: z.ZodBoolean;
|
|
175
180
|
columns: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
176
181
|
}, z.z.core.$strip>>;
|
|
182
|
+
security_labels: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
183
|
+
provider: z.ZodString;
|
|
184
|
+
label: z.ZodString;
|
|
185
|
+
}, z.z.core.$strip>>>>;
|
|
177
186
|
}, z.z.core.$strip>;
|
|
178
187
|
type TablePrivilegeProps = PrivilegeProps;
|
|
188
|
+
/**
|
|
189
|
+
* Table input props. `security_labels` is optional on direct construction
|
|
190
|
+
* (defaults to `[]`); extraction always produces it via the Zod default.
|
|
191
|
+
*/
|
|
179
192
|
export type TableProps = z.infer<typeof tablePropsSchema>;
|
|
180
193
|
export declare class Table extends BasePgModel implements TableLikeObject {
|
|
181
194
|
readonly schema: TableProps["schema"];
|
|
@@ -201,6 +214,7 @@ export declare class Table extends BasePgModel implements TableLikeObject {
|
|
|
201
214
|
readonly columns: TableProps["columns"];
|
|
202
215
|
readonly constraints: TableConstraintProps[];
|
|
203
216
|
readonly privileges: TablePrivilegeProps[];
|
|
217
|
+
readonly security_labels: SecurityLabelProps[];
|
|
204
218
|
constructor(props: TableProps);
|
|
205
219
|
get stableId(): `table:${string}`;
|
|
206
220
|
get identityFields(): {
|
|
@@ -236,6 +250,10 @@ export declare class Table extends BasePgModel implements TableLikeObject {
|
|
|
236
250
|
collation: string | null;
|
|
237
251
|
default: string | null;
|
|
238
252
|
comment: string | null;
|
|
253
|
+
security_labels?: {
|
|
254
|
+
provider: string;
|
|
255
|
+
label: string;
|
|
256
|
+
}[] | undefined;
|
|
239
257
|
}[];
|
|
240
258
|
constraints: {
|
|
241
259
|
name: string;
|
|
@@ -274,6 +292,10 @@ export declare class Table extends BasePgModel implements TableLikeObject {
|
|
|
274
292
|
grantable: boolean;
|
|
275
293
|
columns?: string[] | null | undefined;
|
|
276
294
|
}[];
|
|
295
|
+
security_labels: {
|
|
296
|
+
provider: string;
|
|
297
|
+
label: string;
|
|
298
|
+
}[];
|
|
277
299
|
};
|
|
278
300
|
stableSnapshot(): {
|
|
279
301
|
identity: {
|
|
@@ -297,6 +319,10 @@ export declare class Table extends BasePgModel implements TableLikeObject {
|
|
|
297
319
|
collation: string | null;
|
|
298
320
|
default: string | null;
|
|
299
321
|
comment: string | null;
|
|
322
|
+
security_labels?: {
|
|
323
|
+
provider: string;
|
|
324
|
+
label: string;
|
|
325
|
+
}[] | undefined;
|
|
300
326
|
}[];
|
|
301
327
|
options: string[] | null;
|
|
302
328
|
constraints: {
|
|
@@ -336,6 +362,10 @@ export declare class Table extends BasePgModel implements TableLikeObject {
|
|
|
336
362
|
grantable: boolean;
|
|
337
363
|
columns: string[] | null | undefined;
|
|
338
364
|
}[];
|
|
365
|
+
security_labels: {
|
|
366
|
+
provider: string;
|
|
367
|
+
label: string;
|
|
368
|
+
}[];
|
|
339
369
|
persistence: "u" | "t" | "p";
|
|
340
370
|
row_security: boolean;
|
|
341
371
|
force_row_security: boolean;
|
|
@@ -4,6 +4,7 @@ import { BasePgModel, columnPropsSchema, normalizeColumns, } from "../base.model
|
|
|
4
4
|
import { normalizePrivileges } from "../base.privilege.js";
|
|
5
5
|
import { privilegePropsSchema, } from "../base.privilege-diff.js";
|
|
6
6
|
import { extractWithDefinitionRetry, } from "../extract-with-retry.js";
|
|
7
|
+
import { normalizeSecurityLabels, securityLabelPropsSchema, } from "../security-label.types.js";
|
|
7
8
|
const RelationPersistenceSchema = z.enum([
|
|
8
9
|
"p", // permanent
|
|
9
10
|
"u", // unlogged
|
|
@@ -98,6 +99,7 @@ const tablePropsSchema = z.object({
|
|
|
98
99
|
columns: z.array(columnPropsSchema),
|
|
99
100
|
constraints: z.array(tableConstraintPropsSchema).optional(),
|
|
100
101
|
privileges: z.array(privilegePropsSchema),
|
|
102
|
+
security_labels: z.array(securityLabelPropsSchema).default([]).optional(),
|
|
101
103
|
});
|
|
102
104
|
const tableRowSchema = tablePropsSchema.extend({
|
|
103
105
|
constraints: z.array(tableConstraintRowSchema).optional(),
|
|
@@ -126,6 +128,7 @@ export class Table extends BasePgModel {
|
|
|
126
128
|
columns;
|
|
127
129
|
constraints;
|
|
128
130
|
privileges;
|
|
131
|
+
security_labels;
|
|
129
132
|
constructor(props) {
|
|
130
133
|
super();
|
|
131
134
|
// Identity fields
|
|
@@ -153,6 +156,7 @@ export class Table extends BasePgModel {
|
|
|
153
156
|
this.columns = props.columns;
|
|
154
157
|
this.constraints = props.constraints ?? [];
|
|
155
158
|
this.privileges = props.privileges;
|
|
159
|
+
this.security_labels = props.security_labels ?? [];
|
|
156
160
|
}
|
|
157
161
|
get stableId() {
|
|
158
162
|
return `table:${this.schema}.${this.name}`;
|
|
@@ -181,6 +185,7 @@ export class Table extends BasePgModel {
|
|
|
181
185
|
columns: this.columns,
|
|
182
186
|
constraints: this.constraints,
|
|
183
187
|
privileges: this.privileges,
|
|
188
|
+
security_labels: this.security_labels,
|
|
184
189
|
};
|
|
185
190
|
}
|
|
186
191
|
stableSnapshot() {
|
|
@@ -197,6 +202,7 @@ export class Table extends BasePgModel {
|
|
|
197
202
|
options: this.options ? [...this.options].sort() : this.options,
|
|
198
203
|
constraints: normalizeConstraints(),
|
|
199
204
|
privileges: normalizePrivileges(this.privileges),
|
|
205
|
+
security_labels: normalizeSecurityLabels(this.security_labels),
|
|
200
206
|
},
|
|
201
207
|
};
|
|
202
208
|
}
|
|
@@ -405,7 +411,20 @@ select
|
|
|
405
411
|
and a.attcollation <> t2.typcollation
|
|
406
412
|
),
|
|
407
413
|
'default', pg_get_expr(ad.adbin, ad.adrelid),
|
|
408
|
-
'comment', col_description(a.attrelid, a.attnum)
|
|
414
|
+
'comment', col_description(a.attrelid, a.attnum),
|
|
415
|
+
'security_labels', coalesce(
|
|
416
|
+
(
|
|
417
|
+
select json_agg(
|
|
418
|
+
json_build_object('provider', sl.provider, 'label', sl.label)
|
|
419
|
+
order by sl.provider
|
|
420
|
+
)
|
|
421
|
+
from pg_catalog.pg_seclabel sl
|
|
422
|
+
where sl.objoid = t.oid
|
|
423
|
+
and sl.classoid = 'pg_class'::regclass
|
|
424
|
+
and sl.objsubid = a.attnum
|
|
425
|
+
),
|
|
426
|
+
'[]'::json
|
|
427
|
+
)
|
|
409
428
|
)
|
|
410
429
|
end
|
|
411
430
|
order by a.attnum
|
|
@@ -445,7 +464,20 @@ select
|
|
|
445
464
|
join lateral aclexplode(src.acl) as x(grantor, grantee, privilege_type, is_grantable) on true
|
|
446
465
|
group by x.grantee, x.privilege_type
|
|
447
466
|
) as grp
|
|
448
|
-
), '[]') as privileges
|
|
467
|
+
), '[]') as privileges,
|
|
468
|
+
coalesce(
|
|
469
|
+
(
|
|
470
|
+
select json_agg(
|
|
471
|
+
json_build_object('provider', sl.provider, 'label', sl.label)
|
|
472
|
+
order by sl.provider
|
|
473
|
+
)
|
|
474
|
+
from pg_catalog.pg_seclabel sl
|
|
475
|
+
where sl.objoid = t.oid
|
|
476
|
+
and sl.classoid = 'pg_class'::regclass
|
|
477
|
+
and sl.objsubid = 0
|
|
478
|
+
),
|
|
479
|
+
'[]'::json
|
|
480
|
+
) as security_labels
|
|
449
481
|
from
|
|
450
482
|
tables t
|
|
451
483
|
left join pg_attribute a on a.attrelid = t.oid and a.attnum > 0 and not a.attisdropped
|
|
@@ -2,7 +2,7 @@ import { BaseChange } from "../../../base.change.ts";
|
|
|
2
2
|
import type { CompositeType } from "../composite-type.model.ts";
|
|
3
3
|
declare abstract class BaseCompositeTypeChange extends BaseChange {
|
|
4
4
|
abstract readonly compositeType: CompositeType;
|
|
5
|
-
abstract readonly scope: "object" | "comment" | "privilege";
|
|
5
|
+
abstract readonly scope: "object" | "comment" | "privilege" | "security_label";
|
|
6
6
|
readonly objectType: "composite_type";
|
|
7
7
|
}
|
|
8
8
|
export declare abstract class CreateCompositeTypeChange extends BaseCompositeTypeChange {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { SecurityLabelProps } from "../../../security-label.types.ts";
|
|
2
|
+
import type { CompositeType } from "../composite-type.model.ts";
|
|
3
|
+
import { CreateCompositeTypeChange, DropCompositeTypeChange } from "./composite-type.base.ts";
|
|
4
|
+
export type SecurityLabelCompositeType = CreateSecurityLabelOnCompositeType | DropSecurityLabelOnCompositeType;
|
|
5
|
+
export declare class CreateSecurityLabelOnCompositeType extends CreateCompositeTypeChange {
|
|
6
|
+
readonly compositeType: CompositeType;
|
|
7
|
+
readonly securityLabel: SecurityLabelProps;
|
|
8
|
+
readonly scope: "security_label";
|
|
9
|
+
constructor(props: {
|
|
10
|
+
compositeType: CompositeType;
|
|
11
|
+
securityLabel: SecurityLabelProps;
|
|
12
|
+
});
|
|
13
|
+
get creates(): `securityLabel:${string}::provider:${string}`[];
|
|
14
|
+
get requires(): `type:${string}`[];
|
|
15
|
+
serialize(): string;
|
|
16
|
+
}
|
|
17
|
+
export declare class DropSecurityLabelOnCompositeType extends DropCompositeTypeChange {
|
|
18
|
+
readonly compositeType: CompositeType;
|
|
19
|
+
readonly securityLabel: SecurityLabelProps;
|
|
20
|
+
readonly scope: "security_label";
|
|
21
|
+
constructor(props: {
|
|
22
|
+
compositeType: CompositeType;
|
|
23
|
+
securityLabel: SecurityLabelProps;
|
|
24
|
+
});
|
|
25
|
+
get drops(): `securityLabel:${string}::provider:${string}`[];
|
|
26
|
+
get requires(): (`securityLabel:${string}::provider:${string}` | `type:${string}`)[];
|
|
27
|
+
serialize(): string;
|
|
28
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { quoteLiteral } from "../../../base.change.js";
|
|
2
|
+
import { stableId } from "../../../utils.js";
|
|
3
|
+
import { CreateCompositeTypeChange, DropCompositeTypeChange, } from "./composite-type.base.js";
|
|
4
|
+
export class CreateSecurityLabelOnCompositeType extends CreateCompositeTypeChange {
|
|
5
|
+
compositeType;
|
|
6
|
+
securityLabel;
|
|
7
|
+
scope = "security_label";
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super();
|
|
10
|
+
this.compositeType = props.compositeType;
|
|
11
|
+
this.securityLabel = props.securityLabel;
|
|
12
|
+
}
|
|
13
|
+
get creates() {
|
|
14
|
+
return [
|
|
15
|
+
stableId.securityLabel(this.compositeType.stableId, this.securityLabel.provider),
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
get requires() {
|
|
19
|
+
return [this.compositeType.stableId];
|
|
20
|
+
}
|
|
21
|
+
serialize() {
|
|
22
|
+
return [
|
|
23
|
+
"SECURITY LABEL FOR",
|
|
24
|
+
this.securityLabel.provider,
|
|
25
|
+
"ON TYPE",
|
|
26
|
+
`${this.compositeType.schema}.${this.compositeType.name}`,
|
|
27
|
+
"IS",
|
|
28
|
+
quoteLiteral(this.securityLabel.label),
|
|
29
|
+
].join(" ");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class DropSecurityLabelOnCompositeType extends DropCompositeTypeChange {
|
|
33
|
+
compositeType;
|
|
34
|
+
securityLabel;
|
|
35
|
+
scope = "security_label";
|
|
36
|
+
constructor(props) {
|
|
37
|
+
super();
|
|
38
|
+
this.compositeType = props.compositeType;
|
|
39
|
+
this.securityLabel = props.securityLabel;
|
|
40
|
+
}
|
|
41
|
+
get drops() {
|
|
42
|
+
return [
|
|
43
|
+
stableId.securityLabel(this.compositeType.stableId, this.securityLabel.provider),
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
get requires() {
|
|
47
|
+
return [
|
|
48
|
+
stableId.securityLabel(this.compositeType.stableId, this.securityLabel.provider),
|
|
49
|
+
this.compositeType.stableId,
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
serialize() {
|
|
53
|
+
return [
|
|
54
|
+
"SECURITY LABEL FOR",
|
|
55
|
+
this.securityLabel.provider,
|
|
56
|
+
"ON TYPE",
|
|
57
|
+
`${this.compositeType.schema}.${this.compositeType.name}`,
|
|
58
|
+
"IS NULL",
|
|
59
|
+
].join(" ");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -3,5 +3,6 @@ import type { CommentCompositeType } from "./composite-type.comment.ts";
|
|
|
3
3
|
import type { CreateCompositeType } from "./composite-type.create.ts";
|
|
4
4
|
import type { DropCompositeType } from "./composite-type.drop.ts";
|
|
5
5
|
import type { CompositeTypePrivilege } from "./composite-type.privilege.ts";
|
|
6
|
+
import type { SecurityLabelCompositeType } from "./composite-type.security-label.ts";
|
|
6
7
|
/** Union of all composite-type-related change variants (`objectType: "composite_type"`). @category Change Types */
|
|
7
|
-
export type CompositeTypeChange = AlterCompositeType | CommentCompositeType | CreateCompositeType | DropCompositeType | CompositeTypePrivilege;
|
|
8
|
+
export type CompositeTypeChange = AlterCompositeType | CommentCompositeType | CreateCompositeType | DropCompositeType | CompositeTypePrivilege | SecurityLabelCompositeType;
|
|
@@ -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 { AlterCompositeTypeAddAttribute, AlterCompositeTypeAlterAttributeType, AlterCompositeTypeChangeOwner, AlterCompositeTypeDropAttribute, } from "./changes/composite-type.alter.js";
|
|
5
6
|
import { CreateCommentOnCompositeType, CreateCommentOnCompositeTypeAttribute, DropCommentOnCompositeType, DropCommentOnCompositeTypeAttribute, } from "./changes/composite-type.comment.js";
|
|
6
7
|
import { CreateCompositeType } from "./changes/composite-type.create.js";
|
|
7
8
|
import { DropCompositeType } from "./changes/composite-type.drop.js";
|
|
8
9
|
import { GrantCompositeTypePrivileges, RevokeCompositeTypePrivileges, RevokeGrantOptionCompositeTypePrivileges, } from "./changes/composite-type.privilege.js";
|
|
10
|
+
import { CreateSecurityLabelOnCompositeType, DropSecurityLabelOnCompositeType, } from "./changes/composite-type.security-label.js";
|
|
9
11
|
/**
|
|
10
12
|
* Diff two sets of composite types from main and branch catalogs.
|
|
11
13
|
*
|
|
@@ -32,6 +34,12 @@ export function diffCompositeTypes(ctx, main, branch) {
|
|
|
32
34
|
if (ct.comment !== null) {
|
|
33
35
|
changes.push(new CreateCommentOnCompositeType({ compositeType: ct }));
|
|
34
36
|
}
|
|
37
|
+
for (const label of ct.security_labels) {
|
|
38
|
+
changes.push(new CreateSecurityLabelOnCompositeType({
|
|
39
|
+
compositeType: ct,
|
|
40
|
+
securityLabel: label,
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
35
43
|
// Attribute comments on creation
|
|
36
44
|
for (const attr of ct.columns) {
|
|
37
45
|
if (attr.comment !== null) {
|
|
@@ -111,6 +119,14 @@ export function diffCompositeTypes(ctx, main, branch) {
|
|
|
111
119
|
}));
|
|
112
120
|
}
|
|
113
121
|
}
|
|
122
|
+
// SECURITY LABELS
|
|
123
|
+
changes.push(...diffSecurityLabels(mainCompositeType.security_labels, branchCompositeType.security_labels, (securityLabel) => new CreateSecurityLabelOnCompositeType({
|
|
124
|
+
compositeType: branchCompositeType,
|
|
125
|
+
securityLabel,
|
|
126
|
+
}), (securityLabel) => new DropSecurityLabelOnCompositeType({
|
|
127
|
+
compositeType: mainCompositeType,
|
|
128
|
+
securityLabel,
|
|
129
|
+
})));
|
|
114
130
|
// ATTRIBUTE diffs
|
|
115
131
|
const mainAttrs = new Map(mainCompositeType.columns.map((c) => [c.name, c]));
|
|
116
132
|
const branchAttrs = new Map(branchCompositeType.columns.map((c) => [c.name, c]));
|
|
@@ -2,6 +2,7 @@ import type { Pool } from "pg";
|
|
|
2
2
|
import z from "zod";
|
|
3
3
|
import { BasePgModel, type TableLikeObject } 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 compositeTypePropsSchema: z.ZodObject<{
|
|
6
7
|
schema: z.ZodString;
|
|
7
8
|
name: z.ZodString;
|
|
@@ -40,6 +41,10 @@ declare const compositeTypePropsSchema: z.ZodObject<{
|
|
|
40
41
|
collation: z.ZodNullable<z.ZodString>;
|
|
41
42
|
default: z.ZodNullable<z.ZodString>;
|
|
42
43
|
comment: z.ZodNullable<z.ZodString>;
|
|
44
|
+
security_labels: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
45
|
+
provider: z.ZodString;
|
|
46
|
+
label: z.ZodString;
|
|
47
|
+
}, z.z.core.$strip>>>;
|
|
43
48
|
}, z.z.core.$strip>>;
|
|
44
49
|
privileges: z.ZodArray<z.ZodObject<{
|
|
45
50
|
grantee: z.ZodString;
|
|
@@ -47,6 +52,10 @@ declare const compositeTypePropsSchema: z.ZodObject<{
|
|
|
47
52
|
grantable: z.ZodBoolean;
|
|
48
53
|
columns: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
49
54
|
}, z.z.core.$strip>>;
|
|
55
|
+
security_labels: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
56
|
+
provider: z.ZodString;
|
|
57
|
+
label: z.ZodString;
|
|
58
|
+
}, z.z.core.$strip>>>>;
|
|
50
59
|
}, z.z.core.$strip>;
|
|
51
60
|
type CompositeTypePrivilegeProps = PrivilegeProps;
|
|
52
61
|
export type CompositeTypeProps = z.infer<typeof compositeTypePropsSchema>;
|
|
@@ -68,6 +77,7 @@ export declare class CompositeType extends BasePgModel implements TableLikeObjec
|
|
|
68
77
|
readonly comment: CompositeTypeProps["comment"];
|
|
69
78
|
readonly columns: CompositeTypeProps["columns"];
|
|
70
79
|
readonly privileges: CompositeTypePrivilegeProps[];
|
|
80
|
+
readonly security_labels: SecurityLabelProps[];
|
|
71
81
|
constructor(props: CompositeTypeProps);
|
|
72
82
|
get stableId(): `type:${string}`;
|
|
73
83
|
get identityFields(): {
|
|
@@ -105,6 +115,10 @@ export declare class CompositeType extends BasePgModel implements TableLikeObjec
|
|
|
105
115
|
collation: string | null;
|
|
106
116
|
default: string | null;
|
|
107
117
|
comment: string | null;
|
|
118
|
+
security_labels?: {
|
|
119
|
+
provider: string;
|
|
120
|
+
label: string;
|
|
121
|
+
}[] | undefined;
|
|
108
122
|
}[];
|
|
109
123
|
privileges: {
|
|
110
124
|
grantee: string;
|
|
@@ -112,6 +126,10 @@ export declare class CompositeType extends BasePgModel implements TableLikeObjec
|
|
|
112
126
|
grantable: boolean;
|
|
113
127
|
columns?: string[] | null | undefined;
|
|
114
128
|
}[];
|
|
129
|
+
security_labels: {
|
|
130
|
+
provider: string;
|
|
131
|
+
label: string;
|
|
132
|
+
}[];
|
|
115
133
|
};
|
|
116
134
|
stableSnapshot(): {
|
|
117
135
|
identity: {
|
|
@@ -122,6 +140,10 @@ export declare class CompositeType extends BasePgModel implements TableLikeObjec
|
|
|
122
140
|
columns: {
|
|
123
141
|
[x: string]: unknown;
|
|
124
142
|
}[];
|
|
143
|
+
security_labels: {
|
|
144
|
+
provider: string;
|
|
145
|
+
label: string;
|
|
146
|
+
}[];
|
|
125
147
|
row_security: boolean;
|
|
126
148
|
force_row_security: boolean;
|
|
127
149
|
has_indexes: boolean;
|
|
@@ -2,6 +2,7 @@ import { sql } from "@ts-safeql/sql-tag";
|
|
|
2
2
|
import z from "zod";
|
|
3
3
|
import { BasePgModel, columnPropsSchema, } from "../../base.model.js";
|
|
4
4
|
import { privilegePropsSchema, } from "../../base.privilege-diff.js";
|
|
5
|
+
import { normalizeSecurityLabels, securityLabelPropsSchema, } from "../../security-label.types.js";
|
|
5
6
|
import { ReplicaIdentitySchema } from "../../table/table.model.js";
|
|
6
7
|
const compositeTypePropsSchema = z.object({
|
|
7
8
|
schema: z.string(),
|
|
@@ -21,6 +22,7 @@ const compositeTypePropsSchema = z.object({
|
|
|
21
22
|
comment: z.string().nullable(),
|
|
22
23
|
columns: z.array(columnPropsSchema),
|
|
23
24
|
privileges: z.array(privilegePropsSchema),
|
|
25
|
+
security_labels: z.array(securityLabelPropsSchema).default([]).optional(),
|
|
24
26
|
});
|
|
25
27
|
export class CompositeType extends BasePgModel {
|
|
26
28
|
schema;
|
|
@@ -40,6 +42,7 @@ export class CompositeType extends BasePgModel {
|
|
|
40
42
|
comment;
|
|
41
43
|
columns;
|
|
42
44
|
privileges;
|
|
45
|
+
security_labels;
|
|
43
46
|
constructor(props) {
|
|
44
47
|
super();
|
|
45
48
|
// Identity fields
|
|
@@ -61,6 +64,7 @@ export class CompositeType extends BasePgModel {
|
|
|
61
64
|
this.comment = props.comment;
|
|
62
65
|
this.columns = props.columns;
|
|
63
66
|
this.privileges = props.privileges;
|
|
67
|
+
this.security_labels = props.security_labels ?? [];
|
|
64
68
|
}
|
|
65
69
|
get stableId() {
|
|
66
70
|
return `type:${this.schema}.${this.name}`;
|
|
@@ -88,6 +92,7 @@ export class CompositeType extends BasePgModel {
|
|
|
88
92
|
comment: this.comment,
|
|
89
93
|
columns: this.columns,
|
|
90
94
|
privileges: this.privileges,
|
|
95
|
+
security_labels: this.security_labels,
|
|
91
96
|
};
|
|
92
97
|
}
|
|
93
98
|
stableSnapshot() {
|
|
@@ -106,6 +111,7 @@ export class CompositeType extends BasePgModel {
|
|
|
106
111
|
data: {
|
|
107
112
|
...this.dataFields,
|
|
108
113
|
columns: normalizeColumns(),
|
|
114
|
+
security_labels: normalizeSecurityLabels(this.security_labels),
|
|
109
115
|
},
|
|
110
116
|
};
|
|
111
117
|
}
|
|
@@ -137,7 +143,8 @@ export async function extractCompositeTypes(pool) {
|
|
|
137
143
|
obj_description(c.reltype, 'pg_type') AS comment,
|
|
138
144
|
c.relacl AS relacl, -- used by privileges LATERAL
|
|
139
145
|
c.relowner AS relowner,
|
|
140
|
-
c.oid AS oid
|
|
146
|
+
c.oid AS oid,
|
|
147
|
+
c.reltype AS reltype
|
|
141
148
|
FROM pg_catalog.pg_class c
|
|
142
149
|
LEFT JOIN extension_oids e ON c.reltype = e.objid
|
|
143
150
|
WHERE NOT c.relnamespace::regnamespace::text LIKE ANY (ARRAY['pg\\_%', 'information\\_schema'])
|
|
@@ -161,7 +168,20 @@ export async function extractCompositeTypes(pool) {
|
|
|
161
168
|
ct.owner,
|
|
162
169
|
ct.comment,
|
|
163
170
|
COALESCE(priv.privileges, '[]') AS privileges,
|
|
164
|
-
COALESCE(cols.columns, '[]') AS columns
|
|
171
|
+
COALESCE(cols.columns, '[]') AS columns,
|
|
172
|
+
COALESCE(
|
|
173
|
+
(
|
|
174
|
+
SELECT json_agg(
|
|
175
|
+
json_build_object('provider', sl.provider, 'label', sl.label)
|
|
176
|
+
ORDER BY sl.provider
|
|
177
|
+
)
|
|
178
|
+
FROM pg_catalog.pg_seclabel sl
|
|
179
|
+
WHERE sl.objoid = ct.reltype
|
|
180
|
+
AND sl.classoid = 'pg_type'::regclass
|
|
181
|
+
AND sl.objsubid = 0
|
|
182
|
+
),
|
|
183
|
+
'[]'::json
|
|
184
|
+
) AS security_labels
|
|
165
185
|
FROM composite_types ct
|
|
166
186
|
|
|
167
187
|
-- privileges as a per-row LATERAL subquery
|
|
@@ -2,7 +2,7 @@ import { BaseChange } from "../../../base.change.ts";
|
|
|
2
2
|
import type { Enum } from "../enum.model.ts";
|
|
3
3
|
declare abstract class BaseEnumChange extends BaseChange {
|
|
4
4
|
abstract readonly enum: Enum;
|
|
5
|
-
abstract readonly scope: "object" | "comment" | "privilege";
|
|
5
|
+
abstract readonly scope: "object" | "comment" | "privilege" | "security_label";
|
|
6
6
|
readonly objectType: "enum";
|
|
7
7
|
}
|
|
8
8
|
export declare abstract class CreateEnumChange extends BaseEnumChange {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { SecurityLabelProps } from "../../../security-label.types.ts";
|
|
2
|
+
import type { Enum } from "../enum.model.ts";
|
|
3
|
+
import { CreateEnumChange, DropEnumChange } from "./enum.base.ts";
|
|
4
|
+
export type SecurityLabelEnum = CreateSecurityLabelOnEnum | DropSecurityLabelOnEnum;
|
|
5
|
+
export declare class CreateSecurityLabelOnEnum extends CreateEnumChange {
|
|
6
|
+
readonly enum: Enum;
|
|
7
|
+
readonly securityLabel: SecurityLabelProps;
|
|
8
|
+
readonly scope: "security_label";
|
|
9
|
+
constructor(props: {
|
|
10
|
+
enum: Enum;
|
|
11
|
+
securityLabel: SecurityLabelProps;
|
|
12
|
+
});
|
|
13
|
+
get creates(): `securityLabel:${string}::provider:${string}`[];
|
|
14
|
+
get requires(): `type:${string}`[];
|
|
15
|
+
serialize(): string;
|
|
16
|
+
}
|
|
17
|
+
export declare class DropSecurityLabelOnEnum extends DropEnumChange {
|
|
18
|
+
readonly enum: Enum;
|
|
19
|
+
readonly securityLabel: SecurityLabelProps;
|
|
20
|
+
readonly scope: "security_label";
|
|
21
|
+
constructor(props: {
|
|
22
|
+
enum: Enum;
|
|
23
|
+
securityLabel: SecurityLabelProps;
|
|
24
|
+
});
|
|
25
|
+
get drops(): `securityLabel:${string}::provider:${string}`[];
|
|
26
|
+
get requires(): (`securityLabel:${string}::provider:${string}` | `type:${string}`)[];
|
|
27
|
+
serialize(): string;
|
|
28
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { quoteLiteral } from "../../../base.change.js";
|
|
2
|
+
import { stableId } from "../../../utils.js";
|
|
3
|
+
import { CreateEnumChange, DropEnumChange } from "./enum.base.js";
|
|
4
|
+
export class CreateSecurityLabelOnEnum extends CreateEnumChange {
|
|
5
|
+
enum;
|
|
6
|
+
securityLabel;
|
|
7
|
+
scope = "security_label";
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super();
|
|
10
|
+
this.enum = props.enum;
|
|
11
|
+
this.securityLabel = props.securityLabel;
|
|
12
|
+
}
|
|
13
|
+
get creates() {
|
|
14
|
+
return [
|
|
15
|
+
stableId.securityLabel(this.enum.stableId, this.securityLabel.provider),
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
get requires() {
|
|
19
|
+
return [this.enum.stableId];
|
|
20
|
+
}
|
|
21
|
+
serialize() {
|
|
22
|
+
return [
|
|
23
|
+
"SECURITY LABEL FOR",
|
|
24
|
+
this.securityLabel.provider,
|
|
25
|
+
"ON TYPE",
|
|
26
|
+
`${this.enum.schema}.${this.enum.name}`,
|
|
27
|
+
"IS",
|
|
28
|
+
quoteLiteral(this.securityLabel.label),
|
|
29
|
+
].join(" ");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class DropSecurityLabelOnEnum extends DropEnumChange {
|
|
33
|
+
enum;
|
|
34
|
+
securityLabel;
|
|
35
|
+
scope = "security_label";
|
|
36
|
+
constructor(props) {
|
|
37
|
+
super();
|
|
38
|
+
this.enum = props.enum;
|
|
39
|
+
this.securityLabel = props.securityLabel;
|
|
40
|
+
}
|
|
41
|
+
get drops() {
|
|
42
|
+
return [
|
|
43
|
+
stableId.securityLabel(this.enum.stableId, this.securityLabel.provider),
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
get requires() {
|
|
47
|
+
return [
|
|
48
|
+
stableId.securityLabel(this.enum.stableId, this.securityLabel.provider),
|
|
49
|
+
this.enum.stableId,
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
serialize() {
|
|
53
|
+
return [
|
|
54
|
+
"SECURITY LABEL FOR",
|
|
55
|
+
this.securityLabel.provider,
|
|
56
|
+
"ON TYPE",
|
|
57
|
+
`${this.enum.schema}.${this.enum.name}`,
|
|
58
|
+
"IS NULL",
|
|
59
|
+
].join(" ");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -3,5 +3,6 @@ import type { CommentEnum } from "./enum.comment.ts";
|
|
|
3
3
|
import type { CreateEnum } from "./enum.create.ts";
|
|
4
4
|
import type { DropEnum } from "./enum.drop.ts";
|
|
5
5
|
import type { EnumPrivilege } from "./enum.privilege.ts";
|
|
6
|
+
import type { SecurityLabelEnum } from "./enum.security-label.ts";
|
|
6
7
|
/** Union of all enum-related change variants (`objectType: "enum"`). @category Change Types */
|
|
7
|
-
export type EnumChange = AlterEnum | CommentEnum | CreateEnum | DropEnum | EnumPrivilege;
|
|
8
|
+
export type EnumChange = AlterEnum | CommentEnum | CreateEnum | DropEnum | EnumPrivilege | SecurityLabelEnum;
|