@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.
Files changed (220) hide show
  1. package/dist/core/catalog.model.js +1 -0
  2. package/dist/core/integrations/filter/flatten.js +13 -0
  3. package/dist/core/objects/aggregate/aggregate.diff.js +16 -0
  4. package/dist/core/objects/aggregate/aggregate.model.d.ts +10 -0
  5. package/dist/core/objects/aggregate/aggregate.model.js +19 -1
  6. package/dist/core/objects/aggregate/changes/aggregate.base.d.ts +1 -1
  7. package/dist/core/objects/aggregate/changes/aggregate.security-label.d.ts +28 -0
  8. package/dist/core/objects/aggregate/changes/aggregate.security-label.js +64 -0
  9. package/dist/core/objects/aggregate/changes/aggregate.types.d.ts +2 -1
  10. package/dist/core/objects/base.model.d.ts +8 -0
  11. package/dist/core/objects/base.model.js +2 -0
  12. package/dist/core/objects/domain/changes/domain.base.d.ts +1 -1
  13. package/dist/core/objects/domain/changes/domain.security-label.d.ts +28 -0
  14. package/dist/core/objects/domain/changes/domain.security-label.js +61 -0
  15. package/dist/core/objects/domain/changes/domain.types.d.ts +2 -1
  16. package/dist/core/objects/domain/domain.diff.js +16 -0
  17. package/dist/core/objects/domain/domain.model.d.ts +10 -0
  18. package/dist/core/objects/domain/domain.model.js +19 -1
  19. package/dist/core/objects/event-trigger/changes/event-trigger.base.d.ts +1 -1
  20. package/dist/core/objects/event-trigger/changes/event-trigger.security-label.d.ts +28 -0
  21. package/dist/core/objects/event-trigger/changes/event-trigger.security-label.js +61 -0
  22. package/dist/core/objects/event-trigger/changes/event-trigger.types.d.ts +2 -1
  23. package/dist/core/objects/event-trigger/event-trigger.diff.js +16 -0
  24. package/dist/core/objects/event-trigger/event-trigger.model.d.ts +10 -0
  25. package/dist/core/objects/event-trigger/event-trigger.model.js +19 -1
  26. package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.base.d.ts +1 -1
  27. package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.security-label.d.ts +28 -0
  28. package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.security-label.js +61 -0
  29. package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.types.d.ts +2 -1
  30. package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.js +16 -0
  31. package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.d.ts +22 -0
  32. package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.js +20 -1
  33. package/dist/core/objects/materialized-view/changes/materialized-view.base.d.ts +1 -1
  34. package/dist/core/objects/materialized-view/changes/materialized-view.security-label.d.ts +28 -0
  35. package/dist/core/objects/materialized-view/changes/materialized-view.security-label.js +61 -0
  36. package/dist/core/objects/materialized-view/changes/materialized-view.types.d.ts +2 -1
  37. package/dist/core/objects/materialized-view/materialized-view.diff.js +18 -0
  38. package/dist/core/objects/materialized-view/materialized-view.model.d.ts +22 -0
  39. package/dist/core/objects/materialized-view/materialized-view.model.js +20 -1
  40. package/dist/core/objects/procedure/changes/procedure.base.d.ts +1 -1
  41. package/dist/core/objects/procedure/changes/procedure.security-label.d.ts +28 -0
  42. package/dist/core/objects/procedure/changes/procedure.security-label.js +69 -0
  43. package/dist/core/objects/procedure/changes/procedure.types.d.ts +2 -1
  44. package/dist/core/objects/procedure/procedure.diff.js +16 -0
  45. package/dist/core/objects/procedure/procedure.model.d.ts +10 -0
  46. package/dist/core/objects/procedure/procedure.model.js +19 -1
  47. package/dist/core/objects/publication/changes/publication.base.d.ts +1 -1
  48. package/dist/core/objects/publication/changes/publication.security-label.d.ts +28 -0
  49. package/dist/core/objects/publication/changes/publication.security-label.js +61 -0
  50. package/dist/core/objects/publication/changes/publication.types.d.ts +2 -1
  51. package/dist/core/objects/publication/publication.diff.js +16 -0
  52. package/dist/core/objects/publication/publication.model.d.ts +14 -0
  53. package/dist/core/objects/publication/publication.model.js +20 -1
  54. package/dist/core/objects/role/changes/role.base.d.ts +1 -1
  55. package/dist/core/objects/role/changes/role.security-label.d.ts +28 -0
  56. package/dist/core/objects/role/changes/role.security-label.js +61 -0
  57. package/dist/core/objects/role/changes/role.types.d.ts +2 -1
  58. package/dist/core/objects/role/role.diff.js +16 -0
  59. package/dist/core/objects/role/role.model.d.ts +10 -0
  60. package/dist/core/objects/role/role.model.js +29 -0
  61. package/dist/core/objects/schema/changes/schema.base.d.ts +1 -1
  62. package/dist/core/objects/schema/changes/schema.security-label.d.ts +28 -0
  63. package/dist/core/objects/schema/changes/schema.security-label.js +61 -0
  64. package/dist/core/objects/schema/changes/schema.types.d.ts +2 -1
  65. package/dist/core/objects/schema/schema.diff.js +24 -1
  66. package/dist/core/objects/schema/schema.model.d.ts +10 -0
  67. package/dist/core/objects/schema/schema.model.js +18 -1
  68. package/dist/core/objects/security-label.types.d.ts +20 -0
  69. package/dist/core/objects/security-label.types.js +46 -0
  70. package/dist/core/objects/sequence/changes/sequence.base.d.ts +1 -1
  71. package/dist/core/objects/sequence/changes/sequence.security-label.d.ts +28 -0
  72. package/dist/core/objects/sequence/changes/sequence.security-label.js +61 -0
  73. package/dist/core/objects/sequence/changes/sequence.types.d.ts +2 -1
  74. package/dist/core/objects/sequence/sequence.diff.js +16 -0
  75. package/dist/core/objects/sequence/sequence.model.d.ts +10 -0
  76. package/dist/core/objects/sequence/sequence.model.js +19 -1
  77. package/dist/core/objects/subscription/changes/subscription.base.d.ts +1 -1
  78. package/dist/core/objects/subscription/changes/subscription.security-label.d.ts +28 -0
  79. package/dist/core/objects/subscription/changes/subscription.security-label.js +61 -0
  80. package/dist/core/objects/subscription/changes/subscription.types.d.ts +2 -1
  81. package/dist/core/objects/subscription/subscription.diff.js +16 -0
  82. package/dist/core/objects/subscription/subscription.model.d.ts +10 -0
  83. package/dist/core/objects/subscription/subscription.model.js +19 -1
  84. package/dist/core/objects/table/changes/table.base.d.ts +1 -1
  85. package/dist/core/objects/table/changes/table.security-label.d.ts +63 -0
  86. package/dist/core/objects/table/changes/table.security-label.js +134 -0
  87. package/dist/core/objects/table/changes/table.types.d.ts +2 -1
  88. package/dist/core/objects/table/table.diff.js +49 -0
  89. package/dist/core/objects/table/table.model.d.ts +30 -0
  90. package/dist/core/objects/table/table.model.js +34 -2
  91. package/dist/core/objects/type/composite-type/changes/composite-type.base.d.ts +1 -1
  92. package/dist/core/objects/type/composite-type/changes/composite-type.security-label.d.ts +28 -0
  93. package/dist/core/objects/type/composite-type/changes/composite-type.security-label.js +61 -0
  94. package/dist/core/objects/type/composite-type/changes/composite-type.types.d.ts +2 -1
  95. package/dist/core/objects/type/composite-type/composite-type.diff.js +16 -0
  96. package/dist/core/objects/type/composite-type/composite-type.model.d.ts +22 -0
  97. package/dist/core/objects/type/composite-type/composite-type.model.js +22 -2
  98. package/dist/core/objects/type/enum/changes/enum.base.d.ts +1 -1
  99. package/dist/core/objects/type/enum/changes/enum.security-label.d.ts +28 -0
  100. package/dist/core/objects/type/enum/changes/enum.security-label.js +61 -0
  101. package/dist/core/objects/type/enum/changes/enum.types.d.ts +2 -1
  102. package/dist/core/objects/type/enum/enum.diff.js +16 -0
  103. package/dist/core/objects/type/enum/enum.model.d.ts +10 -0
  104. package/dist/core/objects/type/enum/enum.model.js +20 -1
  105. package/dist/core/objects/type/range/changes/range.base.d.ts +1 -1
  106. package/dist/core/objects/type/range/changes/range.security-label.d.ts +28 -0
  107. package/dist/core/objects/type/range/changes/range.security-label.js +61 -0
  108. package/dist/core/objects/type/range/changes/range.types.d.ts +2 -1
  109. package/dist/core/objects/type/range/range.diff.js +16 -0
  110. package/dist/core/objects/type/range/range.model.d.ts +10 -0
  111. package/dist/core/objects/type/range/range.model.js +19 -1
  112. package/dist/core/objects/utils.d.ts +1 -0
  113. package/dist/core/objects/utils.js +3 -0
  114. package/dist/core/objects/view/changes/view.base.d.ts +1 -1
  115. package/dist/core/objects/view/changes/view.security-label.d.ts +28 -0
  116. package/dist/core/objects/view/changes/view.security-label.js +61 -0
  117. package/dist/core/objects/view/changes/view.types.d.ts +2 -1
  118. package/dist/core/objects/view/view.diff.js +13 -0
  119. package/dist/core/objects/view/view.model.d.ts +26 -0
  120. package/dist/core/objects/view/view.model.js +20 -1
  121. package/dist/core/plan/sql-format/fixtures.js +1 -0
  122. package/package.json +1 -1
  123. package/src/core/catalog.model.ts +1 -0
  124. package/src/core/integrations/filter/dsl.test.ts +27 -0
  125. package/src/core/integrations/filter/flatten.ts +16 -0
  126. package/src/core/objects/aggregate/aggregate.diff.ts +33 -0
  127. package/src/core/objects/aggregate/aggregate.model.ts +22 -1
  128. package/src/core/objects/aggregate/changes/aggregate.base.ts +5 -1
  129. package/src/core/objects/aggregate/changes/aggregate.security-label.ts +99 -0
  130. package/src/core/objects/aggregate/changes/aggregate.types.ts +3 -1
  131. package/src/core/objects/base.model.ts +2 -0
  132. package/src/core/objects/domain/changes/domain.base.ts +5 -1
  133. package/src/core/objects/domain/changes/domain.security-label.test.ts +56 -0
  134. package/src/core/objects/domain/changes/domain.security-label.ts +77 -0
  135. package/src/core/objects/domain/changes/domain.types.ts +3 -1
  136. package/src/core/objects/domain/domain.diff.ts +33 -0
  137. package/src/core/objects/domain/domain.model.ts +22 -1
  138. package/src/core/objects/event-trigger/changes/event-trigger.base.ts +1 -1
  139. package/src/core/objects/event-trigger/changes/event-trigger.security-label.ts +95 -0
  140. package/src/core/objects/event-trigger/changes/event-trigger.types.ts +3 -1
  141. package/src/core/objects/event-trigger/event-trigger.diff.ts +33 -0
  142. package/src/core/objects/event-trigger/event-trigger.model.ts +22 -1
  143. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.base.ts +5 -1
  144. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.security-label.ts +95 -0
  145. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.types.ts +3 -1
  146. package/src/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.ts +33 -0
  147. package/src/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.ts +24 -1
  148. package/src/core/objects/materialized-view/changes/materialized-view.base.ts +5 -1
  149. package/src/core/objects/materialized-view/changes/materialized-view.security-label.test.ts +63 -0
  150. package/src/core/objects/materialized-view/changes/materialized-view.security-label.ts +95 -0
  151. package/src/core/objects/materialized-view/changes/materialized-view.types.ts +3 -1
  152. package/src/core/objects/materialized-view/materialized-view.diff.ts +37 -0
  153. package/src/core/objects/materialized-view/materialized-view.model.ts +25 -4
  154. package/src/core/objects/procedure/changes/procedure.base.ts +5 -1
  155. package/src/core/objects/procedure/changes/procedure.security-label.ts +105 -0
  156. package/src/core/objects/procedure/changes/procedure.types.ts +3 -1
  157. package/src/core/objects/procedure/procedure.diff.ts +33 -0
  158. package/src/core/objects/procedure/procedure.model.ts +23 -2
  159. package/src/core/objects/publication/changes/publication.base.ts +1 -1
  160. package/src/core/objects/publication/changes/publication.security-label.ts +95 -0
  161. package/src/core/objects/publication/changes/publication.types.ts +3 -1
  162. package/src/core/objects/publication/publication.diff.ts +33 -0
  163. package/src/core/objects/publication/publication.model.ts +24 -1
  164. package/src/core/objects/role/changes/role.base.ts +2 -1
  165. package/src/core/objects/role/changes/role.security-label.ts +77 -0
  166. package/src/core/objects/role/changes/role.types.ts +3 -1
  167. package/src/core/objects/role/role.diff.ts +33 -0
  168. package/src/core/objects/role/role.model.ts +32 -0
  169. package/src/core/objects/schema/changes/schema.alter.test.ts +1 -0
  170. package/src/core/objects/schema/changes/schema.base.ts +5 -1
  171. package/src/core/objects/schema/changes/schema.create.test.ts +1 -0
  172. package/src/core/objects/schema/changes/schema.drop.test.ts +1 -0
  173. package/src/core/objects/schema/changes/schema.security-label.test.ts +76 -0
  174. package/src/core/objects/schema/changes/schema.security-label.ts +77 -0
  175. package/src/core/objects/schema/changes/schema.types.ts +3 -1
  176. package/src/core/objects/schema/schema.diff.test.ts +1 -0
  177. package/src/core/objects/schema/schema.diff.ts +43 -1
  178. package/src/core/objects/schema/schema.model.ts +21 -1
  179. package/src/core/objects/security-label.types.test.ts +106 -0
  180. package/src/core/objects/security-label.types.ts +61 -0
  181. package/src/core/objects/sequence/changes/sequence.base.ts +5 -1
  182. package/src/core/objects/sequence/changes/sequence.security-label.test.ts +58 -0
  183. package/src/core/objects/sequence/changes/sequence.security-label.ts +92 -0
  184. package/src/core/objects/sequence/changes/sequence.types.ts +3 -1
  185. package/src/core/objects/sequence/sequence.diff.ts +33 -0
  186. package/src/core/objects/sequence/sequence.model.ts +22 -1
  187. package/src/core/objects/subscription/changes/subscription.base.ts +1 -1
  188. package/src/core/objects/subscription/changes/subscription.security-label.ts +95 -0
  189. package/src/core/objects/subscription/changes/subscription.types.ts +3 -1
  190. package/src/core/objects/subscription/subscription.diff.ts +33 -0
  191. package/src/core/objects/subscription/subscription.model.ts +22 -1
  192. package/src/core/objects/table/changes/table.base.ts +5 -1
  193. package/src/core/objects/table/changes/table.security-label.test.ts +140 -0
  194. package/src/core/objects/table/changes/table.security-label.ts +183 -0
  195. package/src/core/objects/table/changes/table.types.ts +3 -1
  196. package/src/core/objects/table/table.diff.ts +87 -0
  197. package/src/core/objects/table/table.model.ts +42 -2
  198. package/src/core/objects/type/composite-type/changes/composite-type.base.ts +5 -1
  199. package/src/core/objects/type/composite-type/changes/composite-type.security-label.ts +95 -0
  200. package/src/core/objects/type/composite-type/changes/composite-type.types.ts +3 -1
  201. package/src/core/objects/type/composite-type/composite-type.diff.ts +33 -0
  202. package/src/core/objects/type/composite-type/composite-type.model.ts +26 -2
  203. package/src/core/objects/type/enum/changes/enum.base.ts +5 -1
  204. package/src/core/objects/type/enum/changes/enum.security-label.ts +77 -0
  205. package/src/core/objects/type/enum/changes/enum.types.ts +3 -1
  206. package/src/core/objects/type/enum/enum.diff.ts +33 -0
  207. package/src/core/objects/type/enum/enum.model.ts +25 -1
  208. package/src/core/objects/type/range/changes/range.base.ts +5 -1
  209. package/src/core/objects/type/range/changes/range.security-label.ts +77 -0
  210. package/src/core/objects/type/range/changes/range.types.ts +3 -1
  211. package/src/core/objects/type/range/range.diff.ts +33 -0
  212. package/src/core/objects/type/range/range.model.ts +22 -1
  213. package/src/core/objects/utils.ts +3 -0
  214. package/src/core/objects/view/changes/view.base.ts +5 -1
  215. package/src/core/objects/view/changes/view.security-label.test.ts +64 -0
  216. package/src/core/objects/view/changes/view.security-label.ts +77 -0
  217. package/src/core/objects/view/changes/view.types.ts +3 -1
  218. package/src/core/objects/view/view.diff.ts +31 -0
  219. package/src/core/objects/view/view.model.ts +25 -2
  220. package/src/core/plan/sql-format/fixtures.ts +1 -0
@@ -0,0 +1,61 @@
1
+ import { quoteLiteral } from "../../base.change.js";
2
+ import { stableId } from "../../utils.js";
3
+ import { CreateSequenceChange, DropSequenceChange } from "./sequence.base.js";
4
+ export class CreateSecurityLabelOnSequence extends CreateSequenceChange {
5
+ sequence;
6
+ securityLabel;
7
+ scope = "security_label";
8
+ constructor(props) {
9
+ super();
10
+ this.sequence = props.sequence;
11
+ this.securityLabel = props.securityLabel;
12
+ }
13
+ get creates() {
14
+ return [
15
+ stableId.securityLabel(this.sequence.stableId, this.securityLabel.provider),
16
+ ];
17
+ }
18
+ get requires() {
19
+ return [this.sequence.stableId];
20
+ }
21
+ serialize() {
22
+ return [
23
+ "SECURITY LABEL FOR",
24
+ this.securityLabel.provider,
25
+ "ON SEQUENCE",
26
+ `${this.sequence.schema}.${this.sequence.name}`,
27
+ "IS",
28
+ quoteLiteral(this.securityLabel.label),
29
+ ].join(" ");
30
+ }
31
+ }
32
+ export class DropSecurityLabelOnSequence extends DropSequenceChange {
33
+ sequence;
34
+ securityLabel;
35
+ scope = "security_label";
36
+ constructor(props) {
37
+ super();
38
+ this.sequence = props.sequence;
39
+ this.securityLabel = props.securityLabel;
40
+ }
41
+ get drops() {
42
+ return [
43
+ stableId.securityLabel(this.sequence.stableId, this.securityLabel.provider),
44
+ ];
45
+ }
46
+ get requires() {
47
+ return [
48
+ stableId.securityLabel(this.sequence.stableId, this.securityLabel.provider),
49
+ this.sequence.stableId,
50
+ ];
51
+ }
52
+ serialize() {
53
+ return [
54
+ "SECURITY LABEL FOR",
55
+ this.securityLabel.provider,
56
+ "ON SEQUENCE",
57
+ `${this.sequence.schema}.${this.sequence.name}`,
58
+ "IS NULL",
59
+ ].join(" ");
60
+ }
61
+ }
@@ -3,5 +3,6 @@ import type { CommentSequence } from "./sequence.comment.ts";
3
3
  import type { CreateSequence } from "./sequence.create.ts";
4
4
  import type { DropSequence } from "./sequence.drop.ts";
5
5
  import type { SequencePrivilege } from "./sequence.privilege.ts";
6
+ import type { SecurityLabelSequence } from "./sequence.security-label.ts";
6
7
  /** Union of all sequence-related change variants (`objectType: "sequence"`). @category Change Types */
7
- export type SequenceChange = AlterSequence | CommentSequence | CreateSequence | DropSequence | SequencePrivilege;
8
+ export type SequenceChange = AlterSequence | CommentSequence | CreateSequence | DropSequence | SequencePrivilege | SecurityLabelSequence;
@@ -1,5 +1,6 @@
1
1
  import { diffObjects } from "../base.diff.js";
2
2
  import { diffPrivileges, emitObjectPrivilegeChanges, } from "../base.privilege-diff.js";
3
+ import { diffSecurityLabels } from "../security-label.types.js";
3
4
  import { AlterTableAlterColumnSetDefault } from "../table/changes/table.alter.js";
4
5
  import { hasNonAlterableChanges } from "../utils.js";
5
6
  import { AlterSequenceSetOptions, AlterSequenceSetOwnedBy, } from "./changes/sequence.alter.js";
@@ -7,6 +8,7 @@ import { CreateCommentOnSequence, DropCommentOnSequence, } from "./changes/seque
7
8
  import { CreateSequence } from "./changes/sequence.create.js";
8
9
  import { DropSequence } from "./changes/sequence.drop.js";
9
10
  import { GrantSequencePrivileges, RevokeGrantOptionSequencePrivileges, RevokeSequencePrivileges, } from "./changes/sequence.privilege.js";
11
+ import { CreateSecurityLabelOnSequence, DropSecurityLabelOnSequence, } from "./changes/sequence.security-label.js";
10
12
  /**
11
13
  * Diff two sets of sequences from main and branch catalogs.
12
14
  *
@@ -26,6 +28,12 @@ export function diffSequences(ctx, main, branch, branchTables = {}, mainTables =
26
28
  if (createdSeq.comment !== null) {
27
29
  changes.push(new CreateCommentOnSequence({ sequence: createdSeq }));
28
30
  }
31
+ for (const label of createdSeq.security_labels) {
32
+ changes.push(new CreateSecurityLabelOnSequence({
33
+ sequence: createdSeq,
34
+ securityLabel: label,
35
+ }));
36
+ }
29
37
  // If the created sequence is OWNED BY a column, emit an ALTER to set it
30
38
  if (createdSeq.owned_by_schema !== null &&
31
39
  createdSeq.owned_by_table !== null &&
@@ -229,6 +237,14 @@ export function diffSequences(ctx, main, branch, branchTables = {}, mainTables =
229
237
  changes.push(new CreateCommentOnSequence({ sequence: branchSequence }));
230
238
  }
231
239
  }
240
+ // SECURITY LABELS
241
+ changes.push(...diffSecurityLabels(mainSequence.security_labels, branchSequence.security_labels, (securityLabel) => new CreateSecurityLabelOnSequence({
242
+ sequence: branchSequence,
243
+ securityLabel,
244
+ }), (securityLabel) => new DropSecurityLabelOnSequence({
245
+ sequence: mainSequence,
246
+ securityLabel,
247
+ })));
232
248
  // PRIVILEGES
233
249
  // Filter out owner privileges - owner always has ALL privileges implicitly
234
250
  // and shouldn't be compared. Use branch owner as the reference.
@@ -2,6 +2,7 @@ import type { Pool } from "pg";
2
2
  import z from "zod";
3
3
  import { BasePgModel } from "../base.model.ts";
4
4
  import { type PrivilegeProps } from "../base.privilege-diff.ts";
5
+ import { type SecurityLabelProps } from "../security-label.types.ts";
5
6
  declare const sequencePropsSchema: z.ZodObject<{
6
7
  schema: z.ZodString;
7
8
  name: z.ZodString;
@@ -24,6 +25,10 @@ declare const sequencePropsSchema: z.ZodObject<{
24
25
  columns: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
25
26
  }, z.z.core.$strip>>;
26
27
  owner: z.ZodString;
28
+ security_labels: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
29
+ provider: z.ZodString;
30
+ label: z.ZodString;
31
+ }, z.z.core.$strip>>>>;
27
32
  }, z.z.core.$strip>;
28
33
  type SequencePrivilegeProps = PrivilegeProps;
29
34
  export type SequenceProps = z.infer<typeof sequencePropsSchema>;
@@ -44,6 +49,7 @@ export declare class Sequence extends BasePgModel {
44
49
  readonly comment: SequenceProps["comment"];
45
50
  readonly privileges: SequencePrivilegeProps[];
46
51
  readonly owner: SequenceProps["owner"];
52
+ readonly security_labels: SecurityLabelProps[];
47
53
  constructor(props: SequenceProps);
48
54
  get stableId(): `sequence:${string}`;
49
55
  get identityFields(): {
@@ -70,6 +76,10 @@ export declare class Sequence extends BasePgModel {
70
76
  columns?: string[] | null | undefined;
71
77
  }[];
72
78
  owner: string;
79
+ security_labels: {
80
+ provider: string;
81
+ label: string;
82
+ }[];
73
83
  };
74
84
  }
75
85
  export declare function extractSequences(pool: Pool): Promise<Sequence[]>;
@@ -2,6 +2,7 @@ import { sql } from "@ts-safeql/sql-tag";
2
2
  import z from "zod";
3
3
  import { BasePgModel } from "../base.model.js";
4
4
  import { privilegePropsSchema, } from "../base.privilege-diff.js";
5
+ import { securityLabelPropsSchema, } from "../security-label.types.js";
5
6
  const sequencePropsSchema = z.object({
6
7
  schema: z.string(),
7
8
  name: z.string(),
@@ -19,6 +20,7 @@ const sequencePropsSchema = z.object({
19
20
  comment: z.string().nullable(),
20
21
  privileges: z.array(privilegePropsSchema),
21
22
  owner: z.string(),
23
+ security_labels: z.array(securityLabelPropsSchema).default([]).optional(),
22
24
  });
23
25
  export class Sequence extends BasePgModel {
24
26
  schema;
@@ -37,6 +39,7 @@ export class Sequence extends BasePgModel {
37
39
  comment;
38
40
  privileges;
39
41
  owner;
42
+ security_labels;
40
43
  constructor(props) {
41
44
  super();
42
45
  // Identity fields
@@ -57,6 +60,7 @@ export class Sequence extends BasePgModel {
57
60
  this.comment = props.comment;
58
61
  this.privileges = props.privileges;
59
62
  this.owner = props.owner;
63
+ this.security_labels = props.security_labels ?? [];
60
64
  }
61
65
  get stableId() {
62
66
  return `sequence:${this.schema}.${this.name}`;
@@ -83,6 +87,7 @@ export class Sequence extends BasePgModel {
83
87
  comment: this.comment,
84
88
  privileges: this.privileges,
85
89
  owner: this.owner,
90
+ security_labels: this.security_labels,
86
91
  };
87
92
  }
88
93
  }
@@ -135,7 +140,20 @@ select
135
140
  from lateral aclexplode(COALESCE(c.relacl, acldefault('S', c.relowner))) as x(grantor, grantee, privilege_type, is_grantable)
136
141
  ), '[]'
137
142
  ) as privileges,
138
- c.relowner::regrole::text as owner
143
+ c.relowner::regrole::text as owner,
144
+ coalesce(
145
+ (
146
+ select json_agg(
147
+ json_build_object('provider', sl.provider, 'label', sl.label)
148
+ order by sl.provider
149
+ )
150
+ from pg_catalog.pg_seclabel sl
151
+ where sl.objoid = c.oid
152
+ and sl.classoid = 'pg_class'::regclass
153
+ and sl.objsubid = 0
154
+ ),
155
+ '[]'::json
156
+ ) as security_labels
139
157
  from
140
158
  pg_catalog.pg_class c
141
159
  inner join pg_catalog.pg_sequence s on s.seqrelid = c.oid
@@ -2,7 +2,7 @@ import { BaseChange } from "../../base.change.ts";
2
2
  import type { Subscription } from "../subscription.model.ts";
3
3
  declare abstract class BaseSubscriptionChange extends BaseChange {
4
4
  abstract readonly subscription: Subscription;
5
- abstract readonly scope: "object" | "comment";
5
+ abstract readonly scope: "object" | "comment" | "security_label";
6
6
  readonly objectType: "subscription";
7
7
  }
8
8
  export declare abstract class CreateSubscriptionChange extends BaseSubscriptionChange {
@@ -0,0 +1,28 @@
1
+ import type { SecurityLabelProps } from "../../security-label.types.ts";
2
+ import type { Subscription } from "../subscription.model.ts";
3
+ import { CreateSubscriptionChange, DropSubscriptionChange } from "./subscription.base.ts";
4
+ export type SecurityLabelSubscription = CreateSecurityLabelOnSubscription | DropSecurityLabelOnSubscription;
5
+ export declare class CreateSecurityLabelOnSubscription extends CreateSubscriptionChange {
6
+ readonly subscription: Subscription;
7
+ readonly securityLabel: SecurityLabelProps;
8
+ readonly scope: "security_label";
9
+ constructor(props: {
10
+ subscription: Subscription;
11
+ securityLabel: SecurityLabelProps;
12
+ });
13
+ get creates(): `securityLabel:${string}::provider:${string}`[];
14
+ get requires(): `subscription:${string}`[];
15
+ serialize(): string;
16
+ }
17
+ export declare class DropSecurityLabelOnSubscription extends DropSubscriptionChange {
18
+ readonly subscription: Subscription;
19
+ readonly securityLabel: SecurityLabelProps;
20
+ readonly scope: "security_label";
21
+ constructor(props: {
22
+ subscription: Subscription;
23
+ securityLabel: SecurityLabelProps;
24
+ });
25
+ get drops(): `securityLabel:${string}::provider:${string}`[];
26
+ get requires(): (`securityLabel:${string}::provider:${string}` | `subscription:${string}`)[];
27
+ serialize(): string;
28
+ }
@@ -0,0 +1,61 @@
1
+ import { quoteLiteral } from "../../base.change.js";
2
+ import { stableId } from "../../utils.js";
3
+ import { CreateSubscriptionChange, DropSubscriptionChange, } from "./subscription.base.js";
4
+ export class CreateSecurityLabelOnSubscription extends CreateSubscriptionChange {
5
+ subscription;
6
+ securityLabel;
7
+ scope = "security_label";
8
+ constructor(props) {
9
+ super();
10
+ this.subscription = props.subscription;
11
+ this.securityLabel = props.securityLabel;
12
+ }
13
+ get creates() {
14
+ return [
15
+ stableId.securityLabel(this.subscription.stableId, this.securityLabel.provider),
16
+ ];
17
+ }
18
+ get requires() {
19
+ return [this.subscription.stableId];
20
+ }
21
+ serialize() {
22
+ return [
23
+ "SECURITY LABEL FOR",
24
+ this.securityLabel.provider,
25
+ "ON SUBSCRIPTION",
26
+ this.subscription.name,
27
+ "IS",
28
+ quoteLiteral(this.securityLabel.label),
29
+ ].join(" ");
30
+ }
31
+ }
32
+ export class DropSecurityLabelOnSubscription extends DropSubscriptionChange {
33
+ subscription;
34
+ securityLabel;
35
+ scope = "security_label";
36
+ constructor(props) {
37
+ super();
38
+ this.subscription = props.subscription;
39
+ this.securityLabel = props.securityLabel;
40
+ }
41
+ get drops() {
42
+ return [
43
+ stableId.securityLabel(this.subscription.stableId, this.securityLabel.provider),
44
+ ];
45
+ }
46
+ get requires() {
47
+ return [
48
+ stableId.securityLabel(this.subscription.stableId, this.securityLabel.provider),
49
+ this.subscription.stableId,
50
+ ];
51
+ }
52
+ serialize() {
53
+ return [
54
+ "SECURITY LABEL FOR",
55
+ this.securityLabel.provider,
56
+ "ON SUBSCRIPTION",
57
+ this.subscription.name,
58
+ "IS NULL",
59
+ ].join(" ");
60
+ }
61
+ }
@@ -2,5 +2,6 @@ import type { AlterSubscriptionDisable, AlterSubscriptionEnable, AlterSubscripti
2
2
  import type { CommentSubscription } from "./subscription.comment.ts";
3
3
  import type { CreateSubscription } from "./subscription.create.ts";
4
4
  import type { DropSubscription } from "./subscription.drop.ts";
5
+ import type { SecurityLabelSubscription } from "./subscription.security-label.ts";
5
6
  /** Union of all subscription-related change variants (`objectType: "subscription"`). @category Change Types */
6
- export type SubscriptionChange = CreateSubscription | DropSubscription | AlterSubscriptionSetConnection | AlterSubscriptionSetPublication | AlterSubscriptionEnable | AlterSubscriptionDisable | AlterSubscriptionSetOptions | AlterSubscriptionSetOwner | CommentSubscription;
7
+ export type SubscriptionChange = CreateSubscription | DropSubscription | AlterSubscriptionSetConnection | AlterSubscriptionSetPublication | AlterSubscriptionEnable | AlterSubscriptionDisable | AlterSubscriptionSetOptions | AlterSubscriptionSetOwner | CommentSubscription | SecurityLabelSubscription;
@@ -1,9 +1,11 @@
1
1
  import { diffObjects } from "../base.diff.js";
2
+ import { diffSecurityLabels } from "../security-label.types.js";
2
3
  import { hasNonAlterableChanges } from "../utils.js";
3
4
  import { AlterSubscriptionDisable, AlterSubscriptionEnable, AlterSubscriptionSetConnection, AlterSubscriptionSetOptions, AlterSubscriptionSetOwner, AlterSubscriptionSetPublication, } from "./changes/subscription.alter.js";
4
5
  import { CreateCommentOnSubscription, DropCommentOnSubscription, } from "./changes/subscription.comment.js";
5
6
  import { CreateSubscription } from "./changes/subscription.create.js";
6
7
  import { DropSubscription } from "./changes/subscription.drop.js";
8
+ import { CreateSecurityLabelOnSubscription, DropSecurityLabelOnSubscription, } from "./changes/subscription.security-label.js";
7
9
  const NON_ALTERABLE_FIELDS = [
8
10
  "two_phase",
9
11
  ];
@@ -35,6 +37,12 @@ export function diffSubscriptions(ctx, main, branch) {
35
37
  if (subscription.comment !== null) {
36
38
  changes.push(new CreateCommentOnSubscription({ subscription }));
37
39
  }
40
+ for (const label of subscription.security_labels) {
41
+ changes.push(new CreateSecurityLabelOnSubscription({
42
+ subscription,
43
+ securityLabel: label,
44
+ }));
45
+ }
38
46
  }
39
47
  for (const id of dropped) {
40
48
  changes.push(new DropSubscription({ subscription: main[id] }));
@@ -162,6 +170,14 @@ export function diffSubscriptions(ctx, main, branch) {
162
170
  }));
163
171
  }
164
172
  }
173
+ // SECURITY LABELS
174
+ changes.push(...diffSecurityLabels(mainSubscription.security_labels, branchSubscription.security_labels, (securityLabel) => new CreateSecurityLabelOnSubscription({
175
+ subscription: branchSubscription,
176
+ securityLabel,
177
+ }), (securityLabel) => new DropSecurityLabelOnSubscription({
178
+ subscription: mainSubscription,
179
+ securityLabel,
180
+ })));
165
181
  }
166
182
  return changes;
167
183
  }
@@ -1,6 +1,7 @@
1
1
  import type { Pool } from "pg";
2
2
  import z from "zod";
3
3
  import { BasePgModel } from "../base.model.ts";
4
+ import { type SecurityLabelProps } from "../security-label.types.ts";
4
5
  declare const subscriptionPropsSchema: z.ZodObject<{
5
6
  name: z.ZodString;
6
7
  raw_name: z.ZodString;
@@ -28,6 +29,10 @@ declare const subscriptionPropsSchema: z.ZodObject<{
28
29
  any: "any";
29
30
  none: "none";
30
31
  }>;
32
+ security_labels: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
33
+ provider: z.ZodString;
34
+ label: z.ZodString;
35
+ }, z.z.core.$strip>>>>;
31
36
  }, z.z.core.$strip>;
32
37
  export type SubscriptionProps = z.infer<typeof subscriptionPropsSchema>;
33
38
  export declare class Subscription extends BasePgModel {
@@ -50,6 +55,7 @@ export declare class Subscription extends BasePgModel {
50
55
  readonly synchronous_commit: SubscriptionProps["synchronous_commit"];
51
56
  readonly publications: SubscriptionProps["publications"];
52
57
  readonly origin: SubscriptionProps["origin"];
58
+ readonly security_labels: SecurityLabelProps[];
53
59
  constructor(props: SubscriptionProps);
54
60
  get stableId(): `subscription:${string}`;
55
61
  get identityFields(): {
@@ -74,6 +80,10 @@ export declare class Subscription extends BasePgModel {
74
80
  synchronous_commit: string;
75
81
  publications: string[];
76
82
  origin: "any" | "none";
83
+ security_labels: {
84
+ provider: string;
85
+ label: string;
86
+ }[];
77
87
  };
78
88
  }
79
89
  export declare function extractSubscriptions(pool: Pool): Promise<Subscription[]>;
@@ -1,6 +1,7 @@
1
1
  import z from "zod";
2
2
  import { extractVersion } from "../../context.js";
3
3
  import { BasePgModel } from "../base.model.js";
4
+ import { securityLabelPropsSchema, } from "../security-label.types.js";
4
5
  const subscriptionPropsSchema = z.object({
5
6
  name: z.string(),
6
7
  raw_name: z.string(),
@@ -21,6 +22,7 @@ const subscriptionPropsSchema = z.object({
21
22
  synchronous_commit: z.string(),
22
23
  publications: z.array(z.string()),
23
24
  origin: z.enum(["any", "none"]),
25
+ security_labels: z.array(securityLabelPropsSchema).default([]).optional(),
24
26
  });
25
27
  export class Subscription extends BasePgModel {
26
28
  name;
@@ -42,6 +44,7 @@ export class Subscription extends BasePgModel {
42
44
  synchronous_commit;
43
45
  publications;
44
46
  origin;
47
+ security_labels;
45
48
  constructor(props) {
46
49
  super();
47
50
  this.name = props.name;
@@ -63,6 +66,7 @@ export class Subscription extends BasePgModel {
63
66
  this.synchronous_commit = props.synchronous_commit;
64
67
  this.publications = [...props.publications].sort((a, b) => a.localeCompare(b));
65
68
  this.origin = props.origin;
69
+ this.security_labels = props.security_labels ?? [];
66
70
  }
67
71
  get stableId() {
68
72
  return `subscription:${this.name}`;
@@ -92,6 +96,7 @@ export class Subscription extends BasePgModel {
92
96
  synchronous_commit: this.synchronous_commit,
93
97
  publications: this.publications,
94
98
  origin: this.origin,
99
+ security_labels: this.security_labels,
95
100
  };
96
101
  }
97
102
  }
@@ -156,7 +161,20 @@ export async function extractSubscriptions(pool) {
156
161
  ),
157
162
  '[]'::json
158
163
  ) as publications,
159
- ${originExpr} as origin
164
+ ${originExpr} as origin,
165
+ coalesce(
166
+ (
167
+ select json_agg(
168
+ json_build_object('provider', sl.provider, 'label', sl.label)
169
+ order by sl.provider
170
+ )
171
+ from pg_catalog.pg_seclabel sl
172
+ where sl.objoid = s.oid
173
+ and sl.classoid = 'pg_subscription'::regclass
174
+ and sl.objsubid = 0
175
+ ),
176
+ '[]'::json
177
+ ) as security_labels
160
178
  from scoped_subscriptions s
161
179
  left join pg_replication_slots r
162
180
  on r.slot_name = s.subslotname
@@ -2,7 +2,7 @@ import { BaseChange } from "../../base.change.ts";
2
2
  import type { Table } from "../table.model.ts";
3
3
  declare abstract class BaseTableChange extends BaseChange {
4
4
  abstract readonly table: Table;
5
- abstract readonly scope: "object" | "comment" | "privilege";
5
+ abstract readonly scope: "object" | "comment" | "privilege" | "security_label";
6
6
  readonly objectType: "table";
7
7
  }
8
8
  export declare abstract class CreateTableChange extends BaseTableChange {
@@ -0,0 +1,63 @@
1
+ import type { ColumnProps } from "../../base.model.ts";
2
+ import type { SecurityLabelProps } from "../../security-label.types.ts";
3
+ import type { Table } from "../table.model.ts";
4
+ import { CreateTableChange, DropTableChange } from "./table.base.ts";
5
+ export type SecurityLabelTable = CreateSecurityLabelOnTable | DropSecurityLabelOnTable | CreateSecurityLabelOnColumn | DropSecurityLabelOnColumn;
6
+ /**
7
+ * SECURITY LABEL FOR <provider> ON TABLE <schema>.<table> IS <literal>
8
+ */
9
+ export declare class CreateSecurityLabelOnTable extends CreateTableChange {
10
+ readonly table: Table;
11
+ readonly securityLabel: SecurityLabelProps;
12
+ readonly scope: "security_label";
13
+ constructor(props: {
14
+ table: Table;
15
+ securityLabel: SecurityLabelProps;
16
+ });
17
+ get creates(): `securityLabel:${string}::provider:${string}`[];
18
+ get requires(): `table:${string}`[];
19
+ serialize(): string;
20
+ }
21
+ export declare class DropSecurityLabelOnTable extends DropTableChange {
22
+ readonly table: Table;
23
+ readonly securityLabel: SecurityLabelProps;
24
+ readonly scope: "security_label";
25
+ constructor(props: {
26
+ table: Table;
27
+ securityLabel: SecurityLabelProps;
28
+ });
29
+ get drops(): `securityLabel:${string}::provider:${string}`[];
30
+ get requires(): (`securityLabel:${string}::provider:${string}` | `table:${string}`)[];
31
+ serialize(): string;
32
+ }
33
+ /**
34
+ * SECURITY LABEL FOR <provider> ON COLUMN <schema>.<table>.<column> IS <literal>
35
+ */
36
+ export declare class CreateSecurityLabelOnColumn extends CreateTableChange {
37
+ readonly table: Table;
38
+ readonly column: ColumnProps;
39
+ readonly securityLabel: SecurityLabelProps;
40
+ readonly scope: "security_label";
41
+ constructor(props: {
42
+ table: Table;
43
+ column: ColumnProps;
44
+ securityLabel: SecurityLabelProps;
45
+ });
46
+ get creates(): `securityLabel:${string}::provider:${string}`[];
47
+ get requires(): `column:${string}.${string}.${string}`[];
48
+ serialize(): string;
49
+ }
50
+ export declare class DropSecurityLabelOnColumn extends DropTableChange {
51
+ readonly table: Table;
52
+ readonly column: ColumnProps;
53
+ readonly securityLabel: SecurityLabelProps;
54
+ readonly scope: "security_label";
55
+ constructor(props: {
56
+ table: Table;
57
+ column: ColumnProps;
58
+ securityLabel: SecurityLabelProps;
59
+ });
60
+ get drops(): `securityLabel:${string}::provider:${string}`[];
61
+ get requires(): (`column:${string}.${string}.${string}` | `securityLabel:${string}::provider:${string}`)[];
62
+ serialize(): string;
63
+ }
@@ -0,0 +1,134 @@
1
+ import { quoteLiteral } from "../../base.change.js";
2
+ import { stableId } from "../../utils.js";
3
+ import { CreateTableChange, DropTableChange } from "./table.base.js";
4
+ /**
5
+ * SECURITY LABEL FOR <provider> ON TABLE <schema>.<table> IS <literal>
6
+ */
7
+ export class CreateSecurityLabelOnTable extends CreateTableChange {
8
+ table;
9
+ securityLabel;
10
+ scope = "security_label";
11
+ constructor(props) {
12
+ super();
13
+ this.table = props.table;
14
+ this.securityLabel = props.securityLabel;
15
+ }
16
+ get creates() {
17
+ return [
18
+ stableId.securityLabel(this.table.stableId, this.securityLabel.provider),
19
+ ];
20
+ }
21
+ get requires() {
22
+ return [this.table.stableId];
23
+ }
24
+ serialize() {
25
+ return [
26
+ "SECURITY LABEL FOR",
27
+ this.securityLabel.provider,
28
+ "ON TABLE",
29
+ `${this.table.schema}.${this.table.name}`,
30
+ "IS",
31
+ quoteLiteral(this.securityLabel.label),
32
+ ].join(" ");
33
+ }
34
+ }
35
+ export class DropSecurityLabelOnTable extends DropTableChange {
36
+ table;
37
+ securityLabel;
38
+ scope = "security_label";
39
+ constructor(props) {
40
+ super();
41
+ this.table = props.table;
42
+ this.securityLabel = props.securityLabel;
43
+ }
44
+ get drops() {
45
+ return [
46
+ stableId.securityLabel(this.table.stableId, this.securityLabel.provider),
47
+ ];
48
+ }
49
+ get requires() {
50
+ return [
51
+ stableId.securityLabel(this.table.stableId, this.securityLabel.provider),
52
+ this.table.stableId,
53
+ ];
54
+ }
55
+ serialize() {
56
+ return [
57
+ "SECURITY LABEL FOR",
58
+ this.securityLabel.provider,
59
+ "ON TABLE",
60
+ `${this.table.schema}.${this.table.name}`,
61
+ "IS NULL",
62
+ ].join(" ");
63
+ }
64
+ }
65
+ /**
66
+ * SECURITY LABEL FOR <provider> ON COLUMN <schema>.<table>.<column> IS <literal>
67
+ */
68
+ export class CreateSecurityLabelOnColumn extends CreateTableChange {
69
+ table;
70
+ column;
71
+ securityLabel;
72
+ scope = "security_label";
73
+ constructor(props) {
74
+ super();
75
+ this.table = props.table;
76
+ this.column = props.column;
77
+ this.securityLabel = props.securityLabel;
78
+ }
79
+ get creates() {
80
+ const columnStableId = stableId.column(this.table.schema, this.table.name, this.column.name);
81
+ return [
82
+ stableId.securityLabel(columnStableId, this.securityLabel.provider),
83
+ ];
84
+ }
85
+ get requires() {
86
+ return [
87
+ stableId.column(this.table.schema, this.table.name, this.column.name),
88
+ ];
89
+ }
90
+ serialize() {
91
+ return [
92
+ "SECURITY LABEL FOR",
93
+ this.securityLabel.provider,
94
+ "ON COLUMN",
95
+ `${this.table.schema}.${this.table.name}.${this.column.name}`,
96
+ "IS",
97
+ quoteLiteral(this.securityLabel.label),
98
+ ].join(" ");
99
+ }
100
+ }
101
+ export class DropSecurityLabelOnColumn extends DropTableChange {
102
+ table;
103
+ column;
104
+ securityLabel;
105
+ scope = "security_label";
106
+ constructor(props) {
107
+ super();
108
+ this.table = props.table;
109
+ this.column = props.column;
110
+ this.securityLabel = props.securityLabel;
111
+ }
112
+ get drops() {
113
+ const columnStableId = stableId.column(this.table.schema, this.table.name, this.column.name);
114
+ return [
115
+ stableId.securityLabel(columnStableId, this.securityLabel.provider),
116
+ ];
117
+ }
118
+ get requires() {
119
+ const columnStableId = stableId.column(this.table.schema, this.table.name, this.column.name);
120
+ return [
121
+ stableId.securityLabel(columnStableId, this.securityLabel.provider),
122
+ columnStableId,
123
+ ];
124
+ }
125
+ serialize() {
126
+ return [
127
+ "SECURITY LABEL FOR",
128
+ this.securityLabel.provider,
129
+ "ON COLUMN",
130
+ `${this.table.schema}.${this.table.name}.${this.column.name}`,
131
+ "IS NULL",
132
+ ].join(" ");
133
+ }
134
+ }
@@ -3,5 +3,6 @@ import type { CommentTable } from "./table.comment.ts";
3
3
  import type { CreateTable } from "./table.create.ts";
4
4
  import type { DropTable } from "./table.drop.ts";
5
5
  import type { TablePrivilege } from "./table.privilege.ts";
6
+ import type { SecurityLabelTable } from "./table.security-label.ts";
6
7
  /** Union of all table-related change variants (`objectType: "table"`). @category Change Types */
7
- export type TableChange = AlterTable | CommentTable | CreateTable | DropTable | TablePrivilege;
8
+ export type TableChange = AlterTable | CommentTable | CreateTable | DropTable | TablePrivilege | SecurityLabelTable;