rake-db 2.0.36 → 2.1.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/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.esm.js +134 -44
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +133 -43
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/migration/changeTable.test.ts +169 -2
- package/src/migration/changeTable.ts +135 -5
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$
|
|
16
|
+
var __defProp$4 = Object.defineProperty;
|
|
17
17
|
var __defProps$3 = Object.defineProperties;
|
|
18
18
|
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
19
|
-
var __getOwnPropSymbols$
|
|
20
|
-
var __hasOwnProp$
|
|
21
|
-
var __propIsEnum$
|
|
22
|
-
var __defNormalProp$
|
|
23
|
-
var __spreadValues$
|
|
19
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
20
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
21
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
22
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
23
|
+
var __spreadValues$4 = (a, b) => {
|
|
24
24
|
for (var prop in b || (b = {}))
|
|
25
|
-
if (__hasOwnProp$
|
|
26
|
-
__defNormalProp$
|
|
27
|
-
if (__getOwnPropSymbols$
|
|
28
|
-
for (var prop of __getOwnPropSymbols$
|
|
29
|
-
if (__propIsEnum$
|
|
30
|
-
__defNormalProp$
|
|
25
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
26
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
27
|
+
if (__getOwnPropSymbols$4)
|
|
28
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
29
|
+
if (__propIsEnum$4.call(b, prop))
|
|
30
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
31
31
|
}
|
|
32
32
|
return a;
|
|
33
33
|
};
|
|
@@ -40,7 +40,7 @@ const migrationConfigDefaults = {
|
|
|
40
40
|
logger: console
|
|
41
41
|
};
|
|
42
42
|
const getMigrationConfigWithDefaults = (config) => {
|
|
43
|
-
return __spreadValues$
|
|
43
|
+
return __spreadValues$4(__spreadValues$4({}, migrationConfigDefaults), config);
|
|
44
44
|
};
|
|
45
45
|
const getDatabaseAndUserFromOptions = (options) => {
|
|
46
46
|
if (options.connectionString) {
|
|
@@ -68,9 +68,9 @@ const setAdapterOptions = (options, set) => {
|
|
|
68
68
|
if (set.password !== void 0) {
|
|
69
69
|
url.password = set.password;
|
|
70
70
|
}
|
|
71
|
-
return __spreadProps$3(__spreadValues$
|
|
71
|
+
return __spreadProps$3(__spreadValues$4({}, options), { connectionString: url.toString() });
|
|
72
72
|
} else {
|
|
73
|
-
return __spreadValues$
|
|
73
|
+
return __spreadValues$4(__spreadValues$4({}, options), set);
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
const askAdminCredentials = async () => {
|
|
@@ -209,21 +209,21 @@ const setCurrentMigrationUp = (up) => {
|
|
|
209
209
|
const getCurrentPromise = () => currentPromise;
|
|
210
210
|
const getCurrentChangeCallback = () => currentChangeCallback;
|
|
211
211
|
|
|
212
|
-
var __defProp$
|
|
212
|
+
var __defProp$3 = Object.defineProperty;
|
|
213
213
|
var __defProps$2 = Object.defineProperties;
|
|
214
214
|
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
215
|
-
var __getOwnPropSymbols$
|
|
216
|
-
var __hasOwnProp$
|
|
217
|
-
var __propIsEnum$
|
|
218
|
-
var __defNormalProp$
|
|
219
|
-
var __spreadValues$
|
|
215
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
216
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
217
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
218
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
219
|
+
var __spreadValues$3 = (a, b) => {
|
|
220
220
|
for (var prop in b || (b = {}))
|
|
221
|
-
if (__hasOwnProp$
|
|
222
|
-
__defNormalProp$
|
|
223
|
-
if (__getOwnPropSymbols$
|
|
224
|
-
for (var prop of __getOwnPropSymbols$
|
|
225
|
-
if (__propIsEnum$
|
|
226
|
-
__defNormalProp$
|
|
221
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
222
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
223
|
+
if (__getOwnPropSymbols$3)
|
|
224
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
225
|
+
if (__propIsEnum$3.call(b, prop))
|
|
226
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
227
227
|
}
|
|
228
228
|
return a;
|
|
229
229
|
};
|
|
@@ -264,7 +264,7 @@ const addColumnIndex = (indexes, key, item) => {
|
|
|
264
264
|
if (item.data) {
|
|
265
265
|
if (item.data.index) {
|
|
266
266
|
indexes.push({
|
|
267
|
-
columns: [__spreadProps$2(__spreadValues$
|
|
267
|
+
columns: [__spreadProps$2(__spreadValues$3({}, item.data.index), { column: key })],
|
|
268
268
|
options: item.data.index
|
|
269
269
|
});
|
|
270
270
|
}
|
|
@@ -403,21 +403,21 @@ WHERE
|
|
|
403
403
|
return rows;
|
|
404
404
|
};
|
|
405
405
|
|
|
406
|
-
var __defProp$
|
|
406
|
+
var __defProp$2 = Object.defineProperty;
|
|
407
407
|
var __defProps$1 = Object.defineProperties;
|
|
408
408
|
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
409
|
-
var __getOwnPropSymbols$
|
|
410
|
-
var __hasOwnProp$
|
|
411
|
-
var __propIsEnum$
|
|
412
|
-
var __defNormalProp$
|
|
413
|
-
var __spreadValues$
|
|
409
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
410
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
411
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
412
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
413
|
+
var __spreadValues$2 = (a, b) => {
|
|
414
414
|
for (var prop in b || (b = {}))
|
|
415
|
-
if (__hasOwnProp$
|
|
416
|
-
__defNormalProp$
|
|
417
|
-
if (__getOwnPropSymbols$
|
|
418
|
-
for (var prop of __getOwnPropSymbols$
|
|
419
|
-
if (__propIsEnum$
|
|
420
|
-
__defNormalProp$
|
|
415
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
416
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
417
|
+
if (__getOwnPropSymbols$2)
|
|
418
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
419
|
+
if (__propIsEnum$2.call(b, prop))
|
|
420
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
421
421
|
}
|
|
422
422
|
return a;
|
|
423
423
|
};
|
|
@@ -437,7 +437,7 @@ const createJoinTable = async (migration, up, tables, options, fn) => {
|
|
|
437
437
|
const tablesWithPrimaryKeys = await Promise.all(
|
|
438
438
|
tables.map(async (table) => {
|
|
439
439
|
const primaryKeys = await getPrimaryKeysOfTable(migration, table).then(
|
|
440
|
-
(items) => items.map((item) => __spreadProps$1(__spreadValues$
|
|
440
|
+
(items) => items.map((item) => __spreadProps$1(__spreadValues$2({}, item), {
|
|
441
441
|
joinedName: joinWords(pluralize.singular(table), item.name)
|
|
442
442
|
}))
|
|
443
443
|
);
|
|
@@ -529,6 +529,22 @@ const createTable = async (migration, up, tableName, options, fn) => {
|
|
|
529
529
|
}
|
|
530
530
|
};
|
|
531
531
|
|
|
532
|
+
var __defProp$1 = Object.defineProperty;
|
|
533
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
534
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
535
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
536
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
537
|
+
var __spreadValues$1 = (a, b) => {
|
|
538
|
+
for (var prop in b || (b = {}))
|
|
539
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
540
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
541
|
+
if (__getOwnPropSymbols$1)
|
|
542
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
543
|
+
if (__propIsEnum$1.call(b, prop))
|
|
544
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
545
|
+
}
|
|
546
|
+
return a;
|
|
547
|
+
};
|
|
532
548
|
const newChangeTableData = () => ({
|
|
533
549
|
add: [],
|
|
534
550
|
drop: []
|
|
@@ -695,6 +711,68 @@ const changeActions = {
|
|
|
695
711
|
`ALTER COLUMN "${key}" ${to.nullable ? "DROP" : "SET"} NOT NULL`
|
|
696
712
|
);
|
|
697
713
|
}
|
|
714
|
+
if (from.compression !== to.compression) {
|
|
715
|
+
state.alterTable.push(
|
|
716
|
+
`ALTER COLUMN "${key}" SET COMPRESSION ${to.compression || "DEFAULT"}`
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
const fromFkey = from.foreignKey;
|
|
720
|
+
const toFkey = to.foreignKey;
|
|
721
|
+
if (fromFkey || toFkey) {
|
|
722
|
+
if (fromFkey && "fn" in fromFkey || toFkey && "fn" in toFkey) {
|
|
723
|
+
throw new Error("Callback in foreignKey is not allowed in migration");
|
|
724
|
+
}
|
|
725
|
+
if (checkIfForeignKeysAreDifferent(fromFkey, toFkey)) {
|
|
726
|
+
if (fromFkey) {
|
|
727
|
+
const data = pqb.newTableData();
|
|
728
|
+
data.foreignKeys.push({
|
|
729
|
+
columns: [key],
|
|
730
|
+
fnOrTable: fromFkey.table,
|
|
731
|
+
foreignColumns: fromFkey.columns,
|
|
732
|
+
options: fromFkey
|
|
733
|
+
});
|
|
734
|
+
changeTableData[up ? "drop" : "add"].push(data);
|
|
735
|
+
}
|
|
736
|
+
if (toFkey) {
|
|
737
|
+
const data = pqb.newTableData();
|
|
738
|
+
data.foreignKeys.push({
|
|
739
|
+
columns: [key],
|
|
740
|
+
fnOrTable: toFkey.table,
|
|
741
|
+
foreignColumns: toFkey.columns,
|
|
742
|
+
options: toFkey
|
|
743
|
+
});
|
|
744
|
+
changeTableData[up ? "add" : "drop"].push(data);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
const fromIndex = from.index;
|
|
749
|
+
const toIndex = to.index;
|
|
750
|
+
if ((fromIndex || toIndex) && checkIfIndexesAreDifferent(fromIndex, toIndex)) {
|
|
751
|
+
if (fromIndex) {
|
|
752
|
+
const data = pqb.newTableData();
|
|
753
|
+
data.indexes.push({
|
|
754
|
+
columns: [
|
|
755
|
+
__spreadValues$1({
|
|
756
|
+
column: key
|
|
757
|
+
}, fromIndex)
|
|
758
|
+
],
|
|
759
|
+
options: fromIndex
|
|
760
|
+
});
|
|
761
|
+
changeTableData[up ? "drop" : "add"].push(data);
|
|
762
|
+
}
|
|
763
|
+
if (toIndex) {
|
|
764
|
+
const data = pqb.newTableData();
|
|
765
|
+
data.indexes.push({
|
|
766
|
+
columns: [
|
|
767
|
+
__spreadValues$1({
|
|
768
|
+
column: key
|
|
769
|
+
}, toIndex)
|
|
770
|
+
],
|
|
771
|
+
options: toIndex
|
|
772
|
+
});
|
|
773
|
+
changeTableData[up ? "add" : "drop"].push(data);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
698
776
|
if (from.comment !== to.comment) {
|
|
699
777
|
state.comments.push({ column: key, comment: to.comment || null });
|
|
700
778
|
}
|
|
@@ -704,6 +782,12 @@ const changeActions = {
|
|
|
704
782
|
state.alterTable.push(`RENAME COLUMN "${from}" TO "${to}"`);
|
|
705
783
|
}
|
|
706
784
|
};
|
|
785
|
+
const checkIfForeignKeysAreDifferent = (from, to) => {
|
|
786
|
+
return !from || !to || from.name !== to.name || from.match !== to.match || from.onUpdate !== to.onUpdate || from.onDelete !== to.onDelete || from.dropMode !== to.dropMode || from.table !== to.table || from.columns.join(",") !== to.columns.join(",");
|
|
787
|
+
};
|
|
788
|
+
const checkIfIndexesAreDifferent = (from, to) => {
|
|
789
|
+
return !from || !to || from.expression !== to.expression || from.collate !== to.collate || from.operator !== to.operator || from.order !== to.order || from.name !== to.name || from.unique !== to.unique || from.using !== to.using || from.include !== to.include || Array.isArray(from.include) && Array.isArray(to.include) && from.include.join(",") !== to.include.join(",") || from.with !== to.with || from.tablespace !== to.tablespace || from.where !== to.where || from.dropMode !== to.dropMode;
|
|
790
|
+
};
|
|
707
791
|
const getChangeProperties = (item) => {
|
|
708
792
|
if (item instanceof pqb.ColumnType) {
|
|
709
793
|
return {
|
|
@@ -711,7 +795,10 @@ const getChangeProperties = (item) => {
|
|
|
711
795
|
collate: item.data.collate,
|
|
712
796
|
default: item.data.default,
|
|
713
797
|
nullable: item.isNullable,
|
|
714
|
-
comment: item.data.comment
|
|
798
|
+
comment: item.data.comment,
|
|
799
|
+
compression: item.data.compression,
|
|
800
|
+
foreignKey: item.data.foreignKey,
|
|
801
|
+
index: item.data.index
|
|
715
802
|
};
|
|
716
803
|
} else {
|
|
717
804
|
return {
|
|
@@ -719,7 +806,10 @@ const getChangeProperties = (item) => {
|
|
|
719
806
|
collate: void 0,
|
|
720
807
|
default: item[0] === "default" ? item[1] : void 0,
|
|
721
808
|
nullable: item[0] === "nullable" ? item[1] : void 0,
|
|
722
|
-
comment: item[0] === "comment" ? item[1] : void 0
|
|
809
|
+
comment: item[0] === "comment" ? item[1] : void 0,
|
|
810
|
+
compression: item[0] === "compression" ? item[1] : void 0,
|
|
811
|
+
foreignKey: item[0] === "foreignKey" ? item[1] : void 0,
|
|
812
|
+
index: item[0] === "index" ? item[1] : void 0
|
|
723
813
|
};
|
|
724
814
|
}
|
|
725
815
|
};
|