rake-db 2.7.2 → 2.8.0
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.d.ts +14 -4
- package/dist/index.js +17 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { columnTypes, quote, getRaw, EnumColumn, getColumnTypes, getTableData, ColumnType, resetTableData, UnknownColumn, TransactionAdapter, logParamToLogObject, createDb as createDb$1, Adapter, simplifyColumnDefault, columnsByType, instantiateColumn, DomainColumn, CustomTypeColumn, ArrayColumn, getConstraintKind, primaryKeyToCode, indexToCode, constraintToCode, TimestampTzColumn, referencesArgsToCode, constraintPropsToCode } from 'pqb';
|
|
2
|
-
import { singleQuote, toSnakeCase, isRaw, toArray, snakeCaseKey, nameKey, emptyObject, deepCompare, raw, pathToLog, emptyArray, getImportPath, toCamelCase, codeToString, addCode, rawToCode, quoteObjectKey, backtickQuote } from 'orchid-core';
|
|
2
|
+
import { getCallerFilePath, singleQuote, toSnakeCase, isRaw, toArray, snakeCaseKey, nameKey, emptyObject, deepCompare, raw, pathToLog, emptyArray, getImportPath, toCamelCase, codeToString, addCode, rawToCode, quoteObjectKey, backtickQuote } from 'orchid-core';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { readdir, mkdir, writeFile } from 'fs/promises';
|
|
5
5
|
import prompts from 'prompts';
|
|
@@ -43,43 +43,25 @@ const migrationConfigDefaults = {
|
|
|
43
43
|
useCodeUpdater: true
|
|
44
44
|
};
|
|
45
45
|
const processRakeDbConfig = (config) => {
|
|
46
|
-
var _a
|
|
46
|
+
var _a;
|
|
47
47
|
const result = __spreadValues$6(__spreadValues$6({}, migrationConfigDefaults), config);
|
|
48
|
+
if (config.appCodeUpdater && (!("baseTable" in config) || !config.baseTable)) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
"`baseTable` option is required in `rakeDb` for `appCodeUpdater`"
|
|
51
|
+
);
|
|
52
|
+
}
|
|
48
53
|
if (!result.log) {
|
|
49
54
|
delete result.logger;
|
|
50
55
|
}
|
|
51
56
|
if (!result.basePath || !result.dbScript) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
Error.prepareStackTrace = (_, s) => stack = s;
|
|
55
|
-
new Error().stack;
|
|
56
|
-
Error.prepareStackTrace = original;
|
|
57
|
-
if (stack) {
|
|
58
|
-
const thisFile = (_a = stack[0]) == null ? void 0 : _a.getFileName();
|
|
59
|
-
const thisDir = thisFile && path.dirname(thisFile);
|
|
60
|
-
for (const item of stack) {
|
|
61
|
-
let file = item.getFileName();
|
|
62
|
-
if (!file || path.dirname(file) === thisDir || /\bnode_modules\b/.test(file)) {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
if (/file:\/\/\/\w+:\//.test(file)) {
|
|
66
|
-
file = decodeURI(file.slice(8));
|
|
67
|
-
} else {
|
|
68
|
-
try {
|
|
69
|
-
file = new URL(file).pathname;
|
|
70
|
-
} catch (_) {
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
result.basePath = path.dirname(file);
|
|
74
|
-
result.dbScript = path.basename(file);
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (!result.basePath) {
|
|
57
|
+
const filePath = getCallerFilePath();
|
|
58
|
+
if (!filePath) {
|
|
79
59
|
throw new Error(
|
|
80
60
|
"Failed to determine path to db script. Please set basePath option of rakeDb"
|
|
81
61
|
);
|
|
82
62
|
}
|
|
63
|
+
result.basePath = path.dirname(filePath);
|
|
64
|
+
result.dbScript = path.basename(filePath);
|
|
83
65
|
}
|
|
84
66
|
if (!path.isAbsolute(result.migrationsPath)) {
|
|
85
67
|
result.migrationsPath = path.resolve(
|
|
@@ -88,7 +70,7 @@ const processRakeDbConfig = (config) => {
|
|
|
88
70
|
);
|
|
89
71
|
}
|
|
90
72
|
if ("baseTable" in config) {
|
|
91
|
-
const proto = (
|
|
73
|
+
const proto = (_a = config.baseTable) == null ? void 0 : _a.prototype;
|
|
92
74
|
result.columnTypes = proto.columnTypes || columnTypes;
|
|
93
75
|
if (proto.snakeCase)
|
|
94
76
|
result.snakeCase = true;
|
|
@@ -1720,7 +1702,9 @@ const processMigration = async (db, up, file, config, options, appCodeUpdaterCac
|
|
|
1720
1702
|
options,
|
|
1721
1703
|
basePath: config.basePath,
|
|
1722
1704
|
cache: appCodeUpdaterCache,
|
|
1723
|
-
logger: config.logger
|
|
1705
|
+
logger: config.logger,
|
|
1706
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1707
|
+
baseTable: config.baseTable
|
|
1724
1708
|
}));
|
|
1725
1709
|
}
|
|
1726
1710
|
};
|
|
@@ -2994,7 +2978,9 @@ const pullDbStructure = async (options, config) => {
|
|
|
2994
2978
|
options,
|
|
2995
2979
|
basePath: config.basePath,
|
|
2996
2980
|
cache,
|
|
2997
|
-
logger: config.logger
|
|
2981
|
+
logger: config.logger,
|
|
2982
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
2983
|
+
baseTable: config.baseTable
|
|
2998
2984
|
}));
|
|
2999
2985
|
}
|
|
3000
2986
|
const unsupportedEntries = Object.entries(ctx.unsupportedTypes);
|