rake-db 2.3.2 → 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 +12 -0
- package/dist/index.d.ts +0 -4
- package/dist/index.esm.js +95 -219
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +94 -218
- package/dist/index.js.map +1 -1
- package/migrations/20221017200326_createChatUser.ts +1 -1
- package/package.json +1 -1
- package/src/migration/changeTable.test.ts +10 -10
- package/src/migration/createTable.test.ts +1 -1
- package/src/migration/migration.ts +0 -35
- package/src/migration/migrationUtils.ts +19 -11
- package/src/pull/structureToAst.test.ts +100 -0
- package/src/pull/structureToAst.ts +19 -4
- 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
|
);
|
|
@@ -284,8 +277,11 @@ const getForeignKeyTable = (fnOrTable) => {
|
|
|
284
277
|
const item = new (fnOrTable())();
|
|
285
278
|
return [item.schema, item.table];
|
|
286
279
|
};
|
|
280
|
+
const getForeignKeyName = (table, columns) => {
|
|
281
|
+
return `${table}_${columns.join("_")}_fkey`;
|
|
282
|
+
};
|
|
287
283
|
const constraintToSql = ({ name }, up, foreignKey) => {
|
|
288
|
-
const constraintName = foreignKey.options.name ||
|
|
284
|
+
const constraintName = foreignKey.options.name || getForeignKeyName(name, foreignKey.columns);
|
|
289
285
|
if (!up) {
|
|
290
286
|
const { dropMode } = foreignKey.options;
|
|
291
287
|
return `CONSTRAINT "${constraintName}"${dropMode ? ` ${dropMode}` : ""}`;
|
|
@@ -317,13 +313,17 @@ const referencesToSql = (schema, table, columns, foreignKey) => {
|
|
|
317
313
|
}
|
|
318
314
|
return sql.join(" ");
|
|
319
315
|
};
|
|
316
|
+
const getIndexName = (table, columns) => {
|
|
317
|
+
return `${table}_${columns.map(
|
|
318
|
+
(it) => {
|
|
319
|
+
var _a;
|
|
320
|
+
return "column" in it ? it.column : ((_a = it.expression.match(/\w+/g)) == null ? void 0 : _a.join("_")) || "expression";
|
|
321
|
+
}
|
|
322
|
+
).join("_")}_idx`;
|
|
323
|
+
};
|
|
320
324
|
const indexesToQuery = (up, { schema, name }, indexes) => {
|
|
321
325
|
return indexes.map(({ columns, options }) => {
|
|
322
|
-
const indexName = options.name ||
|
|
323
|
-
name,
|
|
324
|
-
...columns.filter((it) => "column" in it).map((it) => it.column),
|
|
325
|
-
"index"
|
|
326
|
-
);
|
|
326
|
+
const indexName = options.name || getIndexName(name, columns);
|
|
327
327
|
if (!up) {
|
|
328
328
|
return {
|
|
329
329
|
text: `DROP INDEX "${indexName}"${options.dropMode ? ` ${options.dropMode}` : ""}`,
|
|
@@ -390,48 +390,26 @@ const primaryKeyToSql = (primaryKey) => {
|
|
|
390
390
|
primaryKey.columns
|
|
391
391
|
)})`;
|
|
392
392
|
};
|
|
393
|
-
const getPrimaryKeysOfTable = async (db, tableName) => {
|
|
394
|
-
const { rows } = await db.query(
|
|
395
|
-
{
|
|
396
|
-
text: `SELECT
|
|
397
|
-
pg_attribute.attname AS name,
|
|
398
|
-
format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS type
|
|
399
|
-
FROM pg_index, pg_class, pg_attribute, pg_namespace
|
|
400
|
-
WHERE
|
|
401
|
-
pg_class.oid = $1::regclass AND
|
|
402
|
-
indrelid = pg_class.oid AND
|
|
403
|
-
nspname = 'public' AND
|
|
404
|
-
pg_class.relnamespace = pg_namespace.oid AND
|
|
405
|
-
pg_attribute.attrelid = pg_class.oid AND
|
|
406
|
-
pg_attribute.attnum = any(pg_index.indkey) AND
|
|
407
|
-
indisprimary`,
|
|
408
|
-
values: [tableName]
|
|
409
|
-
},
|
|
410
|
-
db.types,
|
|
411
|
-
void 0
|
|
412
|
-
);
|
|
413
|
-
return rows;
|
|
414
|
-
};
|
|
415
393
|
|
|
416
|
-
var __defProp$
|
|
417
|
-
var __defProps$
|
|
418
|
-
var __getOwnPropDescs$
|
|
419
|
-
var __getOwnPropSymbols$
|
|
420
|
-
var __hasOwnProp$
|
|
421
|
-
var __propIsEnum$
|
|
422
|
-
var __defNormalProp$
|
|
423
|
-
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) => {
|
|
424
402
|
for (var prop in b || (b = {}))
|
|
425
|
-
if (__hasOwnProp$
|
|
426
|
-
__defNormalProp$
|
|
427
|
-
if (__getOwnPropSymbols$
|
|
428
|
-
for (var prop of __getOwnPropSymbols$
|
|
429
|
-
if (__propIsEnum$
|
|
430
|
-
__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]);
|
|
431
409
|
}
|
|
432
410
|
return a;
|
|
433
411
|
};
|
|
434
|
-
var __spreadProps$
|
|
412
|
+
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
435
413
|
const types = Object.assign(Object.create(columnTypes), {
|
|
436
414
|
raw
|
|
437
415
|
});
|
|
@@ -462,14 +440,14 @@ const makeAst$1 = (up, tableName, shape, tableData, options, noPrimaryKey) => {
|
|
|
462
440
|
}
|
|
463
441
|
const primaryKey = tableData.primaryKey;
|
|
464
442
|
const [schema, table] = getSchemaAndTableFromName(tableName);
|
|
465
|
-
return __spreadProps$
|
|
443
|
+
return __spreadProps$3(__spreadValues$4(__spreadProps$3(__spreadValues$4({
|
|
466
444
|
type: "table",
|
|
467
445
|
action: up ? "create" : "drop",
|
|
468
446
|
schema,
|
|
469
447
|
name: table,
|
|
470
448
|
shape
|
|
471
449
|
}, tableData), {
|
|
472
|
-
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 }
|
|
473
451
|
}), options), {
|
|
474
452
|
noPrimaryKey: options.noPrimaryKey ? "ignore" : noPrimaryKey || "error"
|
|
475
453
|
});
|
|
@@ -543,25 +521,25 @@ const astToQueries$1 = (ast) => {
|
|
|
543
521
|
return result;
|
|
544
522
|
};
|
|
545
523
|
|
|
546
|
-
var __defProp$
|
|
547
|
-
var __defProps$
|
|
548
|
-
var __getOwnPropDescs$
|
|
549
|
-
var __getOwnPropSymbols$
|
|
550
|
-
var __hasOwnProp$
|
|
551
|
-
var __propIsEnum$
|
|
552
|
-
var __defNormalProp$
|
|
553
|
-
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) => {
|
|
554
532
|
for (var prop in b || (b = {}))
|
|
555
|
-
if (__hasOwnProp$
|
|
556
|
-
__defNormalProp$
|
|
557
|
-
if (__getOwnPropSymbols$
|
|
558
|
-
for (var prop of __getOwnPropSymbols$
|
|
559
|
-
if (__propIsEnum$
|
|
560
|
-
__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]);
|
|
561
539
|
}
|
|
562
540
|
return a;
|
|
563
541
|
};
|
|
564
|
-
var __spreadProps$
|
|
542
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
565
543
|
const newChangeTableData = () => ({
|
|
566
544
|
add: { indexes: [], foreignKeys: [] },
|
|
567
545
|
drop: { indexes: [], foreignKeys: [] }
|
|
@@ -577,7 +555,7 @@ const mergeTableData = (a, b) => {
|
|
|
577
555
|
} else {
|
|
578
556
|
a.primaryKey = {
|
|
579
557
|
columns: [...a.primaryKey.columns, ...b.primaryKey.columns],
|
|
580
|
-
options: __spreadValues$
|
|
558
|
+
options: __spreadValues$3(__spreadValues$3({}, a.primaryKey.options), b.primaryKey.options)
|
|
581
559
|
};
|
|
582
560
|
}
|
|
583
561
|
}
|
|
@@ -628,7 +606,7 @@ const columnTypeToColumnChange = (item) => {
|
|
|
628
606
|
if (foreignKeys == null ? void 0 : foreignKeys.some((it) => "fn" in it)) {
|
|
629
607
|
throw new Error("Callback in foreignKey is not allowed in migration");
|
|
630
608
|
}
|
|
631
|
-
return __spreadProps$
|
|
609
|
+
return __spreadProps$2(__spreadValues$3({
|
|
632
610
|
column: item,
|
|
633
611
|
type: item.toSQL(),
|
|
634
612
|
nullable: item.data.isNullable,
|
|
@@ -644,7 +622,7 @@ const tableChangeMethods = {
|
|
|
644
622
|
add,
|
|
645
623
|
drop,
|
|
646
624
|
change(from, to, options) {
|
|
647
|
-
return __spreadValues$
|
|
625
|
+
return __spreadValues$3({
|
|
648
626
|
type: "change",
|
|
649
627
|
from: columnTypeToColumnChange(from),
|
|
650
628
|
to: columnTypeToColumnChange(to)
|
|
@@ -694,18 +672,18 @@ const makeAst = (up, name, changeData, changeTableData2, options) => {
|
|
|
694
672
|
const item = changeData[key];
|
|
695
673
|
if ("type" in item) {
|
|
696
674
|
if (up) {
|
|
697
|
-
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;
|
|
698
676
|
} else {
|
|
699
677
|
if (item.type === "rename") {
|
|
700
|
-
shape[item.name] = __spreadProps$
|
|
678
|
+
shape[item.name] = __spreadProps$2(__spreadValues$3({}, item), { name: key });
|
|
701
679
|
} else {
|
|
702
|
-
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;
|
|
703
681
|
}
|
|
704
682
|
}
|
|
705
683
|
}
|
|
706
684
|
}
|
|
707
685
|
const [schema, table] = getSchemaAndTableFromName(name);
|
|
708
|
-
return __spreadValues$
|
|
686
|
+
return __spreadValues$3({
|
|
709
687
|
type: "changeTable",
|
|
710
688
|
schema,
|
|
711
689
|
name: table,
|
|
@@ -722,10 +700,10 @@ const astToQueries = (ast) => {
|
|
|
722
700
|
values: []
|
|
723
701
|
});
|
|
724
702
|
}
|
|
725
|
-
const addPrimaryKeys = ast.add.primaryKey ? __spreadValues$
|
|
703
|
+
const addPrimaryKeys = ast.add.primaryKey ? __spreadValues$3({}, ast.add.primaryKey) : {
|
|
726
704
|
columns: []
|
|
727
705
|
};
|
|
728
|
-
const dropPrimaryKeys = ast.drop.primaryKey ? __spreadValues$
|
|
706
|
+
const dropPrimaryKeys = ast.drop.primaryKey ? __spreadValues$3({}, ast.drop.primaryKey) : {
|
|
729
707
|
columns: []
|
|
730
708
|
};
|
|
731
709
|
for (const key in ast.shape) {
|
|
@@ -833,7 +811,7 @@ const astToQueries = (ast) => {
|
|
|
833
811
|
if (fromIndex) {
|
|
834
812
|
dropIndexes.push({
|
|
835
813
|
columns: [
|
|
836
|
-
__spreadValues$
|
|
814
|
+
__spreadValues$3({
|
|
837
815
|
column: key
|
|
838
816
|
}, fromIndex)
|
|
839
817
|
],
|
|
@@ -843,7 +821,7 @@ const astToQueries = (ast) => {
|
|
|
843
821
|
if (toIndex) {
|
|
844
822
|
addIndexes.push({
|
|
845
823
|
columns: [
|
|
846
|
-
__spreadValues$
|
|
824
|
+
__spreadValues$3({
|
|
847
825
|
column: key
|
|
848
826
|
}, toIndex)
|
|
849
827
|
],
|
|
@@ -893,98 +871,6 @@ const astToQueries = (ast) => {
|
|
|
893
871
|
return result;
|
|
894
872
|
};
|
|
895
873
|
|
|
896
|
-
var __defProp$3 = Object.defineProperty;
|
|
897
|
-
var __defProps$2 = Object.defineProperties;
|
|
898
|
-
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
899
|
-
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
900
|
-
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
901
|
-
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
902
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
903
|
-
var __spreadValues$3 = (a, b) => {
|
|
904
|
-
for (var prop in b || (b = {}))
|
|
905
|
-
if (__hasOwnProp$3.call(b, prop))
|
|
906
|
-
__defNormalProp$3(a, prop, b[prop]);
|
|
907
|
-
if (__getOwnPropSymbols$3)
|
|
908
|
-
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
909
|
-
if (__propIsEnum$3.call(b, prop))
|
|
910
|
-
__defNormalProp$3(a, prop, b[prop]);
|
|
911
|
-
}
|
|
912
|
-
return a;
|
|
913
|
-
};
|
|
914
|
-
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
915
|
-
class UnknownColumn extends ColumnType {
|
|
916
|
-
constructor(dataType) {
|
|
917
|
-
super();
|
|
918
|
-
this.dataType = dataType;
|
|
919
|
-
this.operators = Operators.any;
|
|
920
|
-
}
|
|
921
|
-
toCode() {
|
|
922
|
-
return "unknown";
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
const createJoinTable = async (migration, up, tables, options, fn) => {
|
|
926
|
-
const tableName = options.tableName || joinWords(...tables);
|
|
927
|
-
if (!up) {
|
|
928
|
-
return createTable$1(
|
|
929
|
-
migration,
|
|
930
|
-
up,
|
|
931
|
-
tableName,
|
|
932
|
-
__spreadProps$2(__spreadValues$3({}, options), { noPrimaryKey: true }),
|
|
933
|
-
() => ({})
|
|
934
|
-
);
|
|
935
|
-
}
|
|
936
|
-
const tablesWithPrimaryKeys = await Promise.all(
|
|
937
|
-
tables.map(async (table) => {
|
|
938
|
-
const primaryKeys = await getPrimaryKeysOfTable(migration, table).then(
|
|
939
|
-
(items) => items.map((item) => __spreadProps$2(__spreadValues$3({}, item), {
|
|
940
|
-
joinedName: joinWords(singular(table), item.name)
|
|
941
|
-
}))
|
|
942
|
-
);
|
|
943
|
-
const [schema, name] = getSchemaAndTableFromName(table);
|
|
944
|
-
if (!primaryKeys.length) {
|
|
945
|
-
throw new Error(
|
|
946
|
-
`Primary key for table ${quoteWithSchema({
|
|
947
|
-
schema,
|
|
948
|
-
name
|
|
949
|
-
})} is not defined`
|
|
950
|
-
);
|
|
951
|
-
}
|
|
952
|
-
return [schema, table, primaryKeys];
|
|
953
|
-
})
|
|
954
|
-
);
|
|
955
|
-
return createTable$1(migration, up, tableName, options, (t) => {
|
|
956
|
-
const result = {};
|
|
957
|
-
tablesWithPrimaryKeys.forEach(([schema, table, primaryKeys]) => {
|
|
958
|
-
if (primaryKeys.length === 1) {
|
|
959
|
-
const [{ type, joinedName, name }] = primaryKeys;
|
|
960
|
-
const column = new UnknownColumn(type);
|
|
961
|
-
result[joinedName] = column.foreignKey(
|
|
962
|
-
schema ? `${schema}.${table}` : table,
|
|
963
|
-
name
|
|
964
|
-
);
|
|
965
|
-
return;
|
|
966
|
-
}
|
|
967
|
-
primaryKeys.forEach(({ joinedName, type }) => {
|
|
968
|
-
result[joinedName] = new UnknownColumn(type);
|
|
969
|
-
});
|
|
970
|
-
t.foreignKey(
|
|
971
|
-
primaryKeys.map((key) => key.joinedName),
|
|
972
|
-
table,
|
|
973
|
-
primaryKeys.map((key) => key.name)
|
|
974
|
-
);
|
|
975
|
-
});
|
|
976
|
-
if (fn) {
|
|
977
|
-
Object.assign(result, fn(t));
|
|
978
|
-
}
|
|
979
|
-
t.primaryKey(
|
|
980
|
-
tablesWithPrimaryKeys.flatMap(
|
|
981
|
-
([, , primaryKeys]) => primaryKeys.map((item) => item.joinedName)
|
|
982
|
-
)
|
|
983
|
-
);
|
|
984
|
-
return result;
|
|
985
|
-
});
|
|
986
|
-
};
|
|
987
|
-
|
|
988
874
|
var __defProp$2 = Object.defineProperty;
|
|
989
875
|
var __defProps$1 = Object.defineProperties;
|
|
990
876
|
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
@@ -1029,16 +915,6 @@ class Migration extends TransactionAdapter {
|
|
|
1029
915
|
const fn = cb || cbOrOptions;
|
|
1030
916
|
return createTable$1(this, !this.up, tableName, options, fn);
|
|
1031
917
|
}
|
|
1032
|
-
async createJoinTable(tables, cbOrOptions, cb) {
|
|
1033
|
-
const options = typeof cbOrOptions === "function" ? {} : cbOrOptions || {};
|
|
1034
|
-
const fn = cb || cbOrOptions;
|
|
1035
|
-
return createJoinTable(this, this.up, tables, options, fn);
|
|
1036
|
-
}
|
|
1037
|
-
async dropJoinTable(tables, cbOrOptions, cb) {
|
|
1038
|
-
const options = typeof cbOrOptions === "function" ? {} : cbOrOptions || {};
|
|
1039
|
-
const fn = cb || cbOrOptions;
|
|
1040
|
-
return createJoinTable(this, !this.up, tables, options, fn);
|
|
1041
|
-
}
|
|
1042
918
|
changeTable(tableName, cbOrOptions, cb) {
|
|
1043
919
|
const [fn, options] = typeof cbOrOptions === "function" ? [cbOrOptions, {}] : [cb, cbOrOptions];
|
|
1044
920
|
return changeTable(this, this.up, tableName, options, fn);
|
|
@@ -1837,7 +1713,7 @@ const structureToAst = async (db) => {
|
|
|
1837
1713
|
collate: options.collate,
|
|
1838
1714
|
opclass: options.opclass,
|
|
1839
1715
|
order: options.order,
|
|
1840
|
-
name: index.name,
|
|
1716
|
+
name: index.name !== getIndexName(name, index.columns) ? index.name : void 0,
|
|
1841
1717
|
using: index.using === "btree" ? void 0 : index.using,
|
|
1842
1718
|
unique: index.isUnique,
|
|
1843
1719
|
include: index.include,
|
|
@@ -1854,7 +1730,7 @@ const structureToAst = async (db) => {
|
|
|
1854
1730
|
foreignKey.foreignTableName,
|
|
1855
1731
|
foreignKey.foreignColumnNames[0],
|
|
1856
1732
|
{
|
|
1857
|
-
name: foreignKey.name,
|
|
1733
|
+
name: foreignKey.name && foreignKey.name !== getForeignKeyName(name, foreignKey.columnNames) ? foreignKey.name : void 0,
|
|
1858
1734
|
match: matchMap[foreignKey.match],
|
|
1859
1735
|
onUpdate: fkeyActionMap[foreignKey.onUpdate],
|
|
1860
1736
|
onDelete: fkeyActionMap[foreignKey.onDelete]
|
|
@@ -1884,7 +1760,7 @@ const structureToAst = async (db) => {
|
|
|
1884
1760
|
order: it.order
|
|
1885
1761
|
})),
|
|
1886
1762
|
options: {
|
|
1887
|
-
name: index.name,
|
|
1763
|
+
name: index.name !== getIndexName(name, index.columns) ? index.name : void 0,
|
|
1888
1764
|
using: index.using === "btree" ? void 0 : index.using,
|
|
1889
1765
|
unique: index.isUnique,
|
|
1890
1766
|
include: index.include,
|
|
@@ -1898,7 +1774,7 @@ const structureToAst = async (db) => {
|
|
|
1898
1774
|
fnOrTable: it.foreignTableName,
|
|
1899
1775
|
foreignColumns: it.foreignColumnNames,
|
|
1900
1776
|
options: {
|
|
1901
|
-
name: it.name,
|
|
1777
|
+
name: it.name && it.name !== getForeignKeyName(name, it.columnNames) ? it.name : void 0,
|
|
1902
1778
|
match: matchMap[it.match],
|
|
1903
1779
|
onUpdate: fkeyActionMap[it.onUpdate],
|
|
1904
1780
|
onDelete: fkeyActionMap[it.onDelete]
|