@proteinjs/db 1.32.0 → 1.32.2

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/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.32.2](https://github.com/proteinjs/db/compare/@proteinjs/db@1.32.1...@proteinjs/db@1.32.2) (2026-08-15)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * schema reconcile logs the concurrent-ALREADY_EXISTS tolerance loudly (WARN) ([8e95c92](https://github.com/proteinjs/db/commit/8e95c92c3757bd577048a269e28a072a2e045208))
12
+
13
+
14
+
15
+
16
+
17
+ ## [1.32.1](https://github.com/proteinjs/db/compare/@proteinjs/db@1.32.0...@proteinjs/db@1.32.1) (2026-08-15)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * schema reconcile tolerates concurrent ALREADY_EXISTS — verify-then-succeed, closes the multi-actor boot race ([ef6afa5](https://github.com/proteinjs/db/commit/ef6afa55690f6481435bc4356cf6cc301869e08f))
23
+
24
+
25
+
26
+
27
+
6
28
  # [1.32.0](https://github.com/proteinjs/db/compare/@proteinjs/db@1.31.0...@proteinjs/db@1.32.0) (2026-08-14)
7
29
 
8
30
 
@@ -8,6 +8,20 @@ export interface SchemaOperations {
8
8
  */
9
9
  createTables(tables: Table<any>[]): Promise<void>;
10
10
  alterTable(table: Table<any>, changes: TableChanges): Promise<void>;
11
+ /**
12
+ * Classify a create/alter DDL error as the backend's "already exists" class — the loser's
13
+ * outcome when two actors concurrently create the same table/index or add the same column and
14
+ * the backend serializes the DDL so the object lands exactly once. Backend-specific (each driver
15
+ * owns its error codes/messages), so it is optional: a driver that does not implement it opts out
16
+ * of {@link TableManager}'s concurrent-reconcile tolerance and keeps the strict rethrow.
17
+ *
18
+ * MUST match on error CLASS (status code + a specific message class), never a loose substring —
19
+ * it decides whether a failure is eligible for verify-then-succeed, and a genuine failure that
20
+ * slipped into this class would be masked. The tolerance is still safe because TableManager
21
+ * re-reads and confirms the intended definition before treating it as success; this predicate is
22
+ * the first gate, not the whole guard.
23
+ */
24
+ isAlreadyExistsError?(error: unknown): boolean;
11
25
  }
12
26
  interface Index {
13
27
  name?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaOperations.d.ts","sourceRoot":"","sources":["../../../src/schema/SchemaOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrE;AAED,UAAU,KAAK;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,UAAU,UAAU;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,0JAA0J;IAC1J,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,oBAAoB;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,iBAAiB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E,MAAM,CAAC;CACjB;AAED,UAAU,oBAAoB;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IACtC,qBAAqB,EAAE,oBAAoB,EAAE,CAAC;IAC9C,8BAA8B,EAAE,MAAM,EAAE,CAAC;IACzC,mBAAmB,EAAE,UAAU,EAAE,CAAC;IAClC,4BAA4B,EAAE,MAAM,EAAE,CAAC;IACvC,iBAAiB,EAAE,UAAU,EAAE,CAAC;IAChC,oCAAoC,EAAE,MAAM,EAAE,CAAC;IAC/C,kCAAkC,EAAE,MAAM,EAAE,CAAC;IAC7C,eAAe,EAAE,KAAK,EAAE,CAAC;IACzB,aAAa,EAAE,KAAK,EAAE,CAAC;CACxB"}
@@ -22,6 +22,42 @@ export declare class TableManager {
22
22
  loadTables(): Promise<void>;
23
23
  loadTable(table: Table<any>): Promise<void>;
24
24
  private alterTableIfChanged;
25
+ /**
26
+ * Reconcile a create/alter DDL failure against a concurrent schema change, closing the
27
+ * check-then-act race in loadTable/loadTables.
28
+ *
29
+ * On a schema-changing release the migration Job, booting pods, and multiple replicas all run
30
+ * Db.init -> loadTables at once. Reconcile is check-then-act (read INFORMATION_SCHEMA -> decide
31
+ * create/alter -> apply DDL): two actors can both observe the same column/table as absent and
32
+ * both issue the CREATE/ALTER. The backend serializes DDL so the object lands EXACTLY once, but
33
+ * the loser's operation fails with an already-exists / duplicate-name error. Before this
34
+ * reconcile that error propagated out of Db.init — a booting pod with no unhandledRejection
35
+ * handler exited (CrashLoopBackOff) and the migration Job exited 1 (a spurious migration-gate
36
+ * failure).
37
+ *
38
+ * This is NOT a blanket swallow (that would mask real schema failures). Two independent gates
39
+ * must BOTH pass before a failure is treated as success:
40
+ * 1. CLASS — the driver's schema layer, which owns the backend's error codes/messages, must
41
+ * classify the error as the already-exists class ({@link SchemaOperations.isAlreadyExistsError}).
42
+ * A driver that does not implement the classifier always rethrows here.
43
+ * 2. INTENDED DEFINITION — a re-read of the live schema (the same metadata-backed detection
44
+ * getTableChanges uses) must confirm every table now exists AND has no remaining changes of
45
+ * the kind we attempted. A concurrent actor applying our EXACT change satisfies this; a
46
+ * genuine conflict (e.g. the column landed with a different type, so a column-type change is
47
+ * still outstanding) does not.
48
+ * If either gate fails, the ORIGINAL error propagates unchanged. Because every actor runs this
49
+ * same reconcile, it closes all three windows: migration-Job-vs-pod, pod-vs-pod, and
50
+ * multi-replica boot.
51
+ *
52
+ * OBSERVABILITY: this path is reached ONLY from the create/alter catch (the no-error happy path
53
+ * never calls it). Every outcome that reaches the intended-definition gate is logged LOUDLY at
54
+ * WARN — tolerance fired (treated as applied) OR the re-read failed (genuine conflict / still
55
+ * absent, re-throwing) — so an unexpected activation is visible in prod logs rather than silent.
56
+ */
57
+ private reconcileConcurrentSchemaChange;
58
+ /** Concise, loggable reason from a schema-update error: the backend names the offending object
59
+ * in `details` (validation phase) or `message` (apply phase). */
60
+ private schemaErrorReason;
25
61
  private validateDynamicReferenceColumns;
26
62
  private shouldAlterTable;
27
63
  private getTableChanges;
@@ -1 +1 @@
1
- {"version":3,"file":"TableManager.d.ts","sourceRoot":"","sources":["../../../src/schema/TableManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAa,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAgB,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAMjC,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,MAAM,C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AgB,EAClC,cAAc,CAAC,EAAE,cAAc;IAO3B,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC;IAInC;;;;;;OAMG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA4B3B,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YAgBnC,mBAAmB;IAajC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;YACW,+BAA+B;IAmC7C;sEACkE;IAClE,OAAO,CAAC,iBAAiB;IAKzB,OAAO,CAAC,+BAA+B;IAwDvC,OAAO,CAAC,gBAAgB;YAgBV,eAAe;YA6Ff,kBAAkB;CA8CjC"}
@@ -69,7 +69,7 @@ var TableManager = /** @class */ (function () {
69
69
  */
70
70
  TableManager.prototype.loadTables = function () {
71
71
  return __awaiter(this, void 0, void 0, function () {
72
- var tables, absentTables, existingTables, _i, tables_1, table, _a, existingTables_1, table;
72
+ var tables, absentTables, existingTables, _i, tables_1, table, error_1, _a, existingTables_1, table;
73
73
  return __generator(this, function (_b) {
74
74
  switch (_b.label) {
75
75
  case 0:
@@ -95,33 +95,45 @@ var TableManager = /** @class */ (function () {
95
95
  _i++;
96
96
  return [3 /*break*/, 1];
97
97
  case 4:
98
- if (!(absentTables.length > 0)) return [3 /*break*/, 6];
98
+ if (!(absentTables.length > 0)) return [3 /*break*/, 10];
99
99
  this.logger.info({ message: "Creating tables: ".concat(absentTables.map(function (table) { return table.name; }).join(', ')) });
100
- return [4 /*yield*/, this.schemaOperations.createTables(absentTables)];
100
+ _b.label = 5;
101
101
  case 5:
102
+ _b.trys.push([5, 7, , 9]);
103
+ return [4 /*yield*/, this.schemaOperations.createTables(absentTables)];
104
+ case 6:
105
+ _b.sent();
106
+ return [3 /*break*/, 9];
107
+ case 7:
108
+ error_1 = _b.sent();
109
+ return [4 /*yield*/, this.reconcileConcurrentSchemaChange(absentTables, error_1)];
110
+ case 8:
102
111
  _b.sent();
112
+ return [3 /*break*/, 9];
113
+ case 9:
103
114
  this.logger.info({ message: "Finished creating ".concat(absentTables.length, " tables") });
104
- _b.label = 6;
105
- case 6:
115
+ _b.label = 10;
116
+ case 10:
106
117
  _a = 0, existingTables_1 = existingTables;
107
- _b.label = 7;
108
- case 7:
109
- if (!(_a < existingTables_1.length)) return [3 /*break*/, 10];
118
+ _b.label = 11;
119
+ case 11:
120
+ if (!(_a < existingTables_1.length)) return [3 /*break*/, 14];
110
121
  table = existingTables_1[_a];
111
122
  return [4 /*yield*/, this.alterTableIfChanged(table)];
112
- case 8:
123
+ case 12:
113
124
  _b.sent();
114
- _b.label = 9;
115
- case 9:
125
+ _b.label = 13;
126
+ case 13:
116
127
  _a++;
117
- return [3 /*break*/, 7];
118
- case 10: return [2 /*return*/];
128
+ return [3 /*break*/, 11];
129
+ case 14: return [2 /*return*/];
119
130
  }
120
131
  });
121
132
  });
122
133
  };
123
134
  TableManager.prototype.loadTable = function (table) {
124
135
  return __awaiter(this, void 0, void 0, function () {
136
+ var error_2;
125
137
  return __generator(this, function (_a) {
126
138
  switch (_a.label) {
127
139
  case 0:
@@ -132,39 +144,152 @@ var TableManager = /** @class */ (function () {
132
144
  return [4 /*yield*/, this.alterTableIfChanged(table)];
133
145
  case 2:
134
146
  _a.sent();
135
- return [3 /*break*/, 5];
147
+ return [3 /*break*/, 9];
136
148
  case 3:
137
149
  this.logger.info({ message: "Creating table: ".concat(table.name) });
138
- return [4 /*yield*/, this.schemaOperations.createTables([table])];
150
+ _a.label = 4;
139
151
  case 4:
152
+ _a.trys.push([4, 6, , 8]);
153
+ return [4 /*yield*/, this.schemaOperations.createTables([table])];
154
+ case 5:
155
+ _a.sent();
156
+ return [3 /*break*/, 8];
157
+ case 6:
158
+ error_2 = _a.sent();
159
+ return [4 /*yield*/, this.reconcileConcurrentSchemaChange([table], error_2)];
160
+ case 7:
140
161
  _a.sent();
162
+ return [3 /*break*/, 8];
163
+ case 8:
141
164
  this.logger.info({ message: "Finished creating table: ".concat(table.name) });
142
- _a.label = 5;
143
- case 5: return [2 /*return*/];
165
+ _a.label = 9;
166
+ case 9: return [2 /*return*/];
144
167
  }
145
168
  });
146
169
  });
147
170
  };
148
171
  TableManager.prototype.alterTableIfChanged = function (table) {
149
172
  return __awaiter(this, void 0, void 0, function () {
150
- var tableChanges;
173
+ var tableChanges, error_3;
151
174
  return __generator(this, function (_a) {
152
175
  switch (_a.label) {
153
176
  case 0: return [4 /*yield*/, this.getTableChanges(table)];
154
177
  case 1:
155
178
  tableChanges = _a.sent();
156
- if (!this.shouldAlterTable(tableChanges)) return [3 /*break*/, 3];
179
+ if (!this.shouldAlterTable(tableChanges)) return [3 /*break*/, 7];
157
180
  this.logger.info({ message: "Altering table: ".concat(table.name) });
158
- return [4 /*yield*/, this.schemaOperations.alterTable(table, tableChanges)];
181
+ _a.label = 2;
159
182
  case 2:
183
+ _a.trys.push([2, 4, , 6]);
184
+ return [4 /*yield*/, this.schemaOperations.alterTable(table, tableChanges)];
185
+ case 3:
160
186
  _a.sent();
187
+ return [3 /*break*/, 6];
188
+ case 4:
189
+ error_3 = _a.sent();
190
+ return [4 /*yield*/, this.reconcileConcurrentSchemaChange([table], error_3)];
191
+ case 5:
192
+ _a.sent();
193
+ return [3 /*break*/, 6];
194
+ case 6:
161
195
  this.logger.info({ message: "Finished altering table: ".concat(table.name) });
162
- _a.label = 3;
163
- case 3: return [2 /*return*/];
196
+ _a.label = 7;
197
+ case 7: return [2 /*return*/];
198
+ }
199
+ });
200
+ });
201
+ };
202
+ /**
203
+ * Reconcile a create/alter DDL failure against a concurrent schema change, closing the
204
+ * check-then-act race in loadTable/loadTables.
205
+ *
206
+ * On a schema-changing release the migration Job, booting pods, and multiple replicas all run
207
+ * Db.init -> loadTables at once. Reconcile is check-then-act (read INFORMATION_SCHEMA -> decide
208
+ * create/alter -> apply DDL): two actors can both observe the same column/table as absent and
209
+ * both issue the CREATE/ALTER. The backend serializes DDL so the object lands EXACTLY once, but
210
+ * the loser's operation fails with an already-exists / duplicate-name error. Before this
211
+ * reconcile that error propagated out of Db.init — a booting pod with no unhandledRejection
212
+ * handler exited (CrashLoopBackOff) and the migration Job exited 1 (a spurious migration-gate
213
+ * failure).
214
+ *
215
+ * This is NOT a blanket swallow (that would mask real schema failures). Two independent gates
216
+ * must BOTH pass before a failure is treated as success:
217
+ * 1. CLASS — the driver's schema layer, which owns the backend's error codes/messages, must
218
+ * classify the error as the already-exists class ({@link SchemaOperations.isAlreadyExistsError}).
219
+ * A driver that does not implement the classifier always rethrows here.
220
+ * 2. INTENDED DEFINITION — a re-read of the live schema (the same metadata-backed detection
221
+ * getTableChanges uses) must confirm every table now exists AND has no remaining changes of
222
+ * the kind we attempted. A concurrent actor applying our EXACT change satisfies this; a
223
+ * genuine conflict (e.g. the column landed with a different type, so a column-type change is
224
+ * still outstanding) does not.
225
+ * If either gate fails, the ORIGINAL error propagates unchanged. Because every actor runs this
226
+ * same reconcile, it closes all three windows: migration-Job-vs-pod, pod-vs-pod, and
227
+ * multi-replica boot.
228
+ *
229
+ * OBSERVABILITY: this path is reached ONLY from the create/alter catch (the no-error happy path
230
+ * never calls it). Every outcome that reaches the intended-definition gate is logged LOUDLY at
231
+ * WARN — tolerance fired (treated as applied) OR the re-read failed (genuine conflict / still
232
+ * absent, re-throwing) — so an unexpected activation is visible in prod logs rather than silent.
233
+ */
234
+ TableManager.prototype.reconcileConcurrentSchemaChange = function (tables, error) {
235
+ var _a, _b;
236
+ return __awaiter(this, void 0, void 0, function () {
237
+ var tableNames, reason, _i, tables_2, table, remainingChanges;
238
+ return __generator(this, function (_c) {
239
+ switch (_c.label) {
240
+ case 0:
241
+ if (!((_b = (_a = this.schemaOperations).isAlreadyExistsError) === null || _b === void 0 ? void 0 : _b.call(_a, error))) {
242
+ throw error;
243
+ }
244
+ tableNames = tables.map(function (table) { return table.name; }).join(', ');
245
+ reason = this.schemaErrorReason(error);
246
+ _i = 0, tables_2 = tables;
247
+ _c.label = 1;
248
+ case 1:
249
+ if (!(_i < tables_2.length)) return [3 /*break*/, 5];
250
+ table = tables_2[_i];
251
+ return [4 /*yield*/, this.tableExists(table)];
252
+ case 2:
253
+ // A create that failed already-exists yet leaves the table absent is not the
254
+ // concurrent-winner case — surface the original error rather than masking it.
255
+ if (!(_c.sent())) {
256
+ this.logger.warn({
257
+ message: "[schema reconcile] caught ALREADY_EXISTS for table(s) '".concat(tableNames, "' but '").concat(table.name, "' is still absent on re-read \u2014 NOT a concurrent apply; re-throwing. reason: ").concat(reason),
258
+ });
259
+ throw error;
260
+ }
261
+ return [4 /*yield*/, this.getTableChanges(table)];
262
+ case 3:
263
+ remainingChanges = _c.sent();
264
+ if (this.shouldAlterTable(remainingChanges)) {
265
+ // The object exists but the live schema still differs from the intended definition, so a
266
+ // concurrent actor did NOT apply our exact change (a genuine conflict). Propagate.
267
+ this.logger.warn({
268
+ message: "[schema reconcile] caught ALREADY_EXISTS for table '".concat(table.name, "' but the live schema does NOT match the intended definition on re-read (genuine conflict) \u2014 re-throwing. reason: ").concat(reason),
269
+ obj: { remainingChanges: remainingChanges },
270
+ });
271
+ throw error;
272
+ }
273
+ _c.label = 4;
274
+ case 4:
275
+ _i++;
276
+ return [3 /*break*/, 1];
277
+ case 5:
278
+ this.logger.warn({
279
+ message: "[schema reconcile] tolerated concurrent ALREADY_EXISTS for table(s) '".concat(tableNames, "' \u2014 re-read verified the object present with the intended definition, treating as applied (a concurrent actor won the race). reason: ").concat(reason),
280
+ });
281
+ return [2 /*return*/];
164
282
  }
165
283
  });
166
284
  });
167
285
  };
286
+ /** Concise, loggable reason from a schema-update error: the backend names the offending object
287
+ * in `details` (validation phase) or `message` (apply phase). */
288
+ TableManager.prototype.schemaErrorReason = function (error) {
289
+ var _a, _b;
290
+ var candidate = error;
291
+ return String((_b = (_a = candidate === null || candidate === void 0 ? void 0 : candidate.details) !== null && _a !== void 0 ? _a : candidate === null || candidate === void 0 ? void 0 : candidate.message) !== null && _b !== void 0 ? _b : error);
292
+ };
168
293
  TableManager.prototype.validateDynamicReferenceColumns = function (table) {
169
294
  var isDynamicRefColumn = function (column) {
170
295
  return typeof column.dynamicRefTableColName === 'string';
@@ -1 +1 @@
1
- {"version":3,"file":"TableManager.js","sourceRoot":"","sources":["../../../src/schema/TableManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA2C;AAC3C,kCAAoD;AAEpD,mDAAkD;AAIlD,IAAM,SAAS,GAAG,UAAC,GAAW;IAC5B,OAAA,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;AAA5E,CAA4E,CAAC;AAM/E;IAME,sBACE,QAAkB,EAClB,iBAAoC,EACpC,gBAAkC,EAClC,cAA+B;QATzB,WAAM,GAAG,IAAI,eAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,cAAc,CAAQ,EAAE,CAAC,CAAC;QAWvG,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,+BAAc,CAAC,QAAQ,CAAC,CAAC;IACvF,CAAC;IAEK,kCAAW,GAAjB,UAAkB,KAAiB;;;;4BAC1B,qBAAM,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,KAAK,CAAC,EAAA;4BAAnD,sBAAO,SAA4C,EAAC;;;;KACrD;IAED;;;;;;OAMG;IACG,iCAAU,GAAhB;;;;;;wBACQ,MAAM,GAAG,IAAA,iBAAS,GAAE,CAAC;wBACrB,YAAY,GAAiB,EAAE,CAAC;wBAChC,cAAc,GAAiB,EAAE,CAAC;8BACd,EAAN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M,EAAE,CAAC,CAAC;iCAC3E;6BACF;yBACF;wBAED,KAAW,OAAO,IAAI,eAAe,EAAE;4BAC/B,aAAa,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;4BACzC,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;4BACxD,IACE,CAAC,eAAe,CAAC,iBAAiB,CAAC;gCACnC,OAAO,IAAI,SAAS;gCACpB,OAAO,IAAI,aAAa;gCACxB,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;gCAC5B,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC;gCAC7B,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,EAC3B;gCACA,aAAa,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;6BAC/D;yBACF;wBAED,sBAAO,EAAE,eAAe,iBAAA,EAAE,aAAa,eAAA,EAAE,EAAC;;;;KAC3C;IACH,mBAAC;AAAD,CAAC,AAlXD,IAkXC;AAlXY,oCAAY"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteinjs/db",
3
- "version": "1.32.0",
3
+ "version": "1.32.2",
4
4
  "main": "./dist/generated/index.js",
5
5
  "types": "./dist/generated/index.d.ts",
6
6
  "exports": {
@@ -66,5 +66,5 @@
66
66
  "ts-jest": "29.1.1",
67
67
  "typescript": "5.2.2"
68
68
  },
69
- "gitHead": "edfed2d7826c7e42ddc0ae84bf97cda11614c1f0"
69
+ "gitHead": "744307f0dc93bb03bf9cecb76251a6848511b327"
70
70
  }
@@ -9,6 +9,21 @@ export interface SchemaOperations {
9
9
  */
10
10
  createTables(tables: Table<any>[]): Promise<void>;
11
11
  alterTable(table: Table<any>, changes: TableChanges): Promise<void>;
12
+
13
+ /**
14
+ * Classify a create/alter DDL error as the backend's "already exists" class — the loser's
15
+ * outcome when two actors concurrently create the same table/index or add the same column and
16
+ * the backend serializes the DDL so the object lands exactly once. Backend-specific (each driver
17
+ * owns its error codes/messages), so it is optional: a driver that does not implement it opts out
18
+ * of {@link TableManager}'s concurrent-reconcile tolerance and keeps the strict rethrow.
19
+ *
20
+ * MUST match on error CLASS (status code + a specific message class), never a loose substring —
21
+ * it decides whether a failure is eligible for verify-then-succeed, and a genuine failure that
22
+ * slipped into this class would be masked. The tolerance is still safe because TableManager
23
+ * re-reads and confirms the intended definition before treating it as success; this predicate is
24
+ * the first gate, not the whole guard.
25
+ */
26
+ isAlreadyExistsError?(error: unknown): boolean;
12
27
  }
13
28
 
14
29
  interface Index {
@@ -55,7 +55,11 @@ export class TableManager {
55
55
 
56
56
  if (absentTables.length > 0) {
57
57
  this.logger.info({ message: `Creating tables: ${absentTables.map((table) => table.name).join(', ')}` });
58
- await this.schemaOperations.createTables(absentTables);
58
+ try {
59
+ await this.schemaOperations.createTables(absentTables);
60
+ } catch (error) {
61
+ await this.reconcileConcurrentSchemaChange(absentTables, error);
62
+ }
59
63
  this.logger.info({ message: `Finished creating ${absentTables.length} tables` });
60
64
  }
61
65
 
@@ -71,7 +75,11 @@ export class TableManager {
71
75
  await this.alterTableIfChanged(table);
72
76
  } else {
73
77
  this.logger.info({ message: `Creating table: ${table.name}` });
74
- await this.schemaOperations.createTables([table]);
78
+ try {
79
+ await this.schemaOperations.createTables([table]);
80
+ } catch (error) {
81
+ await this.reconcileConcurrentSchemaChange([table], error);
82
+ }
75
83
  this.logger.info({ message: `Finished creating table: ${table.name}` });
76
84
  }
77
85
  }
@@ -80,11 +88,89 @@ export class TableManager {
80
88
  const tableChanges = await this.getTableChanges(table);
81
89
  if (this.shouldAlterTable(tableChanges)) {
82
90
  this.logger.info({ message: `Altering table: ${table.name}` });
83
- await this.schemaOperations.alterTable(table, tableChanges);
91
+ try {
92
+ await this.schemaOperations.alterTable(table, tableChanges);
93
+ } catch (error) {
94
+ await this.reconcileConcurrentSchemaChange([table], error);
95
+ }
84
96
  this.logger.info({ message: `Finished altering table: ${table.name}` });
85
97
  }
86
98
  }
87
99
 
100
+ /**
101
+ * Reconcile a create/alter DDL failure against a concurrent schema change, closing the
102
+ * check-then-act race in loadTable/loadTables.
103
+ *
104
+ * On a schema-changing release the migration Job, booting pods, and multiple replicas all run
105
+ * Db.init -> loadTables at once. Reconcile is check-then-act (read INFORMATION_SCHEMA -> decide
106
+ * create/alter -> apply DDL): two actors can both observe the same column/table as absent and
107
+ * both issue the CREATE/ALTER. The backend serializes DDL so the object lands EXACTLY once, but
108
+ * the loser's operation fails with an already-exists / duplicate-name error. Before this
109
+ * reconcile that error propagated out of Db.init — a booting pod with no unhandledRejection
110
+ * handler exited (CrashLoopBackOff) and the migration Job exited 1 (a spurious migration-gate
111
+ * failure).
112
+ *
113
+ * This is NOT a blanket swallow (that would mask real schema failures). Two independent gates
114
+ * must BOTH pass before a failure is treated as success:
115
+ * 1. CLASS — the driver's schema layer, which owns the backend's error codes/messages, must
116
+ * classify the error as the already-exists class ({@link SchemaOperations.isAlreadyExistsError}).
117
+ * A driver that does not implement the classifier always rethrows here.
118
+ * 2. INTENDED DEFINITION — a re-read of the live schema (the same metadata-backed detection
119
+ * getTableChanges uses) must confirm every table now exists AND has no remaining changes of
120
+ * the kind we attempted. A concurrent actor applying our EXACT change satisfies this; a
121
+ * genuine conflict (e.g. the column landed with a different type, so a column-type change is
122
+ * still outstanding) does not.
123
+ * If either gate fails, the ORIGINAL error propagates unchanged. Because every actor runs this
124
+ * same reconcile, it closes all three windows: migration-Job-vs-pod, pod-vs-pod, and
125
+ * multi-replica boot.
126
+ *
127
+ * OBSERVABILITY: this path is reached ONLY from the create/alter catch (the no-error happy path
128
+ * never calls it). Every outcome that reaches the intended-definition gate is logged LOUDLY at
129
+ * WARN — tolerance fired (treated as applied) OR the re-read failed (genuine conflict / still
130
+ * absent, re-throwing) — so an unexpected activation is visible in prod logs rather than silent.
131
+ */
132
+ private async reconcileConcurrentSchemaChange(tables: Table<any>[], error: unknown): Promise<void> {
133
+ if (!this.schemaOperations.isAlreadyExistsError?.(error)) {
134
+ throw error;
135
+ }
136
+
137
+ const tableNames = tables.map((table) => table.name).join(', ');
138
+ const reason = this.schemaErrorReason(error);
139
+
140
+ for (const table of tables) {
141
+ // A create that failed already-exists yet leaves the table absent is not the
142
+ // concurrent-winner case — surface the original error rather than masking it.
143
+ if (!(await this.tableExists(table))) {
144
+ this.logger.warn({
145
+ message: `[schema reconcile] caught ALREADY_EXISTS for table(s) '${tableNames}' but '${table.name}' is still absent on re-read — NOT a concurrent apply; re-throwing. reason: ${reason}`,
146
+ });
147
+ throw error;
148
+ }
149
+
150
+ const remainingChanges = await this.getTableChanges(table);
151
+ if (this.shouldAlterTable(remainingChanges)) {
152
+ // The object exists but the live schema still differs from the intended definition, so a
153
+ // concurrent actor did NOT apply our exact change (a genuine conflict). Propagate.
154
+ this.logger.warn({
155
+ message: `[schema reconcile] caught ALREADY_EXISTS for table '${table.name}' but the live schema does NOT match the intended definition on re-read (genuine conflict) — re-throwing. reason: ${reason}`,
156
+ obj: { remainingChanges },
157
+ });
158
+ throw error;
159
+ }
160
+ }
161
+
162
+ this.logger.warn({
163
+ message: `[schema reconcile] tolerated concurrent ALREADY_EXISTS for table(s) '${tableNames}' — re-read verified the object present with the intended definition, treating as applied (a concurrent actor won the race). reason: ${reason}`,
164
+ });
165
+ }
166
+
167
+ /** Concise, loggable reason from a schema-update error: the backend names the offending object
168
+ * in `details` (validation phase) or `message` (apply phase). */
169
+ private schemaErrorReason(error: unknown): string {
170
+ const candidate = error as { details?: unknown; message?: unknown } | undefined;
171
+ return String(candidate?.details ?? candidate?.message ?? error);
172
+ }
173
+
88
174
  private validateDynamicReferenceColumns(table: Table<any>): void {
89
175
  const isDynamicRefColumn = (column: any): column is DynamicReferenceColumn<any> =>
90
176
  typeof column.dynamicRefTableColName === 'string';