rake-db 2.2.3 → 2.2.4

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/index.js CHANGED
@@ -13,21 +13,21 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
13
13
  var Enquirer__default = /*#__PURE__*/_interopDefaultLegacy(Enquirer);
14
14
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
15
15
 
16
- var __defProp$5 = Object.defineProperty;
16
+ var __defProp$6 = Object.defineProperty;
17
17
  var __defProps$5 = Object.defineProperties;
18
18
  var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
19
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
20
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
21
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
22
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
23
- var __spreadValues$5 = (a, b) => {
19
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
20
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
21
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
22
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
23
+ var __spreadValues$6 = (a, b) => {
24
24
  for (var prop in b || (b = {}))
25
- if (__hasOwnProp$5.call(b, prop))
26
- __defNormalProp$5(a, prop, b[prop]);
27
- if (__getOwnPropSymbols$5)
28
- for (var prop of __getOwnPropSymbols$5(b)) {
29
- if (__propIsEnum$5.call(b, prop))
30
- __defNormalProp$5(a, prop, b[prop]);
25
+ if (__hasOwnProp$6.call(b, prop))
26
+ __defNormalProp$6(a, prop, b[prop]);
27
+ if (__getOwnPropSymbols$6)
28
+ for (var prop of __getOwnPropSymbols$6(b)) {
29
+ if (__propIsEnum$6.call(b, prop))
30
+ __defNormalProp$6(a, prop, b[prop]);
31
31
  }
32
32
  return a;
33
33
  };
@@ -37,10 +37,11 @@ const migrationConfigDefaults = {
37
37
  migrationsTable: "schemaMigrations",
38
38
  requireTs: require,
39
39
  log: true,
40
- logger: console
40
+ logger: console,
41
+ useCodeUpdaterByDefault: true
41
42
  };
42
43
  const getMigrationConfigWithDefaults = (config) => {
43
- return __spreadValues$5(__spreadValues$5({}, migrationConfigDefaults), config);
44
+ return __spreadValues$6(__spreadValues$6({}, migrationConfigDefaults), config);
44
45
  };
45
46
  const getDatabaseAndUserFromOptions = (options) => {
46
47
  if (options.databaseURL) {
@@ -68,9 +69,9 @@ const setAdapterOptions = (options, set) => {
68
69
  if (set.password !== void 0) {
69
70
  url.password = set.password;
70
71
  }
71
- return __spreadProps$5(__spreadValues$5({}, options), { databaseURL: url.toString() });
72
+ return __spreadProps$5(__spreadValues$6({}, options), { databaseURL: url.toString() });
72
73
  } else {
73
- return __spreadValues$5(__spreadValues$5({}, options), set);
74
+ return __spreadValues$6(__spreadValues$6({}, options), set);
74
75
  }
75
76
  };
76
77
  const askAdminCredentials = async () => {
@@ -209,21 +210,21 @@ const setCurrentMigrationUp = (up) => {
209
210
  const getCurrentPromise = () => currentPromise;
210
211
  const getCurrentChangeCallback = () => currentChangeCallback;
211
212
 
212
- var __defProp$4 = Object.defineProperty;
213
+ var __defProp$5 = Object.defineProperty;
213
214
  var __defProps$4 = Object.defineProperties;
214
215
  var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
215
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
216
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
217
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
218
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
219
- var __spreadValues$4 = (a, b) => {
216
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
217
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
218
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
219
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
220
+ var __spreadValues$5 = (a, b) => {
220
221
  for (var prop in b || (b = {}))
221
- if (__hasOwnProp$4.call(b, prop))
222
- __defNormalProp$4(a, prop, b[prop]);
223
- if (__getOwnPropSymbols$4)
224
- for (var prop of __getOwnPropSymbols$4(b)) {
225
- if (__propIsEnum$4.call(b, prop))
226
- __defNormalProp$4(a, prop, b[prop]);
222
+ if (__hasOwnProp$5.call(b, prop))
223
+ __defNormalProp$5(a, prop, b[prop]);
224
+ if (__getOwnPropSymbols$5)
225
+ for (var prop of __getOwnPropSymbols$5(b)) {
226
+ if (__propIsEnum$5.call(b, prop))
227
+ __defNormalProp$5(a, prop, b[prop]);
227
228
  }
228
229
  return a;
229
230
  };
@@ -264,7 +265,7 @@ const addColumnIndex = (indexes, key, item) => {
264
265
  if (item.data) {
265
266
  if (item.data.index) {
266
267
  indexes.push({
267
- columns: [__spreadProps$4(__spreadValues$4({}, item.data.index), { column: key })],
268
+ columns: [__spreadProps$4(__spreadValues$5({}, item.data.index), { column: key })],
268
269
  options: item.data.index
269
270
  });
270
271
  }
@@ -400,21 +401,21 @@ WHERE
400
401
  return rows;
401
402
  };
402
403
 
403
- var __defProp$3 = Object.defineProperty;
404
+ var __defProp$4 = Object.defineProperty;
404
405
  var __defProps$3 = Object.defineProperties;
405
406
  var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
406
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
407
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
408
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
409
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
410
- var __spreadValues$3 = (a, b) => {
407
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
408
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
409
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
410
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
411
+ var __spreadValues$4 = (a, b) => {
411
412
  for (var prop in b || (b = {}))
412
- if (__hasOwnProp$3.call(b, prop))
413
- __defNormalProp$3(a, prop, b[prop]);
414
- if (__getOwnPropSymbols$3)
415
- for (var prop of __getOwnPropSymbols$3(b)) {
416
- if (__propIsEnum$3.call(b, prop))
417
- __defNormalProp$3(a, prop, b[prop]);
413
+ if (__hasOwnProp$4.call(b, prop))
414
+ __defNormalProp$4(a, prop, b[prop]);
415
+ if (__getOwnPropSymbols$4)
416
+ for (var prop of __getOwnPropSymbols$4(b)) {
417
+ if (__propIsEnum$4.call(b, prop))
418
+ __defNormalProp$4(a, prop, b[prop]);
418
419
  }
419
420
  return a;
420
421
  };
@@ -423,7 +424,6 @@ const types = Object.assign(Object.create(pqb.columnTypes), {
423
424
  raw: pqb.raw
424
425
  });
425
426
  const createTable = async (migration, up, tableName, options, fn) => {
426
- var _a, _b;
427
427
  const shape = pqb.getColumnTypes(types, fn);
428
428
  const tableData = pqb.getTableData();
429
429
  const ast = makeAst$1(
@@ -439,7 +439,7 @@ const createTable = async (migration, up, tableName, options, fn) => {
439
439
  for (const query of queries) {
440
440
  await migration.query(query);
441
441
  }
442
- await ((_b = (_a = migration.options).appCodeUpdater) == null ? void 0 : _b.call(_a, ast));
442
+ await runCodeUpdater(migration, ast);
443
443
  };
444
444
  const makeAst$1 = (up, tableName, shape, tableData, options, noPrimaryKey) => {
445
445
  const shapePKeys = [];
@@ -449,13 +449,13 @@ const makeAst$1 = (up, tableName, shape, tableData, options, noPrimaryKey) => {
449
449
  }
450
450
  }
451
451
  const primaryKey = tableData.primaryKey;
452
- return __spreadProps$3(__spreadValues$3(__spreadProps$3(__spreadValues$3({
452
+ return __spreadProps$3(__spreadValues$4(__spreadProps$3(__spreadValues$4({
453
453
  type: "table",
454
454
  action: up ? "create" : "drop",
455
455
  name: tableName,
456
456
  shape
457
457
  }, tableData), {
458
- primaryKey: shapePKeys.length <= 1 ? primaryKey : primaryKey ? __spreadProps$3(__spreadValues$3({}, primaryKey), { columns: [...shapePKeys, ...primaryKey.columns] }) : { columns: shapePKeys }
458
+ primaryKey: shapePKeys.length <= 1 ? primaryKey : primaryKey ? __spreadProps$3(__spreadValues$4({}, primaryKey), { columns: [...shapePKeys, ...primaryKey.columns] }) : { columns: shapePKeys }
459
459
  }), options), {
460
460
  noPrimaryKey: options.noPrimaryKey ? "ignore" : noPrimaryKey || "error"
461
461
  });
@@ -529,21 +529,21 @@ const astToQueries$1 = (ast) => {
529
529
  return result;
530
530
  };
531
531
 
532
- var __defProp$2 = Object.defineProperty;
532
+ var __defProp$3 = Object.defineProperty;
533
533
  var __defProps$2 = Object.defineProperties;
534
534
  var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
535
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
536
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
537
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
538
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
539
- var __spreadValues$2 = (a, b) => {
535
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
536
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
537
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
538
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
539
+ var __spreadValues$3 = (a, b) => {
540
540
  for (var prop in b || (b = {}))
541
- if (__hasOwnProp$2.call(b, prop))
542
- __defNormalProp$2(a, prop, b[prop]);
543
- if (__getOwnPropSymbols$2)
544
- for (var prop of __getOwnPropSymbols$2(b)) {
545
- if (__propIsEnum$2.call(b, prop))
546
- __defNormalProp$2(a, prop, b[prop]);
541
+ if (__hasOwnProp$3.call(b, prop))
542
+ __defNormalProp$3(a, prop, b[prop]);
543
+ if (__getOwnPropSymbols$3)
544
+ for (var prop of __getOwnPropSymbols$3(b)) {
545
+ if (__propIsEnum$3.call(b, prop))
546
+ __defNormalProp$3(a, prop, b[prop]);
547
547
  }
548
548
  return a;
549
549
  };
@@ -563,7 +563,7 @@ const mergeTableData = (a, b) => {
563
563
  } else {
564
564
  a.primaryKey = {
565
565
  columns: [...a.primaryKey.columns, ...b.primaryKey.columns],
566
- options: __spreadValues$2(__spreadValues$2({}, a.primaryKey.options), b.primaryKey.options)
566
+ options: __spreadValues$3(__spreadValues$3({}, a.primaryKey.options), b.primaryKey.options)
567
567
  };
568
568
  }
569
569
  }
@@ -614,7 +614,7 @@ const columnTypeToColumnChange = (item) => {
614
614
  if (foreignKey && "fn" in foreignKey) {
615
615
  throw new Error("Callback in foreignKey is not allowed in migration");
616
616
  }
617
- return __spreadProps$2(__spreadValues$2({
617
+ return __spreadProps$2(__spreadValues$3({
618
618
  column: item,
619
619
  type: item.toSQL(),
620
620
  nullable: item.isNullable,
@@ -630,7 +630,7 @@ const tableChangeMethods = {
630
630
  add,
631
631
  drop,
632
632
  change(from, to, options) {
633
- return __spreadValues$2({
633
+ return __spreadValues$3({
634
634
  type: "change",
635
635
  from: columnTypeToColumnChange(from),
636
636
  to: columnTypeToColumnChange(to)
@@ -661,7 +661,6 @@ const tableChangeMethods = {
661
661
  }
662
662
  };
663
663
  const changeTable = async (migration, up, tableName, options, fn) => {
664
- var _a, _b;
665
664
  pqb.resetTableData();
666
665
  resetChangeTableData();
667
666
  const tableChanger = Object.create(pqb.columnTypes);
@@ -672,7 +671,7 @@ const changeTable = async (migration, up, tableName, options, fn) => {
672
671
  for (const query of queries) {
673
672
  await migration.query(query);
674
673
  }
675
- await ((_b = (_a = migration.options).appCodeUpdater) == null ? void 0 : _b.call(_a, ast));
674
+ await runCodeUpdater(migration, ast);
676
675
  };
677
676
  const makeAst = (up, name, changeData, changeTableData2, options) => {
678
677
  const { comment } = options;
@@ -681,17 +680,17 @@ const makeAst = (up, name, changeData, changeTableData2, options) => {
681
680
  const item = changeData[key];
682
681
  if ("type" in item) {
683
682
  if (up) {
684
- shape[key] = item.type === "change" && item.usingUp ? __spreadProps$2(__spreadValues$2({}, item), { using: item.usingUp }) : item;
683
+ shape[key] = item.type === "change" && item.usingUp ? __spreadProps$2(__spreadValues$3({}, item), { using: item.usingUp }) : item;
685
684
  } else {
686
685
  if (item.type === "rename") {
687
- shape[item.name] = __spreadProps$2(__spreadValues$2({}, item), { name: key });
686
+ shape[item.name] = __spreadProps$2(__spreadValues$3({}, item), { name: key });
688
687
  } else {
689
- shape[key] = item.type === "add" ? __spreadProps$2(__spreadValues$2({}, item), { type: "drop" }) : item.type === "drop" ? __spreadProps$2(__spreadValues$2({}, item), { type: "add" }) : item.type === "change" ? __spreadProps$2(__spreadValues$2({}, item), { from: item.to, to: item.from, using: item.usingDown }) : item;
688
+ shape[key] = item.type === "add" ? __spreadProps$2(__spreadValues$3({}, item), { type: "drop" }) : item.type === "drop" ? __spreadProps$2(__spreadValues$3({}, item), { type: "add" }) : item.type === "change" ? __spreadProps$2(__spreadValues$3({}, item), { from: item.to, to: item.from, using: item.usingDown }) : item;
690
689
  }
691
690
  }
692
691
  }
693
692
  }
694
- return __spreadValues$2({
693
+ return __spreadValues$3({
695
694
  type: "changeTable",
696
695
  name,
697
696
  comment: comment ? up ? Array.isArray(comment) ? comment[1] : comment : Array.isArray(comment) ? comment[0] : null : void 0,
@@ -707,10 +706,10 @@ const astToQueries = (ast) => {
707
706
  values: []
708
707
  });
709
708
  }
710
- const addPrimaryKeys = ast.add.primaryKey ? __spreadValues$2({}, ast.add.primaryKey) : {
709
+ const addPrimaryKeys = ast.add.primaryKey ? __spreadValues$3({}, ast.add.primaryKey) : {
711
710
  columns: []
712
711
  };
713
- const dropPrimaryKeys = ast.drop.primaryKey ? __spreadValues$2({}, ast.drop.primaryKey) : {
712
+ const dropPrimaryKeys = ast.drop.primaryKey ? __spreadValues$3({}, ast.drop.primaryKey) : {
714
713
  columns: []
715
714
  };
716
715
  for (const key in ast.shape) {
@@ -807,7 +806,7 @@ const astToQueries = (ast) => {
807
806
  if (fromIndex) {
808
807
  dropIndexes.push({
809
808
  columns: [
810
- __spreadValues$2({
809
+ __spreadValues$3({
811
810
  column: key
812
811
  }, fromIndex)
813
812
  ],
@@ -817,7 +816,7 @@ const astToQueries = (ast) => {
817
816
  if (toIndex) {
818
817
  addIndexes.push({
819
818
  columns: [
820
- __spreadValues$2({
819
+ __spreadValues$3({
821
820
  column: key
822
821
  }, toIndex)
823
822
  ],
@@ -866,21 +865,21 @@ const astToQueries = (ast) => {
866
865
  return result;
867
866
  };
868
867
 
869
- var __defProp$1 = Object.defineProperty;
868
+ var __defProp$2 = Object.defineProperty;
870
869
  var __defProps$1 = Object.defineProperties;
871
870
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
872
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
873
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
874
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
875
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
876
- var __spreadValues$1 = (a, b) => {
871
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
872
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
873
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
874
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
875
+ var __spreadValues$2 = (a, b) => {
877
876
  for (var prop in b || (b = {}))
878
- if (__hasOwnProp$1.call(b, prop))
879
- __defNormalProp$1(a, prop, b[prop]);
880
- if (__getOwnPropSymbols$1)
881
- for (var prop of __getOwnPropSymbols$1(b)) {
882
- if (__propIsEnum$1.call(b, prop))
883
- __defNormalProp$1(a, prop, b[prop]);
877
+ if (__hasOwnProp$2.call(b, prop))
878
+ __defNormalProp$2(a, prop, b[prop]);
879
+ if (__getOwnPropSymbols$2)
880
+ for (var prop of __getOwnPropSymbols$2(b)) {
881
+ if (__propIsEnum$2.call(b, prop))
882
+ __defNormalProp$2(a, prop, b[prop]);
884
883
  }
885
884
  return a;
886
885
  };
@@ -902,14 +901,14 @@ const createJoinTable = async (migration, up, tables, options, fn) => {
902
901
  migration,
903
902
  up,
904
903
  tableName,
905
- __spreadProps$1(__spreadValues$1({}, options), { noPrimaryKey: true }),
904
+ __spreadProps$1(__spreadValues$2({}, options), { noPrimaryKey: true }),
906
905
  () => ({})
907
906
  );
908
907
  }
909
908
  const tablesWithPrimaryKeys = await Promise.all(
910
909
  tables.map(async (table) => {
911
910
  const primaryKeys = await getPrimaryKeysOfTable(migration, table).then(
912
- (items) => items.map((item) => __spreadProps$1(__spreadValues$1({}, item), {
911
+ (items) => items.map((item) => __spreadProps$1(__spreadValues$2({}, item), {
913
912
  joinedName: joinWords(pluralize.singular(table), item.name)
914
913
  }))
915
914
  );
@@ -951,30 +950,32 @@ const createJoinTable = async (migration, up, tables, options, fn) => {
951
950
  });
952
951
  };
953
952
 
954
- var __defProp = Object.defineProperty;
953
+ var __defProp$1 = Object.defineProperty;
955
954
  var __defProps = Object.defineProperties;
956
955
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
957
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
958
- var __hasOwnProp = Object.prototype.hasOwnProperty;
959
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
960
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
961
- var __spreadValues = (a, b) => {
956
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
957
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
958
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
959
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
960
+ var __spreadValues$1 = (a, b) => {
962
961
  for (var prop in b || (b = {}))
963
- if (__hasOwnProp.call(b, prop))
964
- __defNormalProp(a, prop, b[prop]);
965
- if (__getOwnPropSymbols)
966
- for (var prop of __getOwnPropSymbols(b)) {
967
- if (__propIsEnum.call(b, prop))
968
- __defNormalProp(a, prop, b[prop]);
962
+ if (__hasOwnProp$1.call(b, prop))
963
+ __defNormalProp$1(a, prop, b[prop]);
964
+ if (__getOwnPropSymbols$1)
965
+ for (var prop of __getOwnPropSymbols$1(b)) {
966
+ if (__propIsEnum$1.call(b, prop))
967
+ __defNormalProp$1(a, prop, b[prop]);
969
968
  }
970
969
  return a;
971
970
  };
972
971
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
973
972
  class Migration extends pqb.TransactionAdapter {
974
- constructor(tx, up, options) {
973
+ constructor(tx, up, options, adapterOptions, appCodeUpdaterCache) {
975
974
  super(tx, tx.client, tx.types);
976
975
  this.up = up;
977
976
  this.options = options;
977
+ this.adapterOptions = adapterOptions;
978
+ this.appCodeUpdaterCache = appCodeUpdaterCache;
978
979
  this.log = pqb.logParamToLogObject(options.logger || console, options.log);
979
980
  }
980
981
  async query(query, types = this.types, log = this.log) {
@@ -1008,7 +1009,6 @@ class Migration extends pqb.TransactionAdapter {
1008
1009
  return changeTable(this, this.up, tableName, options, fn);
1009
1010
  }
1010
1011
  async renameTable(from, to) {
1011
- var _a, _b;
1012
1012
  const ast = {
1013
1013
  type: "renameTable",
1014
1014
  from: this.up ? from : to,
@@ -1017,7 +1017,7 @@ class Migration extends pqb.TransactionAdapter {
1017
1017
  await this.query(
1018
1018
  `ALTER TABLE ${quoteTable(ast.from)} RENAME TO "${ast.to}"`
1019
1019
  );
1020
- await ((_b = (_a = this.options).appCodeUpdater) == null ? void 0 : _b.call(_a, ast));
1020
+ await runCodeUpdater(this, ast);
1021
1021
  }
1022
1022
  addColumn(tableName, columnName, fn) {
1023
1023
  return addColumn(this, this.up, tableName, columnName, fn);
@@ -1099,7 +1099,7 @@ const wrapWithLog = async (log, query, fn) => {
1099
1099
  if (!log) {
1100
1100
  return fn();
1101
1101
  } else {
1102
- const sql = typeof query === "string" ? { text: query, values: [] } : query.values ? query : __spreadProps(__spreadValues({}, query), { values: [] });
1102
+ const sql = typeof query === "string" ? { text: query, values: [] } : query.values ? query : __spreadProps(__spreadValues$1({}, query), { values: [] });
1103
1103
  const logData = log.beforeQuery(sql);
1104
1104
  try {
1105
1105
  const result = await fn();
@@ -1117,16 +1117,15 @@ const addColumn = (migration, up, tableName, columnName, fn) => {
1117
1117
  }));
1118
1118
  };
1119
1119
  const addIndex = (migration, up, tableName, columns, options) => {
1120
- return changeTable(migration, up, tableName, {}, (t) => __spreadValues({}, t.add(t.index(columns, options))));
1120
+ return changeTable(migration, up, tableName, {}, (t) => __spreadValues$1({}, t.add(t.index(columns, options))));
1121
1121
  };
1122
1122
  const addForeignKey = (migration, up, tableName, columns, foreignTable, foreignColumns, options) => {
1123
- return changeTable(migration, up, tableName, {}, (t) => __spreadValues({}, t.add(t.foreignKey(columns, foreignTable, foreignColumns, options))));
1123
+ return changeTable(migration, up, tableName, {}, (t) => __spreadValues$1({}, t.add(t.foreignKey(columns, foreignTable, foreignColumns, options))));
1124
1124
  };
1125
1125
  const addPrimaryKey = (migration, up, tableName, columns, options) => {
1126
- return changeTable(migration, up, tableName, {}, (t) => __spreadValues({}, t.add(t.primaryKey(columns, options))));
1126
+ return changeTable(migration, up, tableName, {}, (t) => __spreadValues$1({}, t.add(t.primaryKey(columns, options))));
1127
1127
  };
1128
1128
  const createSchema = async (migration, up, name) => {
1129
- var _a, _b;
1130
1129
  const ast = {
1131
1130
  type: "schema",
1132
1131
  action: up ? "create" : "drop",
@@ -1135,11 +1134,10 @@ const createSchema = async (migration, up, name) => {
1135
1134
  await migration.query(
1136
1135
  `${ast.action === "create" ? "CREATE" : "DROP"} SCHEMA "${name}"`
1137
1136
  );
1138
- await ((_b = (_a = migration.options).appCodeUpdater) == null ? void 0 : _b.call(_a, ast));
1137
+ await runCodeUpdater(migration, ast);
1139
1138
  };
1140
1139
  const createExtension = async (migration, up, name, options) => {
1141
- var _a, _b;
1142
- const ast = __spreadValues({
1140
+ const ast = __spreadValues$1({
1143
1141
  type: "extension",
1144
1142
  action: up ? "create" : "drop",
1145
1143
  name
@@ -1151,17 +1149,54 @@ const createExtension = async (migration, up, name, options) => {
1151
1149
  query = `CREATE EXTENSION${ast.ifExists ? " IF NOT EXISTS" : ""} "${ast.name}"${ast.schema ? ` SCHEMA "${ast.schema}"` : ""}${ast.version ? ` VERSION '${ast.version}'` : ""}${ast.cascade ? " CASCADE" : ""}`;
1152
1150
  }
1153
1151
  await migration.query(query);
1154
- await ((_b = (_a = migration.options).appCodeUpdater) == null ? void 0 : _b.call(_a, ast));
1152
+ await runCodeUpdater(migration, ast);
1155
1153
  };
1156
1154
  const queryExists = (db, sql) => {
1157
1155
  return db.query(sql).then(({ rowCount }) => rowCount > 0);
1158
1156
  };
1157
+ const runCodeUpdater = (migration, ast) => {
1158
+ var _a, _b;
1159
+ return (_b = (_a = migration.options).appCodeUpdater) == null ? void 0 : _b.call(_a, {
1160
+ ast,
1161
+ options: migration.adapterOptions,
1162
+ cache: migration.appCodeUpdaterCache
1163
+ });
1164
+ };
1159
1165
 
1166
+ var __defProp = Object.defineProperty;
1167
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1168
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
1169
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
1170
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1171
+ var __spreadValues = (a, b) => {
1172
+ for (var prop in b || (b = {}))
1173
+ if (__hasOwnProp.call(b, prop))
1174
+ __defNormalProp(a, prop, b[prop]);
1175
+ if (__getOwnPropSymbols)
1176
+ for (var prop of __getOwnPropSymbols(b)) {
1177
+ if (__propIsEnum.call(b, prop))
1178
+ __defNormalProp(a, prop, b[prop]);
1179
+ }
1180
+ return a;
1181
+ };
1160
1182
  const migrateOrRollback = async (options, config, args, up) => {
1161
1183
  var _a;
1184
+ config = __spreadValues({}, config);
1162
1185
  const files = await getMigrationFiles(config, up);
1163
- const argCount = args[0] === "all" ? Infinity : parseInt(args[0]);
1164
- let count = isNaN(argCount) ? up ? Infinity : 1 : argCount;
1186
+ let count = up ? Infinity : 1;
1187
+ let argI = 0;
1188
+ const num = args[0] === "all" ? Infinity : parseInt(args[0]);
1189
+ if (!isNaN(num)) {
1190
+ argI++;
1191
+ count = num;
1192
+ }
1193
+ const arg = args[argI];
1194
+ if (arg === "--code") {
1195
+ config.useCodeUpdater = args[argI + 1] !== "false";
1196
+ }
1197
+ if (!config.useCodeUpdater)
1198
+ delete config.appCodeUpdater;
1199
+ const appCodeUpdaterCache = {};
1165
1200
  for (const opts of pqb.toArray(options)) {
1166
1201
  const db = new pqb.Adapter(opts);
1167
1202
  const migratedVersions = await getMigratedVersionsMap(db, config);
@@ -1172,18 +1207,19 @@ const migrateOrRollback = async (options, config, args, up) => {
1172
1207
  }
1173
1208
  if (count-- <= 0)
1174
1209
  break;
1175
- await processMigration(db, up, file, config);
1210
+ await processMigration(db, up, file, config, opts, appCodeUpdaterCache);
1176
1211
  (_a = config.logger) == null ? void 0 : _a.log(`${file.path} ${up ? "migrated" : "rolled back"}`);
1177
1212
  }
1178
1213
  } finally {
1179
1214
  await db.close();
1180
1215
  }
1216
+ delete config.appCodeUpdater;
1181
1217
  }
1182
1218
  };
1183
1219
  const changeCache = {};
1184
- const processMigration = async (db, up, file, config) => {
1220
+ const processMigration = async (db, up, file, config, options, appCodeUpdaterCache) => {
1185
1221
  await db.transaction(async (tx) => {
1186
- const db2 = new Migration(tx, up, config);
1222
+ const db2 = new Migration(tx, up, config, options, appCodeUpdaterCache);
1187
1223
  setCurrentMigration(db2);
1188
1224
  setCurrentMigrationUp(up);
1189
1225
  const callback = changeCache[file.path];
@@ -1406,17 +1442,30 @@ Commands:
1406
1442
  drop drop databases
1407
1443
  reset drop, create and migrate databases
1408
1444
  g, generate generate migration file, see below
1409
- migrate migrate all pending migrations
1445
+ migrate migrate pending migrations
1410
1446
  rollback rollback the last migrated
1411
1447
  no or unknown command prints this message
1412
1448
 
1449
+ Migrate arguments:
1450
+ no arguments run all pending migrations
1451
+ number run specific number of pending migrations
1452
+
1453
+ Rollback arguments:
1454
+ no arguments rollback one last applied migration
1455
+ number rollback specific number of applied migrations
1456
+ all rollback all applied migrations
1457
+
1458
+ Migrate and rollback common arguments:
1459
+ --code run code updater, overrides \`useCodeUpdater\` option
1460
+ --code false do not run code updater
1461
+
1413
1462
  Generate arguments:
1414
1463
  - (required) first argument is migration name
1415
- * create* template for create table
1416
- * change* template for change table
1417
- * add*To* template for add columns
1418
- * remove*From* template for remove columns
1419
- * drop* template for drop table
1464
+ * create* template for create table
1465
+ * change* template for change table
1466
+ * add*To* template for add columns
1467
+ * remove*From* template for remove columns
1468
+ * drop* template for drop table
1420
1469
 
1421
1470
  - other arguments considered as columns with types and optional methods:
1422
1471
  rake-db g createTable id:serial.primaryKey name:text.nullable
@@ -1432,4 +1481,5 @@ exports.migrate = migrate;
1432
1481
  exports.rakeDb = rakeDb;
1433
1482
  exports.resetDb = resetDb;
1434
1483
  exports.rollback = rollback;
1484
+ exports.runCodeUpdater = runCodeUpdater;
1435
1485
  //# sourceMappingURL=index.js.map