@momentumcms/migrations 0.4.1 → 0.5.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": "@momentumcms/migrations",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "Database migration system for Momentum CMS",
5
5
  "license": "MIT",
6
6
  "main": "./src/index.cjs",
@@ -161,7 +161,7 @@ var MediaCollection = defineCollection({
161
161
  function resolveMigrationMode(mode) {
162
162
  if (mode === "push" || mode === "migrate")
163
163
  return mode;
164
- const env = process.env["NODE_ENV"];
164
+ const env = globalThis["process"]?.env?.["NODE_ENV"];
165
165
  if (env === "production")
166
166
  return "migrate";
167
167
  return "push";
@@ -686,10 +686,14 @@ function diffColumns(tableName, desiredColumns, actualColumns, dialect, opts) {
686
686
  const extraInActual = [...actualMap.keys()].filter((k) => !desiredMap.has(k));
687
687
  for (const newName of missingInActual) {
688
688
  const desiredCol = desiredMap.get(newName);
689
+ if (!desiredCol)
690
+ continue;
689
691
  for (const oldName of extraInActual) {
690
692
  if (renamedFrom.has(oldName))
691
693
  continue;
692
694
  const actualCol = actualMap.get(oldName);
695
+ if (!actualCol)
696
+ continue;
693
697
  if (areTypesCompatible(desiredCol.type, actualCol.type, dialect)) {
694
698
  operations.push({
695
699
  type: "renameColumn",
@@ -802,6 +806,8 @@ function diffForeignKeys(tableName, desiredFks, actualFks) {
802
806
  summary.push(`Add foreign key "${name}" on "${tableName}"`);
803
807
  } else {
804
808
  const actualFk = actualMap.get(name);
809
+ if (!actualFk)
810
+ continue;
805
811
  if (fk.column !== actualFk.column || fk.referencedTable !== actualFk.referencedTable || fk.referencedColumn !== actualFk.referencedColumn || fk.onDelete !== actualFk.onDelete) {
806
812
  operations.push({
807
813
  type: "dropForeignKey",
@@ -854,6 +860,8 @@ function diffIndexes(tableName, desiredIdxs, actualIdxs) {
854
860
  summary.push(`Create index "${name}" on "${tableName}"`);
855
861
  } else {
856
862
  const actualIdx = actualMap.get(name);
863
+ if (!actualIdx)
864
+ continue;
857
865
  if (idx.unique !== actualIdx.unique || JSON.stringify(idx.columns) !== JSON.stringify(actualIdx.columns)) {
858
866
  operations.push({
859
867
  type: "dropIndex",
@@ -1400,22 +1408,26 @@ async function introspectPostgres(queryFn, schema = "public") {
1400
1408
  const pkLookup = /* @__PURE__ */ new Map();
1401
1409
  for (const row2 of pkRows) {
1402
1410
  const tableName = row2.table_name;
1403
- if (!pkLookup.has(tableName)) {
1404
- pkLookup.set(tableName, /* @__PURE__ */ new Set());
1411
+ let pkSet = pkLookup.get(tableName);
1412
+ if (!pkSet) {
1413
+ pkSet = /* @__PURE__ */ new Set();
1414
+ pkLookup.set(tableName, pkSet);
1405
1415
  }
1406
- pkLookup.get(tableName).add(row2.column_name);
1416
+ pkSet.add(row2.column_name);
1407
1417
  }
1408
1418
  const tableColumnsMap = /* @__PURE__ */ new Map();
1409
1419
  for (const row2 of columnRows) {
1410
1420
  const tableName = row2.table_name;
1411
1421
  if (INTERNAL_TABLES.has(tableName))
1412
1422
  continue;
1413
- if (!tableColumnsMap.has(tableName)) {
1414
- tableColumnsMap.set(tableName, []);
1423
+ let columnList = tableColumnsMap.get(tableName);
1424
+ if (!columnList) {
1425
+ columnList = [];
1426
+ tableColumnsMap.set(tableName, columnList);
1415
1427
  }
1416
1428
  const rawType = buildPgColumnType(row2);
1417
1429
  const pkSet = pkLookup.get(tableName);
1418
- tableColumnsMap.get(tableName).push({
1430
+ columnList.push({
1419
1431
  name: row2.column_name,
1420
1432
  type: normalizeColumnType(rawType, "postgresql"),
1421
1433
  nullable: row2.is_nullable === "YES",
@@ -1428,10 +1440,12 @@ async function introspectPostgres(queryFn, schema = "public") {
1428
1440
  const tableName = row2.table_name;
1429
1441
  if (INTERNAL_TABLES.has(tableName))
1430
1442
  continue;
1431
- if (!tableFkMap.has(tableName)) {
1432
- tableFkMap.set(tableName, []);
1443
+ let fkList = tableFkMap.get(tableName);
1444
+ if (!fkList) {
1445
+ fkList = [];
1446
+ tableFkMap.set(tableName, fkList);
1433
1447
  }
1434
- tableFkMap.get(tableName).push({
1448
+ fkList.push({
1435
1449
  constraintName: row2.constraint_name,
1436
1450
  column: row2.column_name,
1437
1451
  referencedTable: row2.foreign_table_name,
@@ -1451,12 +1465,14 @@ async function introspectPostgres(queryFn, schema = "public") {
1451
1465
  continue;
1452
1466
  if (row2.indexname.endsWith("_pkey"))
1453
1467
  continue;
1454
- if (!tableIndexMap.has(tableName)) {
1455
- tableIndexMap.set(tableName, []);
1468
+ let indexList = tableIndexMap.get(tableName);
1469
+ if (!indexList) {
1470
+ indexList = [];
1471
+ tableIndexMap.set(tableName, indexList);
1456
1472
  }
1457
1473
  const columns = extractIndexColumns(row2.indexdef);
1458
1474
  const unique = row2.indexdef.toUpperCase().includes("UNIQUE");
1459
- tableIndexMap.get(tableName).push({
1475
+ indexList.push({
1460
1476
  name: row2.indexname,
1461
1477
  columns,
1462
1478
  unique
@@ -159,7 +159,7 @@ var MediaCollection = defineCollection({
159
159
  function resolveMigrationMode(mode) {
160
160
  if (mode === "push" || mode === "migrate")
161
161
  return mode;
162
- const env = process.env["NODE_ENV"];
162
+ const env = globalThis["process"]?.env?.["NODE_ENV"];
163
163
  if (env === "production")
164
164
  return "migrate";
165
165
  return "push";
@@ -684,10 +684,14 @@ function diffColumns(tableName, desiredColumns, actualColumns, dialect, opts) {
684
684
  const extraInActual = [...actualMap.keys()].filter((k) => !desiredMap.has(k));
685
685
  for (const newName of missingInActual) {
686
686
  const desiredCol = desiredMap.get(newName);
687
+ if (!desiredCol)
688
+ continue;
687
689
  for (const oldName of extraInActual) {
688
690
  if (renamedFrom.has(oldName))
689
691
  continue;
690
692
  const actualCol = actualMap.get(oldName);
693
+ if (!actualCol)
694
+ continue;
691
695
  if (areTypesCompatible(desiredCol.type, actualCol.type, dialect)) {
692
696
  operations.push({
693
697
  type: "renameColumn",
@@ -800,6 +804,8 @@ function diffForeignKeys(tableName, desiredFks, actualFks) {
800
804
  summary.push(`Add foreign key "${name}" on "${tableName}"`);
801
805
  } else {
802
806
  const actualFk = actualMap.get(name);
807
+ if (!actualFk)
808
+ continue;
803
809
  if (fk.column !== actualFk.column || fk.referencedTable !== actualFk.referencedTable || fk.referencedColumn !== actualFk.referencedColumn || fk.onDelete !== actualFk.onDelete) {
804
810
  operations.push({
805
811
  type: "dropForeignKey",
@@ -852,6 +858,8 @@ function diffIndexes(tableName, desiredIdxs, actualIdxs) {
852
858
  summary.push(`Create index "${name}" on "${tableName}"`);
853
859
  } else {
854
860
  const actualIdx = actualMap.get(name);
861
+ if (!actualIdx)
862
+ continue;
855
863
  if (idx.unique !== actualIdx.unique || JSON.stringify(idx.columns) !== JSON.stringify(actualIdx.columns)) {
856
864
  operations.push({
857
865
  type: "dropIndex",
@@ -1398,22 +1406,26 @@ async function introspectPostgres(queryFn, schema = "public") {
1398
1406
  const pkLookup = /* @__PURE__ */ new Map();
1399
1407
  for (const row2 of pkRows) {
1400
1408
  const tableName = row2.table_name;
1401
- if (!pkLookup.has(tableName)) {
1402
- pkLookup.set(tableName, /* @__PURE__ */ new Set());
1409
+ let pkSet = pkLookup.get(tableName);
1410
+ if (!pkSet) {
1411
+ pkSet = /* @__PURE__ */ new Set();
1412
+ pkLookup.set(tableName, pkSet);
1403
1413
  }
1404
- pkLookup.get(tableName).add(row2.column_name);
1414
+ pkSet.add(row2.column_name);
1405
1415
  }
1406
1416
  const tableColumnsMap = /* @__PURE__ */ new Map();
1407
1417
  for (const row2 of columnRows) {
1408
1418
  const tableName = row2.table_name;
1409
1419
  if (INTERNAL_TABLES.has(tableName))
1410
1420
  continue;
1411
- if (!tableColumnsMap.has(tableName)) {
1412
- tableColumnsMap.set(tableName, []);
1421
+ let columnList = tableColumnsMap.get(tableName);
1422
+ if (!columnList) {
1423
+ columnList = [];
1424
+ tableColumnsMap.set(tableName, columnList);
1413
1425
  }
1414
1426
  const rawType = buildPgColumnType(row2);
1415
1427
  const pkSet = pkLookup.get(tableName);
1416
- tableColumnsMap.get(tableName).push({
1428
+ columnList.push({
1417
1429
  name: row2.column_name,
1418
1430
  type: normalizeColumnType(rawType, "postgresql"),
1419
1431
  nullable: row2.is_nullable === "YES",
@@ -1426,10 +1438,12 @@ async function introspectPostgres(queryFn, schema = "public") {
1426
1438
  const tableName = row2.table_name;
1427
1439
  if (INTERNAL_TABLES.has(tableName))
1428
1440
  continue;
1429
- if (!tableFkMap.has(tableName)) {
1430
- tableFkMap.set(tableName, []);
1441
+ let fkList = tableFkMap.get(tableName);
1442
+ if (!fkList) {
1443
+ fkList = [];
1444
+ tableFkMap.set(tableName, fkList);
1431
1445
  }
1432
- tableFkMap.get(tableName).push({
1446
+ fkList.push({
1433
1447
  constraintName: row2.constraint_name,
1434
1448
  column: row2.column_name,
1435
1449
  referencedTable: row2.foreign_table_name,
@@ -1449,12 +1463,14 @@ async function introspectPostgres(queryFn, schema = "public") {
1449
1463
  continue;
1450
1464
  if (row2.indexname.endsWith("_pkey"))
1451
1465
  continue;
1452
- if (!tableIndexMap.has(tableName)) {
1453
- tableIndexMap.set(tableName, []);
1466
+ let indexList = tableIndexMap.get(tableName);
1467
+ if (!indexList) {
1468
+ indexList = [];
1469
+ tableIndexMap.set(tableName, indexList);
1454
1470
  }
1455
1471
  const columns = extractIndexColumns(row2.indexdef);
1456
1472
  const unique = row2.indexdef.toUpperCase().includes("UNIQUE");
1457
- tableIndexMap.get(tableName).push({
1473
+ indexList.push({
1458
1474
  name: row2.indexname,
1459
1475
  columns,
1460
1476
  unique
@@ -121,7 +121,7 @@ var MediaCollection = defineCollection({
121
121
  function resolveMigrationMode(mode) {
122
122
  if (mode === "push" || mode === "migrate")
123
123
  return mode;
124
- const env = process.env["NODE_ENV"];
124
+ const env = globalThis["process"]?.env?.["NODE_ENV"];
125
125
  if (env === "production")
126
126
  return "migrate";
127
127
  return "push";
@@ -119,7 +119,7 @@ var MediaCollection = defineCollection({
119
119
  function resolveMigrationMode(mode) {
120
120
  if (mode === "push" || mode === "migrate")
121
121
  return mode;
122
- const env = process.env["NODE_ENV"];
122
+ const env = globalThis["process"]?.env?.["NODE_ENV"];
123
123
  if (env === "production")
124
124
  return "migrate";
125
125
  return "push";
package/src/cli/run.cjs CHANGED
@@ -121,7 +121,7 @@ var MediaCollection = defineCollection({
121
121
  function resolveMigrationMode(mode) {
122
122
  if (mode === "push" || mode === "migrate")
123
123
  return mode;
124
- const env = process.env["NODE_ENV"];
124
+ const env = globalThis["process"]?.env?.["NODE_ENV"];
125
125
  if (env === "production")
126
126
  return "migrate";
127
127
  return "push";
package/src/cli/run.js CHANGED
@@ -127,7 +127,7 @@ var MediaCollection = defineCollection({
127
127
  function resolveMigrationMode(mode) {
128
128
  if (mode === "push" || mode === "migrate")
129
129
  return mode;
130
- const env = process.env["NODE_ENV"];
130
+ const env = globalThis["process"]?.env?.["NODE_ENV"];
131
131
  if (env === "production")
132
132
  return "migrate";
133
133
  return "push";
@@ -121,7 +121,7 @@ var MediaCollection = defineCollection({
121
121
  function resolveMigrationMode(mode) {
122
122
  if (mode === "push" || mode === "migrate")
123
123
  return mode;
124
- const env = process.env["NODE_ENV"];
124
+ const env = globalThis["process"]?.env?.["NODE_ENV"];
125
125
  if (env === "production")
126
126
  return "migrate";
127
127
  return "push";
package/src/cli/status.js CHANGED
@@ -119,7 +119,7 @@ var MediaCollection = defineCollection({
119
119
  function resolveMigrationMode(mode) {
120
120
  if (mode === "push" || mode === "migrate")
121
121
  return mode;
122
- const env = process.env["NODE_ENV"];
122
+ const env = globalThis["process"]?.env?.["NODE_ENV"];
123
123
  if (env === "production")
124
124
  return "migrate";
125
125
  return "push";
package/src/index.cjs CHANGED
@@ -285,22 +285,26 @@ async function introspectPostgres(queryFn, schema = "public") {
285
285
  const pkLookup = /* @__PURE__ */ new Map();
286
286
  for (const row2 of pkRows) {
287
287
  const tableName = row2.table_name;
288
- if (!pkLookup.has(tableName)) {
289
- pkLookup.set(tableName, /* @__PURE__ */ new Set());
288
+ let pkSet = pkLookup.get(tableName);
289
+ if (!pkSet) {
290
+ pkSet = /* @__PURE__ */ new Set();
291
+ pkLookup.set(tableName, pkSet);
290
292
  }
291
- pkLookup.get(tableName).add(row2.column_name);
293
+ pkSet.add(row2.column_name);
292
294
  }
293
295
  const tableColumnsMap = /* @__PURE__ */ new Map();
294
296
  for (const row2 of columnRows) {
295
297
  const tableName = row2.table_name;
296
298
  if (INTERNAL_TABLES.has(tableName))
297
299
  continue;
298
- if (!tableColumnsMap.has(tableName)) {
299
- tableColumnsMap.set(tableName, []);
300
+ let columnList = tableColumnsMap.get(tableName);
301
+ if (!columnList) {
302
+ columnList = [];
303
+ tableColumnsMap.set(tableName, columnList);
300
304
  }
301
305
  const rawType = buildPgColumnType(row2);
302
306
  const pkSet = pkLookup.get(tableName);
303
- tableColumnsMap.get(tableName).push({
307
+ columnList.push({
304
308
  name: row2.column_name,
305
309
  type: normalizeColumnType(rawType, "postgresql"),
306
310
  nullable: row2.is_nullable === "YES",
@@ -313,10 +317,12 @@ async function introspectPostgres(queryFn, schema = "public") {
313
317
  const tableName = row2.table_name;
314
318
  if (INTERNAL_TABLES.has(tableName))
315
319
  continue;
316
- if (!tableFkMap.has(tableName)) {
317
- tableFkMap.set(tableName, []);
320
+ let fkList = tableFkMap.get(tableName);
321
+ if (!fkList) {
322
+ fkList = [];
323
+ tableFkMap.set(tableName, fkList);
318
324
  }
319
- tableFkMap.get(tableName).push({
325
+ fkList.push({
320
326
  constraintName: row2.constraint_name,
321
327
  column: row2.column_name,
322
328
  referencedTable: row2.foreign_table_name,
@@ -336,12 +342,14 @@ async function introspectPostgres(queryFn, schema = "public") {
336
342
  continue;
337
343
  if (row2.indexname.endsWith("_pkey"))
338
344
  continue;
339
- if (!tableIndexMap.has(tableName)) {
340
- tableIndexMap.set(tableName, []);
345
+ let indexList = tableIndexMap.get(tableName);
346
+ if (!indexList) {
347
+ indexList = [];
348
+ tableIndexMap.set(tableName, indexList);
341
349
  }
342
350
  const columns = extractIndexColumns(row2.indexdef);
343
351
  const unique = row2.indexdef.toUpperCase().includes("UNIQUE");
344
- tableIndexMap.get(tableName).push({
352
+ indexList.push({
345
353
  name: row2.indexname,
346
354
  columns,
347
355
  unique
@@ -935,10 +943,14 @@ function diffColumns(tableName, desiredColumns, actualColumns, dialect, opts) {
935
943
  const extraInActual = [...actualMap.keys()].filter((k) => !desiredMap.has(k));
936
944
  for (const newName of missingInActual) {
937
945
  const desiredCol = desiredMap.get(newName);
946
+ if (!desiredCol)
947
+ continue;
938
948
  for (const oldName of extraInActual) {
939
949
  if (renamedFrom.has(oldName))
940
950
  continue;
941
951
  const actualCol = actualMap.get(oldName);
952
+ if (!actualCol)
953
+ continue;
942
954
  if (areTypesCompatible(desiredCol.type, actualCol.type, dialect)) {
943
955
  operations.push({
944
956
  type: "renameColumn",
@@ -1051,6 +1063,8 @@ function diffForeignKeys(tableName, desiredFks, actualFks) {
1051
1063
  summary.push(`Add foreign key "${name}" on "${tableName}"`);
1052
1064
  } else {
1053
1065
  const actualFk = actualMap.get(name);
1066
+ if (!actualFk)
1067
+ continue;
1054
1068
  if (fk.column !== actualFk.column || fk.referencedTable !== actualFk.referencedTable || fk.referencedColumn !== actualFk.referencedColumn || fk.onDelete !== actualFk.onDelete) {
1055
1069
  operations.push({
1056
1070
  type: "dropForeignKey",
@@ -1103,6 +1117,8 @@ function diffIndexes(tableName, desiredIdxs, actualIdxs) {
1103
1117
  summary.push(`Create index "${name}" on "${tableName}"`);
1104
1118
  } else {
1105
1119
  const actualIdx = actualMap.get(name);
1120
+ if (!actualIdx)
1121
+ continue;
1106
1122
  if (idx.unique !== actualIdx.unique || JSON.stringify(idx.columns) !== JSON.stringify(actualIdx.columns)) {
1107
1123
  operations.push({
1108
1124
  type: "dropIndex",
package/src/index.js CHANGED
@@ -220,22 +220,26 @@ async function introspectPostgres(queryFn, schema = "public") {
220
220
  const pkLookup = /* @__PURE__ */ new Map();
221
221
  for (const row2 of pkRows) {
222
222
  const tableName = row2.table_name;
223
- if (!pkLookup.has(tableName)) {
224
- pkLookup.set(tableName, /* @__PURE__ */ new Set());
223
+ let pkSet = pkLookup.get(tableName);
224
+ if (!pkSet) {
225
+ pkSet = /* @__PURE__ */ new Set();
226
+ pkLookup.set(tableName, pkSet);
225
227
  }
226
- pkLookup.get(tableName).add(row2.column_name);
228
+ pkSet.add(row2.column_name);
227
229
  }
228
230
  const tableColumnsMap = /* @__PURE__ */ new Map();
229
231
  for (const row2 of columnRows) {
230
232
  const tableName = row2.table_name;
231
233
  if (INTERNAL_TABLES.has(tableName))
232
234
  continue;
233
- if (!tableColumnsMap.has(tableName)) {
234
- tableColumnsMap.set(tableName, []);
235
+ let columnList = tableColumnsMap.get(tableName);
236
+ if (!columnList) {
237
+ columnList = [];
238
+ tableColumnsMap.set(tableName, columnList);
235
239
  }
236
240
  const rawType = buildPgColumnType(row2);
237
241
  const pkSet = pkLookup.get(tableName);
238
- tableColumnsMap.get(tableName).push({
242
+ columnList.push({
239
243
  name: row2.column_name,
240
244
  type: normalizeColumnType(rawType, "postgresql"),
241
245
  nullable: row2.is_nullable === "YES",
@@ -248,10 +252,12 @@ async function introspectPostgres(queryFn, schema = "public") {
248
252
  const tableName = row2.table_name;
249
253
  if (INTERNAL_TABLES.has(tableName))
250
254
  continue;
251
- if (!tableFkMap.has(tableName)) {
252
- tableFkMap.set(tableName, []);
255
+ let fkList = tableFkMap.get(tableName);
256
+ if (!fkList) {
257
+ fkList = [];
258
+ tableFkMap.set(tableName, fkList);
253
259
  }
254
- tableFkMap.get(tableName).push({
260
+ fkList.push({
255
261
  constraintName: row2.constraint_name,
256
262
  column: row2.column_name,
257
263
  referencedTable: row2.foreign_table_name,
@@ -271,12 +277,14 @@ async function introspectPostgres(queryFn, schema = "public") {
271
277
  continue;
272
278
  if (row2.indexname.endsWith("_pkey"))
273
279
  continue;
274
- if (!tableIndexMap.has(tableName)) {
275
- tableIndexMap.set(tableName, []);
280
+ let indexList = tableIndexMap.get(tableName);
281
+ if (!indexList) {
282
+ indexList = [];
283
+ tableIndexMap.set(tableName, indexList);
276
284
  }
277
285
  const columns = extractIndexColumns(row2.indexdef);
278
286
  const unique = row2.indexdef.toUpperCase().includes("UNIQUE");
279
- tableIndexMap.get(tableName).push({
287
+ indexList.push({
280
288
  name: row2.indexname,
281
289
  columns,
282
290
  unique
@@ -870,10 +878,14 @@ function diffColumns(tableName, desiredColumns, actualColumns, dialect, opts) {
870
878
  const extraInActual = [...actualMap.keys()].filter((k) => !desiredMap.has(k));
871
879
  for (const newName of missingInActual) {
872
880
  const desiredCol = desiredMap.get(newName);
881
+ if (!desiredCol)
882
+ continue;
873
883
  for (const oldName of extraInActual) {
874
884
  if (renamedFrom.has(oldName))
875
885
  continue;
876
886
  const actualCol = actualMap.get(oldName);
887
+ if (!actualCol)
888
+ continue;
877
889
  if (areTypesCompatible(desiredCol.type, actualCol.type, dialect)) {
878
890
  operations.push({
879
891
  type: "renameColumn",
@@ -986,6 +998,8 @@ function diffForeignKeys(tableName, desiredFks, actualFks) {
986
998
  summary.push(`Add foreign key "${name}" on "${tableName}"`);
987
999
  } else {
988
1000
  const actualFk = actualMap.get(name);
1001
+ if (!actualFk)
1002
+ continue;
989
1003
  if (fk.column !== actualFk.column || fk.referencedTable !== actualFk.referencedTable || fk.referencedColumn !== actualFk.referencedColumn || fk.onDelete !== actualFk.onDelete) {
990
1004
  operations.push({
991
1005
  type: "dropForeignKey",
@@ -1038,6 +1052,8 @@ function diffIndexes(tableName, desiredIdxs, actualIdxs) {
1038
1052
  summary.push(`Create index "${name}" on "${tableName}"`);
1039
1053
  } else {
1040
1054
  const actualIdx = actualMap.get(name);
1055
+ if (!actualIdx)
1056
+ continue;
1041
1057
  if (idx.unique !== actualIdx.unique || JSON.stringify(idx.columns) !== JSON.stringify(actualIdx.columns)) {
1042
1058
  operations.push({
1043
1059
  type: "dropIndex",