rake-db 2.3.3 → 2.3.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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +0 -4
- package/dist/index.esm.js +78 -209
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +77 -208
- package/dist/index.js.map +1 -1
- package/migrations/20221017200326_createChatUser.ts +1 -1
- package/package.json +1 -1
- package/src/migration/migration.ts +0 -35
- package/migrations/20230124210600_pull.ts +0 -86
- package/src/migration/createJoinTable.test.ts +0 -96
- package/src/migration/createJoinTable.ts +0 -107
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -73,10 +73,6 @@ declare class Migration extends TransactionAdapter {
|
|
|
73
73
|
createTable(tableName: string, fn: ColumnsShapeCallback): Promise<void>;
|
|
74
74
|
dropTable(tableName: string, options: TableOptions, fn: ColumnsShapeCallback): Promise<void>;
|
|
75
75
|
dropTable(tableName: string, fn: ColumnsShapeCallback): Promise<void>;
|
|
76
|
-
createJoinTable(tables: string[], options?: JoinTableOptions, fn?: ColumnsShapeCallback): Promise<void>;
|
|
77
|
-
createJoinTable(tables: string[], fn?: ColumnsShapeCallback): Promise<void>;
|
|
78
|
-
dropJoinTable(tables: string[], options?: JoinTableOptions, fn?: ColumnsShapeCallback): Promise<void>;
|
|
79
|
-
dropJoinTable(tables: string[], fn?: ColumnsShapeCallback): Promise<void>;
|
|
80
76
|
changeTable(tableName: string, options: ChangeTableOptions, fn?: ChangeTableCallback): Promise<void>;
|
|
81
77
|
changeTable(tableName: string, fn: ChangeTableCallback): Promise<void>;
|
|
82
78
|
renameTable(from: string, to: string): Promise<void>;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
import { singleQuote, quote, isRaw, getRaw, toArray, columnTypes, raw, getColumnTypes, getTableData, resetTableData, ColumnType, emptyObject,
|
|
1
|
+
import { singleQuote, quote, isRaw, getRaw, toArray, columnTypes, raw, getColumnTypes, getTableData, resetTableData, ColumnType, emptyObject, TransactionAdapter, logParamToLogObject, Adapter, columnsByType, instantiateColumn, codeToString, addCode, quoteObjectKey, primaryKeyToCode, indexToCode, foreignKeyToCode, TimestampColumn } from 'pqb';
|
|
2
2
|
import Enquirer from 'enquirer';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { readdir, mkdir, writeFile } from 'fs/promises';
|
|
5
|
-
import { singular } from 'pluralize';
|
|
6
5
|
|
|
7
|
-
var __defProp$
|
|
8
|
-
var __defProps$
|
|
9
|
-
var __getOwnPropDescs$
|
|
10
|
-
var __getOwnPropSymbols$
|
|
11
|
-
var __hasOwnProp$
|
|
12
|
-
var __propIsEnum$
|
|
13
|
-
var __defNormalProp$
|
|
14
|
-
var __spreadValues$
|
|
6
|
+
var __defProp$6 = Object.defineProperty;
|
|
7
|
+
var __defProps$5 = Object.defineProperties;
|
|
8
|
+
var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
|
|
9
|
+
var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
|
|
10
|
+
var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues$6 = (a, b) => {
|
|
15
14
|
for (var prop in b || (b = {}))
|
|
16
|
-
if (__hasOwnProp$
|
|
17
|
-
__defNormalProp$
|
|
18
|
-
if (__getOwnPropSymbols$
|
|
19
|
-
for (var prop of __getOwnPropSymbols$
|
|
20
|
-
if (__propIsEnum$
|
|
21
|
-
__defNormalProp$
|
|
15
|
+
if (__hasOwnProp$6.call(b, prop))
|
|
16
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols$6)
|
|
18
|
+
for (var prop of __getOwnPropSymbols$6(b)) {
|
|
19
|
+
if (__propIsEnum$6.call(b, prop))
|
|
20
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
22
21
|
}
|
|
23
22
|
return a;
|
|
24
23
|
};
|
|
25
|
-
var __spreadProps$
|
|
24
|
+
var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
26
25
|
const migrationConfigDefaults = {
|
|
27
26
|
migrationsPath: path.resolve("src", "migrations"),
|
|
28
27
|
migrationsTable: "schemaMigrations",
|
|
@@ -32,7 +31,7 @@ const migrationConfigDefaults = {
|
|
|
32
31
|
useCodeUpdater: true
|
|
33
32
|
};
|
|
34
33
|
const getMigrationConfigWithDefaults = (config) => {
|
|
35
|
-
return __spreadValues$
|
|
34
|
+
return __spreadValues$6(__spreadValues$6({}, migrationConfigDefaults), config);
|
|
36
35
|
};
|
|
37
36
|
const getDatabaseAndUserFromOptions = (options) => {
|
|
38
37
|
if (options.databaseURL) {
|
|
@@ -60,9 +59,9 @@ const setAdapterOptions = (options, set) => {
|
|
|
60
59
|
if (set.password !== void 0) {
|
|
61
60
|
url.password = set.password;
|
|
62
61
|
}
|
|
63
|
-
return __spreadProps$
|
|
62
|
+
return __spreadProps$5(__spreadValues$6({}, options), { databaseURL: url.toString() });
|
|
64
63
|
} else {
|
|
65
|
-
return __spreadValues$
|
|
64
|
+
return __spreadValues$6(__spreadValues$6({}, options), set);
|
|
66
65
|
}
|
|
67
66
|
};
|
|
68
67
|
const askAdminCredentials = async () => {
|
|
@@ -164,12 +163,6 @@ const getMigrationFiles = async (config, up) => {
|
|
|
164
163
|
};
|
|
165
164
|
const sortAsc = (arr) => arr.sort();
|
|
166
165
|
const sortDesc = (arr) => arr.sort((a, b) => a > b ? -1 : 1);
|
|
167
|
-
const joinWords = (...words) => {
|
|
168
|
-
return words.slice(1).reduce(
|
|
169
|
-
(acc, word) => acc + word[0].toUpperCase() + word.slice(1),
|
|
170
|
-
words[0]
|
|
171
|
-
);
|
|
172
|
-
};
|
|
173
166
|
const joinColumns = (columns) => {
|
|
174
167
|
return columns.map((column) => `"${column}"`).join(", ");
|
|
175
168
|
};
|
|
@@ -209,25 +202,25 @@ const setCurrentMigrationUp = (up) => {
|
|
|
209
202
|
const getCurrentPromise = () => currentPromise;
|
|
210
203
|
const getCurrentChangeCallback = () => currentChangeCallback;
|
|
211
204
|
|
|
212
|
-
var __defProp$
|
|
213
|
-
var __defProps$
|
|
214
|
-
var __getOwnPropDescs$
|
|
215
|
-
var __getOwnPropSymbols$
|
|
216
|
-
var __hasOwnProp$
|
|
217
|
-
var __propIsEnum$
|
|
218
|
-
var __defNormalProp$
|
|
219
|
-
var __spreadValues$
|
|
205
|
+
var __defProp$5 = Object.defineProperty;
|
|
206
|
+
var __defProps$4 = Object.defineProperties;
|
|
207
|
+
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
|
|
208
|
+
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
|
|
209
|
+
var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
|
|
210
|
+
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
|
|
211
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
212
|
+
var __spreadValues$5 = (a, b) => {
|
|
220
213
|
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$
|
|
214
|
+
if (__hasOwnProp$5.call(b, prop))
|
|
215
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
216
|
+
if (__getOwnPropSymbols$5)
|
|
217
|
+
for (var prop of __getOwnPropSymbols$5(b)) {
|
|
218
|
+
if (__propIsEnum$5.call(b, prop))
|
|
219
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
227
220
|
}
|
|
228
221
|
return a;
|
|
229
222
|
};
|
|
230
|
-
var __spreadProps$
|
|
223
|
+
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
231
224
|
const columnToSql = (key, item, values, hasMultiplePrimaryKeys) => {
|
|
232
225
|
const line = [`"${key}" ${item.toSQL()}`];
|
|
233
226
|
if (item.data.compression) {
|
|
@@ -266,7 +259,7 @@ const addColumnIndex = (indexes, key, item) => {
|
|
|
266
259
|
if (item.data.indexes) {
|
|
267
260
|
indexes.push(
|
|
268
261
|
...item.data.indexes.map((index) => ({
|
|
269
|
-
columns: [__spreadProps$
|
|
262
|
+
columns: [__spreadProps$4(__spreadValues$5({}, index), { column: key })],
|
|
270
263
|
options: index
|
|
271
264
|
}))
|
|
272
265
|
);
|
|
@@ -397,48 +390,26 @@ const primaryKeyToSql = (primaryKey) => {
|
|
|
397
390
|
primaryKey.columns
|
|
398
391
|
)})`;
|
|
399
392
|
};
|
|
400
|
-
const getPrimaryKeysOfTable = async (db, tableName) => {
|
|
401
|
-
const { rows } = await db.query(
|
|
402
|
-
{
|
|
403
|
-
text: `SELECT
|
|
404
|
-
pg_attribute.attname AS name,
|
|
405
|
-
format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS type
|
|
406
|
-
FROM pg_index, pg_class, pg_attribute, pg_namespace
|
|
407
|
-
WHERE
|
|
408
|
-
pg_class.oid = $1::regclass AND
|
|
409
|
-
indrelid = pg_class.oid AND
|
|
410
|
-
nspname = 'public' AND
|
|
411
|
-
pg_class.relnamespace = pg_namespace.oid AND
|
|
412
|
-
pg_attribute.attrelid = pg_class.oid AND
|
|
413
|
-
pg_attribute.attnum = any(pg_index.indkey) AND
|
|
414
|
-
indisprimary`,
|
|
415
|
-
values: [tableName]
|
|
416
|
-
},
|
|
417
|
-
db.types,
|
|
418
|
-
void 0
|
|
419
|
-
);
|
|
420
|
-
return rows;
|
|
421
|
-
};
|
|
422
393
|
|
|
423
|
-
var __defProp$
|
|
424
|
-
var __defProps$
|
|
425
|
-
var __getOwnPropDescs$
|
|
426
|
-
var __getOwnPropSymbols$
|
|
427
|
-
var __hasOwnProp$
|
|
428
|
-
var __propIsEnum$
|
|
429
|
-
var __defNormalProp$
|
|
430
|
-
var __spreadValues$
|
|
394
|
+
var __defProp$4 = Object.defineProperty;
|
|
395
|
+
var __defProps$3 = Object.defineProperties;
|
|
396
|
+
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
397
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
398
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
399
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
400
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
401
|
+
var __spreadValues$4 = (a, b) => {
|
|
431
402
|
for (var prop in b || (b = {}))
|
|
432
|
-
if (__hasOwnProp$
|
|
433
|
-
__defNormalProp$
|
|
434
|
-
if (__getOwnPropSymbols$
|
|
435
|
-
for (var prop of __getOwnPropSymbols$
|
|
436
|
-
if (__propIsEnum$
|
|
437
|
-
__defNormalProp$
|
|
403
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
404
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
405
|
+
if (__getOwnPropSymbols$4)
|
|
406
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
407
|
+
if (__propIsEnum$4.call(b, prop))
|
|
408
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
438
409
|
}
|
|
439
410
|
return a;
|
|
440
411
|
};
|
|
441
|
-
var __spreadProps$
|
|
412
|
+
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
442
413
|
const types = Object.assign(Object.create(columnTypes), {
|
|
443
414
|
raw
|
|
444
415
|
});
|
|
@@ -469,14 +440,14 @@ const makeAst$1 = (up, tableName, shape, tableData, options, noPrimaryKey) => {
|
|
|
469
440
|
}
|
|
470
441
|
const primaryKey = tableData.primaryKey;
|
|
471
442
|
const [schema, table] = getSchemaAndTableFromName(tableName);
|
|
472
|
-
return __spreadProps$
|
|
443
|
+
return __spreadProps$3(__spreadValues$4(__spreadProps$3(__spreadValues$4({
|
|
473
444
|
type: "table",
|
|
474
445
|
action: up ? "create" : "drop",
|
|
475
446
|
schema,
|
|
476
447
|
name: table,
|
|
477
448
|
shape
|
|
478
449
|
}, tableData), {
|
|
479
|
-
primaryKey: shapePKeys.length <= 1 ? primaryKey : primaryKey ? __spreadProps$
|
|
450
|
+
primaryKey: shapePKeys.length <= 1 ? primaryKey : primaryKey ? __spreadProps$3(__spreadValues$4({}, primaryKey), { columns: [...shapePKeys, ...primaryKey.columns] }) : { columns: shapePKeys }
|
|
480
451
|
}), options), {
|
|
481
452
|
noPrimaryKey: options.noPrimaryKey ? "ignore" : noPrimaryKey || "error"
|
|
482
453
|
});
|
|
@@ -550,25 +521,25 @@ const astToQueries$1 = (ast) => {
|
|
|
550
521
|
return result;
|
|
551
522
|
};
|
|
552
523
|
|
|
553
|
-
var __defProp$
|
|
554
|
-
var __defProps$
|
|
555
|
-
var __getOwnPropDescs$
|
|
556
|
-
var __getOwnPropSymbols$
|
|
557
|
-
var __hasOwnProp$
|
|
558
|
-
var __propIsEnum$
|
|
559
|
-
var __defNormalProp$
|
|
560
|
-
var __spreadValues$
|
|
524
|
+
var __defProp$3 = Object.defineProperty;
|
|
525
|
+
var __defProps$2 = Object.defineProperties;
|
|
526
|
+
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
527
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
528
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
529
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
530
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
531
|
+
var __spreadValues$3 = (a, b) => {
|
|
561
532
|
for (var prop in b || (b = {}))
|
|
562
|
-
if (__hasOwnProp$
|
|
563
|
-
__defNormalProp$
|
|
564
|
-
if (__getOwnPropSymbols$
|
|
565
|
-
for (var prop of __getOwnPropSymbols$
|
|
566
|
-
if (__propIsEnum$
|
|
567
|
-
__defNormalProp$
|
|
533
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
534
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
535
|
+
if (__getOwnPropSymbols$3)
|
|
536
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
537
|
+
if (__propIsEnum$3.call(b, prop))
|
|
538
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
568
539
|
}
|
|
569
540
|
return a;
|
|
570
541
|
};
|
|
571
|
-
var __spreadProps$
|
|
542
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
572
543
|
const newChangeTableData = () => ({
|
|
573
544
|
add: { indexes: [], foreignKeys: [] },
|
|
574
545
|
drop: { indexes: [], foreignKeys: [] }
|
|
@@ -584,7 +555,7 @@ const mergeTableData = (a, b) => {
|
|
|
584
555
|
} else {
|
|
585
556
|
a.primaryKey = {
|
|
586
557
|
columns: [...a.primaryKey.columns, ...b.primaryKey.columns],
|
|
587
|
-
options: __spreadValues$
|
|
558
|
+
options: __spreadValues$3(__spreadValues$3({}, a.primaryKey.options), b.primaryKey.options)
|
|
588
559
|
};
|
|
589
560
|
}
|
|
590
561
|
}
|
|
@@ -635,7 +606,7 @@ const columnTypeToColumnChange = (item) => {
|
|
|
635
606
|
if (foreignKeys == null ? void 0 : foreignKeys.some((it) => "fn" in it)) {
|
|
636
607
|
throw new Error("Callback in foreignKey is not allowed in migration");
|
|
637
608
|
}
|
|
638
|
-
return __spreadProps$
|
|
609
|
+
return __spreadProps$2(__spreadValues$3({
|
|
639
610
|
column: item,
|
|
640
611
|
type: item.toSQL(),
|
|
641
612
|
nullable: item.data.isNullable,
|
|
@@ -651,7 +622,7 @@ const tableChangeMethods = {
|
|
|
651
622
|
add,
|
|
652
623
|
drop,
|
|
653
624
|
change(from, to, options) {
|
|
654
|
-
return __spreadValues$
|
|
625
|
+
return __spreadValues$3({
|
|
655
626
|
type: "change",
|
|
656
627
|
from: columnTypeToColumnChange(from),
|
|
657
628
|
to: columnTypeToColumnChange(to)
|
|
@@ -701,18 +672,18 @@ const makeAst = (up, name, changeData, changeTableData2, options) => {
|
|
|
701
672
|
const item = changeData[key];
|
|
702
673
|
if ("type" in item) {
|
|
703
674
|
if (up) {
|
|
704
|
-
shape[key] = item.type === "change" && item.usingUp ? __spreadProps$
|
|
675
|
+
shape[key] = item.type === "change" && item.usingUp ? __spreadProps$2(__spreadValues$3({}, item), { using: item.usingUp }) : item;
|
|
705
676
|
} else {
|
|
706
677
|
if (item.type === "rename") {
|
|
707
|
-
shape[item.name] = __spreadProps$
|
|
678
|
+
shape[item.name] = __spreadProps$2(__spreadValues$3({}, item), { name: key });
|
|
708
679
|
} else {
|
|
709
|
-
shape[key] = item.type === "add" ? __spreadProps$
|
|
680
|
+
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;
|
|
710
681
|
}
|
|
711
682
|
}
|
|
712
683
|
}
|
|
713
684
|
}
|
|
714
685
|
const [schema, table] = getSchemaAndTableFromName(name);
|
|
715
|
-
return __spreadValues$
|
|
686
|
+
return __spreadValues$3({
|
|
716
687
|
type: "changeTable",
|
|
717
688
|
schema,
|
|
718
689
|
name: table,
|
|
@@ -729,10 +700,10 @@ const astToQueries = (ast) => {
|
|
|
729
700
|
values: []
|
|
730
701
|
});
|
|
731
702
|
}
|
|
732
|
-
const addPrimaryKeys = ast.add.primaryKey ? __spreadValues$
|
|
703
|
+
const addPrimaryKeys = ast.add.primaryKey ? __spreadValues$3({}, ast.add.primaryKey) : {
|
|
733
704
|
columns: []
|
|
734
705
|
};
|
|
735
|
-
const dropPrimaryKeys = ast.drop.primaryKey ? __spreadValues$
|
|
706
|
+
const dropPrimaryKeys = ast.drop.primaryKey ? __spreadValues$3({}, ast.drop.primaryKey) : {
|
|
736
707
|
columns: []
|
|
737
708
|
};
|
|
738
709
|
for (const key in ast.shape) {
|
|
@@ -840,7 +811,7 @@ const astToQueries = (ast) => {
|
|
|
840
811
|
if (fromIndex) {
|
|
841
812
|
dropIndexes.push({
|
|
842
813
|
columns: [
|
|
843
|
-
__spreadValues$
|
|
814
|
+
__spreadValues$3({
|
|
844
815
|
column: key
|
|
845
816
|
}, fromIndex)
|
|
846
817
|
],
|
|
@@ -850,7 +821,7 @@ const astToQueries = (ast) => {
|
|
|
850
821
|
if (toIndex) {
|
|
851
822
|
addIndexes.push({
|
|
852
823
|
columns: [
|
|
853
|
-
__spreadValues$
|
|
824
|
+
__spreadValues$3({
|
|
854
825
|
column: key
|
|
855
826
|
}, toIndex)
|
|
856
827
|
],
|
|
@@ -900,98 +871,6 @@ const astToQueries = (ast) => {
|
|
|
900
871
|
return result;
|
|
901
872
|
};
|
|
902
873
|
|
|
903
|
-
var __defProp$3 = Object.defineProperty;
|
|
904
|
-
var __defProps$2 = Object.defineProperties;
|
|
905
|
-
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
906
|
-
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
907
|
-
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
908
|
-
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
909
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
910
|
-
var __spreadValues$3 = (a, b) => {
|
|
911
|
-
for (var prop in b || (b = {}))
|
|
912
|
-
if (__hasOwnProp$3.call(b, prop))
|
|
913
|
-
__defNormalProp$3(a, prop, b[prop]);
|
|
914
|
-
if (__getOwnPropSymbols$3)
|
|
915
|
-
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
916
|
-
if (__propIsEnum$3.call(b, prop))
|
|
917
|
-
__defNormalProp$3(a, prop, b[prop]);
|
|
918
|
-
}
|
|
919
|
-
return a;
|
|
920
|
-
};
|
|
921
|
-
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
922
|
-
class UnknownColumn extends ColumnType {
|
|
923
|
-
constructor(dataType) {
|
|
924
|
-
super();
|
|
925
|
-
this.dataType = dataType;
|
|
926
|
-
this.operators = Operators.any;
|
|
927
|
-
}
|
|
928
|
-
toCode() {
|
|
929
|
-
return "unknown";
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
const createJoinTable = async (migration, up, tables, options, fn) => {
|
|
933
|
-
const tableName = options.tableName || joinWords(...tables);
|
|
934
|
-
if (!up) {
|
|
935
|
-
return createTable$1(
|
|
936
|
-
migration,
|
|
937
|
-
up,
|
|
938
|
-
tableName,
|
|
939
|
-
__spreadProps$2(__spreadValues$3({}, options), { noPrimaryKey: true }),
|
|
940
|
-
() => ({})
|
|
941
|
-
);
|
|
942
|
-
}
|
|
943
|
-
const tablesWithPrimaryKeys = await Promise.all(
|
|
944
|
-
tables.map(async (table) => {
|
|
945
|
-
const primaryKeys = await getPrimaryKeysOfTable(migration, table).then(
|
|
946
|
-
(items) => items.map((item) => __spreadProps$2(__spreadValues$3({}, item), {
|
|
947
|
-
joinedName: joinWords(singular(table), item.name)
|
|
948
|
-
}))
|
|
949
|
-
);
|
|
950
|
-
const [schema, name] = getSchemaAndTableFromName(table);
|
|
951
|
-
if (!primaryKeys.length) {
|
|
952
|
-
throw new Error(
|
|
953
|
-
`Primary key for table ${quoteWithSchema({
|
|
954
|
-
schema,
|
|
955
|
-
name
|
|
956
|
-
})} is not defined`
|
|
957
|
-
);
|
|
958
|
-
}
|
|
959
|
-
return [schema, table, primaryKeys];
|
|
960
|
-
})
|
|
961
|
-
);
|
|
962
|
-
return createTable$1(migration, up, tableName, options, (t) => {
|
|
963
|
-
const result = {};
|
|
964
|
-
tablesWithPrimaryKeys.forEach(([schema, table, primaryKeys]) => {
|
|
965
|
-
if (primaryKeys.length === 1) {
|
|
966
|
-
const [{ type, joinedName, name }] = primaryKeys;
|
|
967
|
-
const column = new UnknownColumn(type);
|
|
968
|
-
result[joinedName] = column.foreignKey(
|
|
969
|
-
schema ? `${schema}.${table}` : table,
|
|
970
|
-
name
|
|
971
|
-
);
|
|
972
|
-
return;
|
|
973
|
-
}
|
|
974
|
-
primaryKeys.forEach(({ joinedName, type }) => {
|
|
975
|
-
result[joinedName] = new UnknownColumn(type);
|
|
976
|
-
});
|
|
977
|
-
t.foreignKey(
|
|
978
|
-
primaryKeys.map((key) => key.joinedName),
|
|
979
|
-
table,
|
|
980
|
-
primaryKeys.map((key) => key.name)
|
|
981
|
-
);
|
|
982
|
-
});
|
|
983
|
-
if (fn) {
|
|
984
|
-
Object.assign(result, fn(t));
|
|
985
|
-
}
|
|
986
|
-
t.primaryKey(
|
|
987
|
-
tablesWithPrimaryKeys.flatMap(
|
|
988
|
-
([, , primaryKeys]) => primaryKeys.map((item) => item.joinedName)
|
|
989
|
-
)
|
|
990
|
-
);
|
|
991
|
-
return result;
|
|
992
|
-
});
|
|
993
|
-
};
|
|
994
|
-
|
|
995
874
|
var __defProp$2 = Object.defineProperty;
|
|
996
875
|
var __defProps$1 = Object.defineProperties;
|
|
997
876
|
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
@@ -1036,16 +915,6 @@ class Migration extends TransactionAdapter {
|
|
|
1036
915
|
const fn = cb || cbOrOptions;
|
|
1037
916
|
return createTable$1(this, !this.up, tableName, options, fn);
|
|
1038
917
|
}
|
|
1039
|
-
async createJoinTable(tables, cbOrOptions, cb) {
|
|
1040
|
-
const options = typeof cbOrOptions === "function" ? {} : cbOrOptions || {};
|
|
1041
|
-
const fn = cb || cbOrOptions;
|
|
1042
|
-
return createJoinTable(this, this.up, tables, options, fn);
|
|
1043
|
-
}
|
|
1044
|
-
async dropJoinTable(tables, cbOrOptions, cb) {
|
|
1045
|
-
const options = typeof cbOrOptions === "function" ? {} : cbOrOptions || {};
|
|
1046
|
-
const fn = cb || cbOrOptions;
|
|
1047
|
-
return createJoinTable(this, !this.up, tables, options, fn);
|
|
1048
|
-
}
|
|
1049
918
|
changeTable(tableName, cbOrOptions, cb) {
|
|
1050
919
|
const [fn, options] = typeof cbOrOptions === "function" ? [cbOrOptions, {}] : [cb, cbOrOptions];
|
|
1051
920
|
return changeTable(this, this.up, tableName, options, fn);
|