@proteinjs/db 1.34.0 → 1.34.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteinjs/db",
3
- "version": "1.34.0",
3
+ "version": "1.34.1",
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": "7a301275151aee8040fd52e15e3fe950a6863783"
69
+ "gitHead": "a5a56218a5757e47576cbe79858c9aacc6026816"
70
70
  }
@@ -206,7 +206,7 @@ export class MigrationRunner implements MigrationRunnerService {
206
206
  const db = getRunDb();
207
207
  migration.status = 'running';
208
208
  migration.startTime = moment();
209
- await db.update(migrationTable, migration);
209
+ await db.update(migrationTable, this.definedFields(migration));
210
210
  this.logger.info({ message: `Running migration (${migration.id}) ${migration.description}` });
211
211
  try {
212
212
  migration.output = await migration.run();
@@ -222,12 +222,31 @@ export class MigrationRunner implements MigrationRunnerService {
222
222
  migration.endTime = moment();
223
223
  }
224
224
  migration.duration = this.duration(migration.startTime, migration.endTime);
225
- await db.update(migrationTable, migration);
225
+ await db.update(migrationTable, this.definedFields(migration));
226
226
  this.logger.info({
227
227
  message: `[${migration.status}] (${migration.duration}) Finished running migration (${migration.id}) ${migration.description}`,
228
228
  });
229
229
  }
230
230
 
231
+ /**
232
+ * The run-state payload with `undefined`-valued fields OMITTED. Several of the record's fields
233
+ * are legitimately absent depending on the run (`output` for a void `run()`, `failureMessage`/
234
+ * `failureStack` for a non-Error throw), but the migration object carries them as explicit
235
+ * `undefined` assignments — and `RecordSerializer` rejects any payload field holding `undefined`
236
+ * (never a partial write), which would strand the row at 'running' status with the run's real
237
+ * outcome lost. Absent means omitted, never undefined — for EVERY optional field of the payload,
238
+ * not per-field.
239
+ */
240
+ private definedFields(migration: Migration): Partial<Migration> {
241
+ const payload: Partial<Migration> = {};
242
+ for (const [field, value] of Object.entries(migration)) {
243
+ if (value !== undefined) {
244
+ (payload as any)[field] = value;
245
+ }
246
+ }
247
+ return payload;
248
+ }
249
+
231
250
  private resolveMigration(migrationTable: Table<Migration>, id: string): Migration {
232
251
  const migration = new SourceRecordRepo().getSourceRecord<Migration>(migrationTable.name, id);
233
252
  if (!migration) {