@supabase/pg-delta 1.0.0-alpha.25 → 1.0.0-alpha.26
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 +2 -0
- package/dist/core/expand-replace-dependencies.js +1 -7
- package/dist/core/objects/table/table.diff.js +53 -30
- package/dist/core/plan/hierarchy.js +4 -4
- package/dist/core/postgres-config.d.ts +7 -0
- package/dist/core/postgres-config.js +19 -5
- package/dist/core/sort/debug-visualization.js +1 -1
- package/dist/core/sort/topological-sort.js +2 -2
- package/package.json +34 -33
- package/src/core/catalog.model.ts +4 -3
- package/src/core/catalog.snapshot.test.ts +1 -0
- package/src/core/expand-replace-dependencies.test.ts +12 -0
- package/src/core/expand-replace-dependencies.ts +1 -12
- package/src/core/objects/aggregate/changes/aggregate.base.ts +1 -1
- package/src/core/objects/collation/changes/collation.base.ts +1 -1
- package/src/core/objects/domain/changes/domain.base.ts +1 -1
- package/src/core/objects/extension/changes/extension.base.ts +1 -1
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.base.ts +1 -1
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.base.ts +1 -1
- package/src/core/objects/foreign-data-wrapper/server/changes/server.base.ts +1 -1
- package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.base.ts +1 -1
- package/src/core/objects/index/changes/index.base.ts +1 -1
- package/src/core/objects/language/changes/language.base.ts +1 -1
- package/src/core/objects/materialized-view/changes/materialized-view.base.ts +1 -1
- package/src/core/objects/procedure/changes/procedure.base.ts +1 -1
- package/src/core/objects/rls-policy/changes/rls-policy.base.ts +1 -1
- package/src/core/objects/role/changes/role.base.ts +1 -1
- package/src/core/objects/schema/changes/schema.base.ts +1 -1
- package/src/core/objects/sequence/changes/sequence.base.ts +1 -1
- package/src/core/objects/table/changes/table.base.ts +1 -1
- package/src/core/objects/table/changes/table.comment.ts +2 -8
- package/src/core/objects/table/table.diff.test.ts +198 -5
- package/src/core/objects/table/table.diff.ts +63 -34
- package/src/core/objects/trigger/changes/trigger.alter.ts +1 -4
- package/src/core/objects/trigger/changes/trigger.base.ts +1 -1
- package/src/core/objects/type/composite-type/changes/composite-type.base.ts +1 -1
- package/src/core/objects/type/enum/changes/enum.base.ts +1 -1
- package/src/core/objects/type/range/changes/range.base.ts +1 -1
- package/src/core/objects/view/changes/view.base.ts +1 -1
- package/src/core/plan/hierarchy.ts +4 -4
- package/src/core/postgres-config.test.ts +39 -1
- package/src/core/postgres-config.ts +32 -16
- package/src/core/sort/debug-visualization.ts +1 -1
- package/src/core/sort/sort-changes.test.ts +1 -0
- package/src/core/sort/topological-sort.ts +2 -2
|
@@ -4,7 +4,7 @@ import type { RlsPolicy } from "../rls-policy.model.ts";
|
|
|
4
4
|
abstract class BaseRlsPolicyChange extends BaseChange {
|
|
5
5
|
abstract readonly policy: RlsPolicy;
|
|
6
6
|
abstract readonly scope: "object" | "comment";
|
|
7
|
-
readonly objectType
|
|
7
|
+
readonly objectType = "rls_policy" as const;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export abstract class CreateRlsPolicyChange extends BaseRlsPolicyChange {
|
|
@@ -9,7 +9,7 @@ abstract class BaseRoleChange extends BaseChange {
|
|
|
9
9
|
| "membership"
|
|
10
10
|
| "default_privilege"
|
|
11
11
|
| "security_label";
|
|
12
|
-
readonly objectType
|
|
12
|
+
readonly objectType = "role" as const;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export abstract class CreateRoleChange extends BaseRoleChange {
|
|
@@ -8,7 +8,7 @@ abstract class BaseSchemaChange extends BaseChange {
|
|
|
8
8
|
| "comment"
|
|
9
9
|
| "privilege"
|
|
10
10
|
| "security_label";
|
|
11
|
-
readonly objectType
|
|
11
|
+
readonly objectType = "schema" as const;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export abstract class CreateSchemaChange extends BaseSchemaChange {
|
|
@@ -8,7 +8,7 @@ abstract class BaseSequenceChange extends BaseChange {
|
|
|
8
8
|
| "comment"
|
|
9
9
|
| "privilege"
|
|
10
10
|
| "security_label";
|
|
11
|
-
readonly objectType
|
|
11
|
+
readonly objectType = "sequence" as const;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export abstract class CreateSequenceChange extends BaseSequenceChange {
|
|
@@ -8,7 +8,7 @@ abstract class BaseTableChange extends BaseChange {
|
|
|
8
8
|
| "comment"
|
|
9
9
|
| "privilege"
|
|
10
10
|
| "security_label";
|
|
11
|
-
readonly objectType
|
|
11
|
+
readonly objectType = "table" as const;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export abstract class CreateTableChange extends BaseTableChange {
|
|
@@ -179,10 +179,7 @@ export class CreateCommentOnConstraint extends CreateTableChange {
|
|
|
179
179
|
public readonly constraint: TableConstraintProps;
|
|
180
180
|
public readonly scope = "comment" as const;
|
|
181
181
|
|
|
182
|
-
constructor(props: {
|
|
183
|
-
table: Table;
|
|
184
|
-
constraint: TableConstraintProps;
|
|
185
|
-
}) {
|
|
182
|
+
constructor(props: { table: Table; constraint: TableConstraintProps }) {
|
|
186
183
|
super();
|
|
187
184
|
this.table = props.table;
|
|
188
185
|
this.constraint = props.constraint;
|
|
@@ -228,10 +225,7 @@ export class DropCommentOnConstraint extends DropTableChange {
|
|
|
228
225
|
public readonly constraint: TableConstraintProps;
|
|
229
226
|
public readonly scope = "comment" as const;
|
|
230
227
|
|
|
231
|
-
constructor(props: {
|
|
232
|
-
table: Table;
|
|
233
|
-
constraint: TableConstraintProps;
|
|
234
|
-
}) {
|
|
228
|
+
constructor(props: { table: Table; constraint: TableConstraintProps }) {
|
|
235
229
|
super();
|
|
236
230
|
this.table = props.table;
|
|
237
231
|
this.constraint = props.constraint;
|
|
@@ -75,7 +75,7 @@ describe.concurrent("table.diff", () => {
|
|
|
75
75
|
expect(dropped[0]).toBeInstanceOf(DropTable);
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
test("created NOT VALID CHECK emits AddConstraint
|
|
78
|
+
test("created NOT VALID CHECK emits AddConstraint only (no Validate)", () => {
|
|
79
79
|
const main = new Table({
|
|
80
80
|
...base,
|
|
81
81
|
name: "t_nv",
|
|
@@ -102,6 +102,7 @@ describe.concurrent("table.diff", () => {
|
|
|
102
102
|
constraints: [],
|
|
103
103
|
});
|
|
104
104
|
const branch = new Table({
|
|
105
|
+
// oxlint-disable-next-line typescript/no-misused-spread
|
|
105
106
|
...main,
|
|
106
107
|
constraints: [
|
|
107
108
|
{
|
|
@@ -132,20 +133,208 @@ describe.concurrent("table.diff", () => {
|
|
|
132
133
|
match_type: null,
|
|
133
134
|
check_expression: "a > 0",
|
|
134
135
|
owner: "o1",
|
|
136
|
+
definition: "CHECK (a > 0) NOT VALID",
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
});
|
|
140
|
+
const changes = diffTables(
|
|
141
|
+
testContext,
|
|
142
|
+
{ [main.stableId]: main },
|
|
143
|
+
{ [branch.stableId]: branch },
|
|
144
|
+
);
|
|
145
|
+
const add = changes.find((c) => c instanceof AlterTableAddConstraint);
|
|
146
|
+
expect(add).toBeInstanceOf(AlterTableAddConstraint);
|
|
147
|
+
expect(add?.serialize()).toContain("NOT VALID");
|
|
148
|
+
expect(changes.some((c) => c instanceof AlterTableValidateConstraint)).toBe(
|
|
149
|
+
false,
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("NOT VALID -> validated emits only VALIDATE CONSTRAINT (no drop+add)", () => {
|
|
154
|
+
const sharedConstraint = {
|
|
155
|
+
name: "ck_nv",
|
|
156
|
+
constraint_type: "c" as const,
|
|
157
|
+
deferrable: false,
|
|
158
|
+
initially_deferred: false,
|
|
159
|
+
is_local: true,
|
|
160
|
+
no_inherit: false,
|
|
161
|
+
is_temporal: false,
|
|
162
|
+
is_partition_clone: false,
|
|
163
|
+
parent_constraint_schema: null,
|
|
164
|
+
parent_constraint_name: null,
|
|
165
|
+
parent_table_schema: null,
|
|
166
|
+
parent_table_name: null,
|
|
167
|
+
key_columns: [],
|
|
168
|
+
foreign_key_columns: null,
|
|
169
|
+
foreign_key_table: null,
|
|
170
|
+
foreign_key_schema: null,
|
|
171
|
+
foreign_key_table_is_partition: null,
|
|
172
|
+
foreign_key_parent_schema: null,
|
|
173
|
+
foreign_key_parent_table: null,
|
|
174
|
+
foreign_key_effective_schema: null,
|
|
175
|
+
foreign_key_effective_table: null,
|
|
176
|
+
on_update: null,
|
|
177
|
+
on_delete: null,
|
|
178
|
+
match_type: null,
|
|
179
|
+
check_expression: "a > 0",
|
|
180
|
+
owner: "o1",
|
|
181
|
+
comment: null,
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const main = new Table({
|
|
185
|
+
...base,
|
|
186
|
+
name: "t_nv",
|
|
187
|
+
columns: [
|
|
188
|
+
{
|
|
189
|
+
name: "a",
|
|
190
|
+
position: 1,
|
|
191
|
+
data_type: "integer",
|
|
192
|
+
data_type_str: "integer",
|
|
193
|
+
is_custom_type: false,
|
|
194
|
+
custom_type_type: null,
|
|
195
|
+
custom_type_category: null,
|
|
196
|
+
custom_type_schema: null,
|
|
197
|
+
custom_type_name: null,
|
|
198
|
+
not_null: false,
|
|
199
|
+
is_identity: false,
|
|
200
|
+
is_identity_always: false,
|
|
201
|
+
is_generated: false,
|
|
202
|
+
collation: null,
|
|
203
|
+
default: null,
|
|
204
|
+
comment: null,
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
constraints: [
|
|
208
|
+
{
|
|
209
|
+
...sharedConstraint,
|
|
210
|
+
validated: false,
|
|
211
|
+
definition: "CHECK (a > 0) NOT VALID",
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
});
|
|
215
|
+
const branch = new Table({
|
|
216
|
+
// oxlint-disable-next-line typescript/no-misused-spread
|
|
217
|
+
...main,
|
|
218
|
+
constraints: [
|
|
219
|
+
{
|
|
220
|
+
...sharedConstraint,
|
|
221
|
+
validated: true,
|
|
135
222
|
definition: "CHECK (a > 0)",
|
|
136
223
|
},
|
|
137
224
|
],
|
|
138
225
|
});
|
|
226
|
+
|
|
227
|
+
const changes = diffTables(
|
|
228
|
+
testContext,
|
|
229
|
+
{ [main.stableId]: main },
|
|
230
|
+
{ [branch.stableId]: branch },
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
const validate = changes.find(
|
|
234
|
+
(c) => c instanceof AlterTableValidateConstraint,
|
|
235
|
+
);
|
|
236
|
+
expect(validate).toBeInstanceOf(AlterTableValidateConstraint);
|
|
237
|
+
expect(validate?.serialize()).toMatchInlineSnapshot(
|
|
238
|
+
`"ALTER TABLE public.t_nv VALIDATE CONSTRAINT ck_nv"`,
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
expect(changes.some((c) => c instanceof AlterTableDropConstraint)).toBe(
|
|
242
|
+
false,
|
|
243
|
+
);
|
|
244
|
+
expect(changes.some((c) => c instanceof AlterTableAddConstraint)).toBe(
|
|
245
|
+
false,
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test("NOT VALID -> validated + other field change still drops+adds (no shortcut)", () => {
|
|
250
|
+
const sharedConstraint = {
|
|
251
|
+
name: "ck_nv",
|
|
252
|
+
constraint_type: "c" as const,
|
|
253
|
+
deferrable: false,
|
|
254
|
+
initially_deferred: false,
|
|
255
|
+
is_local: true,
|
|
256
|
+
no_inherit: false,
|
|
257
|
+
is_temporal: false,
|
|
258
|
+
is_partition_clone: false,
|
|
259
|
+
parent_constraint_schema: null,
|
|
260
|
+
parent_constraint_name: null,
|
|
261
|
+
parent_table_schema: null,
|
|
262
|
+
parent_table_name: null,
|
|
263
|
+
key_columns: [],
|
|
264
|
+
foreign_key_columns: null,
|
|
265
|
+
foreign_key_table: null,
|
|
266
|
+
foreign_key_schema: null,
|
|
267
|
+
foreign_key_table_is_partition: null,
|
|
268
|
+
foreign_key_parent_schema: null,
|
|
269
|
+
foreign_key_parent_table: null,
|
|
270
|
+
foreign_key_effective_schema: null,
|
|
271
|
+
foreign_key_effective_table: null,
|
|
272
|
+
on_update: null,
|
|
273
|
+
on_delete: null,
|
|
274
|
+
match_type: null,
|
|
275
|
+
owner: "o1",
|
|
276
|
+
comment: null,
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const main = new Table({
|
|
280
|
+
...base,
|
|
281
|
+
name: "t_nv",
|
|
282
|
+
columns: [
|
|
283
|
+
{
|
|
284
|
+
name: "a",
|
|
285
|
+
position: 1,
|
|
286
|
+
data_type: "integer",
|
|
287
|
+
data_type_str: "integer",
|
|
288
|
+
is_custom_type: false,
|
|
289
|
+
custom_type_type: null,
|
|
290
|
+
custom_type_category: null,
|
|
291
|
+
custom_type_schema: null,
|
|
292
|
+
custom_type_name: null,
|
|
293
|
+
not_null: false,
|
|
294
|
+
is_identity: false,
|
|
295
|
+
is_identity_always: false,
|
|
296
|
+
is_generated: false,
|
|
297
|
+
collation: null,
|
|
298
|
+
default: null,
|
|
299
|
+
comment: null,
|
|
300
|
+
},
|
|
301
|
+
],
|
|
302
|
+
constraints: [
|
|
303
|
+
{
|
|
304
|
+
...sharedConstraint,
|
|
305
|
+
validated: false,
|
|
306
|
+
check_expression: "a > 0",
|
|
307
|
+
definition: "CHECK (a > 0) NOT VALID",
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
});
|
|
311
|
+
const branch = new Table({
|
|
312
|
+
// oxlint-disable-next-line typescript/no-misused-spread
|
|
313
|
+
...main,
|
|
314
|
+
constraints: [
|
|
315
|
+
{
|
|
316
|
+
...sharedConstraint,
|
|
317
|
+
validated: true,
|
|
318
|
+
check_expression: "a > 1",
|
|
319
|
+
definition: "CHECK (a > 1)",
|
|
320
|
+
},
|
|
321
|
+
],
|
|
322
|
+
});
|
|
323
|
+
|
|
139
324
|
const changes = diffTables(
|
|
140
325
|
testContext,
|
|
141
326
|
{ [main.stableId]: main },
|
|
142
327
|
{ [branch.stableId]: branch },
|
|
143
328
|
);
|
|
329
|
+
|
|
330
|
+
expect(changes.some((c) => c instanceof AlterTableDropConstraint)).toBe(
|
|
331
|
+
true,
|
|
332
|
+
);
|
|
144
333
|
expect(changes.some((c) => c instanceof AlterTableAddConstraint)).toBe(
|
|
145
334
|
true,
|
|
146
335
|
);
|
|
147
336
|
expect(changes.some((c) => c instanceof AlterTableValidateConstraint)).toBe(
|
|
148
|
-
|
|
337
|
+
false,
|
|
149
338
|
);
|
|
150
339
|
});
|
|
151
340
|
|
|
@@ -362,7 +551,7 @@ describe.concurrent("table.diff", () => {
|
|
|
362
551
|
true,
|
|
363
552
|
);
|
|
364
553
|
expect(created.some((c) => c instanceof AlterTableValidateConstraint)).toBe(
|
|
365
|
-
|
|
554
|
+
false,
|
|
366
555
|
);
|
|
367
556
|
|
|
368
557
|
const dropped = diffTables(
|
|
@@ -480,6 +669,7 @@ describe.concurrent("table.diff", () => {
|
|
|
480
669
|
],
|
|
481
670
|
});
|
|
482
671
|
const tBranch = new Table({
|
|
672
|
+
// oxlint-disable-next-line typescript/no-misused-spread
|
|
483
673
|
...tMain,
|
|
484
674
|
constraints: [
|
|
485
675
|
{
|
|
@@ -501,7 +691,7 @@ describe.concurrent("table.diff", () => {
|
|
|
501
691
|
);
|
|
502
692
|
});
|
|
503
693
|
|
|
504
|
-
test("altered foreign key
|
|
694
|
+
test("altered foreign key to NOT VALID triggers drop+add without validate", () => {
|
|
505
695
|
const tMain = new Table({
|
|
506
696
|
...base,
|
|
507
697
|
name: "t_fk",
|
|
@@ -559,12 +749,14 @@ describe.concurrent("table.diff", () => {
|
|
|
559
749
|
],
|
|
560
750
|
});
|
|
561
751
|
const tBranch = new Table({
|
|
752
|
+
// oxlint-disable-next-line typescript/no-misused-spread
|
|
562
753
|
...tMain,
|
|
563
754
|
constraints: [
|
|
564
755
|
{
|
|
565
756
|
...(tMain.constraints[0] as (typeof tMain.constraints)[number]),
|
|
566
757
|
on_delete: "c",
|
|
567
758
|
validated: false,
|
|
759
|
+
definition: "FOREIGN KEY (a) REFERENCES other(a) NOT VALID",
|
|
568
760
|
},
|
|
569
761
|
],
|
|
570
762
|
});
|
|
@@ -606,7 +798,7 @@ describe.concurrent("table.diff", () => {
|
|
|
606
798
|
true,
|
|
607
799
|
);
|
|
608
800
|
expect(changes.some((c) => c instanceof AlterTableValidateConstraint)).toBe(
|
|
609
|
-
|
|
801
|
+
false,
|
|
610
802
|
);
|
|
611
803
|
});
|
|
612
804
|
|
|
@@ -686,6 +878,7 @@ describe.concurrent("table.diff", () => {
|
|
|
686
878
|
],
|
|
687
879
|
});
|
|
688
880
|
const tBranch = new Table({
|
|
881
|
+
// oxlint-disable-next-line typescript/no-misused-spread
|
|
689
882
|
...tMain,
|
|
690
883
|
constraints: [
|
|
691
884
|
{
|
|
@@ -86,14 +86,6 @@ function createAlterConstraintChange(mainTable: Table, branchTable: Table) {
|
|
|
86
86
|
constraint: c,
|
|
87
87
|
}),
|
|
88
88
|
);
|
|
89
|
-
if (!c.validated) {
|
|
90
|
-
changes.push(
|
|
91
|
-
new AlterTableValidateConstraint({
|
|
92
|
-
table: branchTable,
|
|
93
|
-
constraint: c,
|
|
94
|
-
}),
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
89
|
// Add comment for newly created constraint
|
|
98
90
|
if (c.comment !== null) {
|
|
99
91
|
changes.push(
|
|
@@ -120,7 +112,7 @@ function createAlterConstraintChange(mainTable: Table, branchTable: Table) {
|
|
|
120
112
|
}
|
|
121
113
|
}
|
|
122
114
|
|
|
123
|
-
// Altered constraints -> drop + add
|
|
115
|
+
// Altered constraints -> drop + add (or VALIDATE-only shortcut)
|
|
124
116
|
for (const [name, mainC] of mainByName) {
|
|
125
117
|
const branchC = branchByName.get(name);
|
|
126
118
|
if (!branchC) continue;
|
|
@@ -130,24 +122,68 @@ function createAlterConstraintChange(mainTable: Table, branchTable: Table) {
|
|
|
130
122
|
continue;
|
|
131
123
|
}
|
|
132
124
|
|
|
125
|
+
// Cheap scalar `===` checks first; only fall through to JSON.stringify
|
|
126
|
+
// on the array fields when every scalar has already matched.
|
|
127
|
+
const fieldsEqualExceptValidated =
|
|
128
|
+
mainC.constraint_type === branchC.constraint_type &&
|
|
129
|
+
mainC.deferrable === branchC.deferrable &&
|
|
130
|
+
mainC.initially_deferred === branchC.initially_deferred &&
|
|
131
|
+
mainC.is_local === branchC.is_local &&
|
|
132
|
+
mainC.no_inherit === branchC.no_inherit &&
|
|
133
|
+
mainC.is_temporal === branchC.is_temporal &&
|
|
134
|
+
mainC.foreign_key_table === branchC.foreign_key_table &&
|
|
135
|
+
mainC.foreign_key_schema === branchC.foreign_key_schema &&
|
|
136
|
+
mainC.on_update === branchC.on_update &&
|
|
137
|
+
mainC.on_delete === branchC.on_delete &&
|
|
138
|
+
mainC.match_type === branchC.match_type &&
|
|
139
|
+
mainC.check_expression === branchC.check_expression &&
|
|
140
|
+
JSON.stringify(mainC.key_columns) ===
|
|
141
|
+
JSON.stringify(branchC.key_columns) &&
|
|
142
|
+
JSON.stringify(mainC.foreign_key_columns) ===
|
|
143
|
+
JSON.stringify(branchC.foreign_key_columns);
|
|
144
|
+
|
|
145
|
+
// Safe-migration shortcut: when the only difference is `validated`
|
|
146
|
+
// flipping from false to true, emit a single `ALTER TABLE ... VALIDATE
|
|
147
|
+
// CONSTRAINT` instead of drop+add. VALIDATE CONSTRAINT only takes
|
|
148
|
+
// SHARE UPDATE EXCLUSIVE (concurrent reads/writes proceed), whereas
|
|
149
|
+
// dropping and re-adding takes ACCESS EXCLUSIVE for the entire scan.
|
|
150
|
+
// Postgres has no reverse command, so `true -> false` must still go
|
|
151
|
+
// through drop+add below.
|
|
152
|
+
if (
|
|
153
|
+
fieldsEqualExceptValidated &&
|
|
154
|
+
mainC.validated === false &&
|
|
155
|
+
branchC.validated === true
|
|
156
|
+
) {
|
|
157
|
+
changes.push(
|
|
158
|
+
new AlterTableValidateConstraint({
|
|
159
|
+
table: branchTable,
|
|
160
|
+
constraint: branchC,
|
|
161
|
+
}),
|
|
162
|
+
);
|
|
163
|
+
// VALIDATE preserves the constraint OID, so its comment is preserved
|
|
164
|
+
// too. Only emit a comment change if it actually differs.
|
|
165
|
+
if (mainC.comment !== branchC.comment) {
|
|
166
|
+
if (branchC.comment === null) {
|
|
167
|
+
changes.push(
|
|
168
|
+
new DropCommentOnConstraint({
|
|
169
|
+
table: mainTable,
|
|
170
|
+
constraint: mainC,
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
173
|
+
} else {
|
|
174
|
+
changes.push(
|
|
175
|
+
new CreateCommentOnConstraint({
|
|
176
|
+
table: branchTable,
|
|
177
|
+
constraint: branchC,
|
|
178
|
+
}),
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
|
|
133
185
|
const changed =
|
|
134
|
-
mainC.
|
|
135
|
-
mainC.deferrable !== branchC.deferrable ||
|
|
136
|
-
mainC.initially_deferred !== branchC.initially_deferred ||
|
|
137
|
-
mainC.validated !== branchC.validated ||
|
|
138
|
-
mainC.is_local !== branchC.is_local ||
|
|
139
|
-
mainC.no_inherit !== branchC.no_inherit ||
|
|
140
|
-
mainC.is_temporal !== branchC.is_temporal ||
|
|
141
|
-
JSON.stringify(mainC.key_columns) !==
|
|
142
|
-
JSON.stringify(branchC.key_columns) ||
|
|
143
|
-
JSON.stringify(mainC.foreign_key_columns) !==
|
|
144
|
-
JSON.stringify(branchC.foreign_key_columns) ||
|
|
145
|
-
mainC.foreign_key_table !== branchC.foreign_key_table ||
|
|
146
|
-
mainC.foreign_key_schema !== branchC.foreign_key_schema ||
|
|
147
|
-
mainC.on_update !== branchC.on_update ||
|
|
148
|
-
mainC.on_delete !== branchC.on_delete ||
|
|
149
|
-
mainC.match_type !== branchC.match_type ||
|
|
150
|
-
mainC.check_expression !== branchC.check_expression;
|
|
186
|
+
mainC.validated !== branchC.validated || !fieldsEqualExceptValidated;
|
|
151
187
|
if (changed) {
|
|
152
188
|
changes.push(
|
|
153
189
|
new AlterTableDropConstraint({
|
|
@@ -161,14 +197,6 @@ function createAlterConstraintChange(mainTable: Table, branchTable: Table) {
|
|
|
161
197
|
constraint: branchC,
|
|
162
198
|
}),
|
|
163
199
|
);
|
|
164
|
-
if (!branchC.validated) {
|
|
165
|
-
changes.push(
|
|
166
|
-
new AlterTableValidateConstraint({
|
|
167
|
-
table: branchTable,
|
|
168
|
-
constraint: branchC,
|
|
169
|
-
}),
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
200
|
// Ensure constraint comment is applied after re-creation
|
|
173
201
|
if (branchC.comment !== null) {
|
|
174
202
|
changes.push(
|
|
@@ -265,6 +293,7 @@ export function diffTables(
|
|
|
265
293
|
...createAlterConstraintChange(
|
|
266
294
|
// Create a dummy table with no constraints do diff constraints against
|
|
267
295
|
new Table({
|
|
296
|
+
// oxlint-disable-next-line typescript/no-misused-spread
|
|
268
297
|
...branchTable,
|
|
269
298
|
constraints: [],
|
|
270
299
|
}),
|
|
@@ -28,10 +28,7 @@ export class ReplaceTrigger extends AlterTriggerChange {
|
|
|
28
28
|
public readonly indexableObject?: TableLikeObject;
|
|
29
29
|
public readonly scope = "object" as const;
|
|
30
30
|
|
|
31
|
-
constructor(props: {
|
|
32
|
-
trigger: Trigger;
|
|
33
|
-
indexableObject?: TableLikeObject;
|
|
34
|
-
}) {
|
|
31
|
+
constructor(props: { trigger: Trigger; indexableObject?: TableLikeObject }) {
|
|
35
32
|
super();
|
|
36
33
|
this.trigger = props.trigger;
|
|
37
34
|
this.indexableObject = props.indexableObject;
|
|
@@ -4,7 +4,7 @@ import type { Trigger } from "../trigger.model.ts";
|
|
|
4
4
|
abstract class BaseTriggerChange extends BaseChange {
|
|
5
5
|
abstract readonly trigger: Trigger;
|
|
6
6
|
abstract readonly scope: "object" | "comment";
|
|
7
|
-
readonly objectType
|
|
7
|
+
readonly objectType = "trigger" as const;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export abstract class CreateTriggerChange extends BaseTriggerChange {
|
|
@@ -8,7 +8,7 @@ abstract class BaseCompositeTypeChange extends BaseChange {
|
|
|
8
8
|
| "comment"
|
|
9
9
|
| "privilege"
|
|
10
10
|
| "security_label";
|
|
11
|
-
readonly objectType
|
|
11
|
+
readonly objectType = "composite_type" as const;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export abstract class CreateCompositeTypeChange extends BaseCompositeTypeChange {
|
|
@@ -8,7 +8,7 @@ abstract class BaseRangeChange extends BaseChange {
|
|
|
8
8
|
| "comment"
|
|
9
9
|
| "privilege"
|
|
10
10
|
| "security_label";
|
|
11
|
-
readonly objectType
|
|
11
|
+
readonly objectType = "range" as const;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export abstract class CreateRangeChange extends BaseRangeChange {
|
|
@@ -322,7 +322,7 @@ function addClusterChange(cluster: ClusterGroup, change: Change): void {
|
|
|
322
322
|
break;
|
|
323
323
|
default: {
|
|
324
324
|
const _exhaustive: never = objectType;
|
|
325
|
-
throw new Error(`Unhandled object type: ${_exhaustive}`);
|
|
325
|
+
throw new Error(`Unhandled object type: ${JSON.stringify(_exhaustive)}`);
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
}
|
|
@@ -366,7 +366,7 @@ function addChildChange(schema: SchemaGroup, change: Change): void {
|
|
|
366
366
|
break;
|
|
367
367
|
default: {
|
|
368
368
|
const _exhaustive: never = parentType;
|
|
369
|
-
throw new Error(`Unhandled parent type: ${_exhaustive}`);
|
|
369
|
+
throw new Error(`Unhandled parent type: ${JSON.stringify(_exhaustive)}`);
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
372
|
|
|
@@ -416,7 +416,7 @@ function addChildChange(schema: SchemaGroup, change: Change): void {
|
|
|
416
416
|
break;
|
|
417
417
|
default: {
|
|
418
418
|
const _exhaustive: never = objectType;
|
|
419
|
-
throw new Error(`Unhandled object type: ${_exhaustive}`);
|
|
419
|
+
throw new Error(`Unhandled object type: ${JSON.stringify(_exhaustive)}`);
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
422
|
}
|
|
@@ -568,7 +568,7 @@ function addSchemaLevelChange(
|
|
|
568
568
|
break;
|
|
569
569
|
default: {
|
|
570
570
|
const _exhaustive: never = objectType;
|
|
571
|
-
throw new Error(`Unhandled object type: ${_exhaustive}`);
|
|
571
|
+
throw new Error(`Unhandled object type: ${JSON.stringify(_exhaustive)}`);
|
|
572
572
|
}
|
|
573
573
|
}
|
|
574
574
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
1
|
+
import { describe, expect, spyOn, test } from "bun:test";
|
|
2
2
|
import {
|
|
3
3
|
connectWithRetry,
|
|
4
|
+
connectWithTimeout,
|
|
4
5
|
isRetryableConnectError,
|
|
5
6
|
poolConfigFromUrl,
|
|
6
7
|
} from "./postgres-config.ts";
|
|
@@ -241,6 +242,43 @@ describe("connectWithRetry", () => {
|
|
|
241
242
|
});
|
|
242
243
|
});
|
|
243
244
|
|
|
245
|
+
describe("connectWithTimeout", () => {
|
|
246
|
+
test("clears the timer when connect resolves before it fires", async () => {
|
|
247
|
+
const clearSpy = spyOn(globalThis, "clearTimeout");
|
|
248
|
+
try {
|
|
249
|
+
const sentinel = { client: true };
|
|
250
|
+
const result = await connectWithTimeout(
|
|
251
|
+
() => Promise.resolve(sentinel),
|
|
252
|
+
60_000,
|
|
253
|
+
"source",
|
|
254
|
+
);
|
|
255
|
+
expect(result).toBe(sentinel);
|
|
256
|
+
expect(clearSpy).toHaveBeenCalled();
|
|
257
|
+
} finally {
|
|
258
|
+
clearSpy.mockRestore();
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test("rejects with a timeout error when connect is too slow", async () => {
|
|
263
|
+
await expect(
|
|
264
|
+
connectWithTimeout(() => new Promise<never>(() => {}), 5, "target"),
|
|
265
|
+
).rejects.toThrow(/timed out after 5ms/);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test("clears the timer even when connect rejects", async () => {
|
|
269
|
+
const clearSpy = spyOn(globalThis, "clearTimeout");
|
|
270
|
+
try {
|
|
271
|
+
const boom = new Error("connect ECONNREFUSED");
|
|
272
|
+
await expect(
|
|
273
|
+
connectWithTimeout(() => Promise.reject(boom), 60_000, "target"),
|
|
274
|
+
).rejects.toBe(boom);
|
|
275
|
+
expect(clearSpy).toHaveBeenCalled();
|
|
276
|
+
} finally {
|
|
277
|
+
clearSpy.mockRestore();
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
244
282
|
describe("poolConfigFromUrl", () => {
|
|
245
283
|
describe("non-IPv6 URLs pass through as connectionString", () => {
|
|
246
284
|
test("DNS hostname", () => {
|