rake-db 2.7.1 → 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 +26 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -262,13 +262,18 @@ declare namespace RakeDbAst {
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
type Db = DbResult<DefaultColumnTypes>;
|
|
265
|
-
type
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
265
|
+
type BaseTable<CT extends ColumnTypesBase> = {
|
|
266
|
+
name: string;
|
|
267
|
+
filePath: string;
|
|
268
|
+
new (): {
|
|
269
269
|
columnTypes: CT;
|
|
270
270
|
snakeCase?: boolean;
|
|
271
271
|
};
|
|
272
|
+
};
|
|
273
|
+
type InputRakeDbConfig<CT extends ColumnTypesBase> = Partial<Omit<RakeDbConfig<CT>, 'columnTypes'>> & ({
|
|
274
|
+
columnTypes?: CT | ((t: DefaultColumnTypes) => CT);
|
|
275
|
+
} | {
|
|
276
|
+
baseTable?: BaseTable<CT>;
|
|
272
277
|
});
|
|
273
278
|
type RakeDbConfig<CT extends ColumnTypesBase = DefaultColumnTypes> = {
|
|
274
279
|
columnTypes: CT;
|
|
@@ -280,6 +285,7 @@ type RakeDbConfig<CT extends ColumnTypesBase = DefaultColumnTypes> = {
|
|
|
280
285
|
commands: Record<string, (options: AdapterOptions[], config: RakeDbConfig<CT>, args: string[]) => Promise<void>>;
|
|
281
286
|
import(path: string): Promise<void>;
|
|
282
287
|
noPrimaryKey?: NoPrimaryKeyOption;
|
|
288
|
+
baseTable?: BaseTable<CT>;
|
|
283
289
|
appCodeUpdater?: AppCodeUpdater;
|
|
284
290
|
useCodeUpdater?: boolean;
|
|
285
291
|
beforeMigrate?(db: Db): Promise<void>;
|
|
@@ -293,6 +299,10 @@ type AppCodeUpdater = (params: {
|
|
|
293
299
|
basePath: string;
|
|
294
300
|
cache: object;
|
|
295
301
|
logger: QueryLogOptions['logger'];
|
|
302
|
+
baseTable: {
|
|
303
|
+
filePath: string;
|
|
304
|
+
name: string;
|
|
305
|
+
};
|
|
296
306
|
}) => Promise<void>;
|
|
297
307
|
|
|
298
308
|
declare const createDb: <CT extends ColumnTypesBase>(arg: MaybeArray<AdapterOptions>, config: RakeDbConfig<CT>) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -50,49 +50,39 @@ const migrationConfigDefaults = {
|
|
|
50
50
|
migrationsTable: "schemaMigrations",
|
|
51
51
|
snakeCase: false,
|
|
52
52
|
commands: {},
|
|
53
|
-
import: (path2) =>
|
|
53
|
+
import: (path2) => {
|
|
54
|
+
return import(path2).catch((err) => {
|
|
55
|
+
if (err.code === "ERR_UNKNOWN_FILE_EXTENSION") {
|
|
56
|
+
require(path2);
|
|
57
|
+
} else {
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
},
|
|
54
62
|
log: true,
|
|
55
63
|
logger: console,
|
|
56
64
|
useCodeUpdater: true
|
|
57
65
|
};
|
|
58
66
|
const processRakeDbConfig = (config) => {
|
|
59
|
-
var _a
|
|
67
|
+
var _a;
|
|
60
68
|
const result = __spreadValues$6(__spreadValues$6({}, migrationConfigDefaults), config);
|
|
69
|
+
if (config.appCodeUpdater && (!("baseTable" in config) || !config.baseTable)) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
"`baseTable` option is required in `rakeDb` for `appCodeUpdater`"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
61
74
|
if (!result.log) {
|
|
62
75
|
delete result.logger;
|
|
63
76
|
}
|
|
64
77
|
if (!result.basePath || !result.dbScript) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
Error.prepareStackTrace = (_, s) => stack = s;
|
|
68
|
-
new Error().stack;
|
|
69
|
-
Error.prepareStackTrace = original;
|
|
70
|
-
if (stack) {
|
|
71
|
-
const thisFile = (_a = stack[0]) == null ? void 0 : _a.getFileName();
|
|
72
|
-
const thisDir = thisFile && path.dirname(thisFile);
|
|
73
|
-
for (const item of stack) {
|
|
74
|
-
let file = item.getFileName();
|
|
75
|
-
if (!file || path.dirname(file) === thisDir || /\bnode_modules\b/.test(file)) {
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if (/file:\/\/\/\w+:\//.test(file)) {
|
|
79
|
-
file = decodeURI(file.slice(8));
|
|
80
|
-
} else {
|
|
81
|
-
try {
|
|
82
|
-
file = new URL(file).pathname;
|
|
83
|
-
} catch (_) {
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
result.basePath = path.dirname(file);
|
|
87
|
-
result.dbScript = path.basename(file);
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (!result.basePath) {
|
|
78
|
+
const filePath = orchidCore.getCallerFilePath();
|
|
79
|
+
if (!filePath) {
|
|
92
80
|
throw new Error(
|
|
93
81
|
"Failed to determine path to db script. Please set basePath option of rakeDb"
|
|
94
82
|
);
|
|
95
83
|
}
|
|
84
|
+
result.basePath = path.dirname(filePath);
|
|
85
|
+
result.dbScript = path.basename(filePath);
|
|
96
86
|
}
|
|
97
87
|
if (!path.isAbsolute(result.migrationsPath)) {
|
|
98
88
|
result.migrationsPath = path.resolve(
|
|
@@ -101,7 +91,7 @@ const processRakeDbConfig = (config) => {
|
|
|
101
91
|
);
|
|
102
92
|
}
|
|
103
93
|
if ("baseTable" in config) {
|
|
104
|
-
const proto = (
|
|
94
|
+
const proto = (_a = config.baseTable) == null ? void 0 : _a.prototype;
|
|
105
95
|
result.columnTypes = proto.columnTypes || pqb.columnTypes;
|
|
106
96
|
if (proto.snakeCase)
|
|
107
97
|
result.snakeCase = true;
|
|
@@ -1733,7 +1723,9 @@ const processMigration = async (db, up, file, config, options, appCodeUpdaterCac
|
|
|
1733
1723
|
options,
|
|
1734
1724
|
basePath: config.basePath,
|
|
1735
1725
|
cache: appCodeUpdaterCache,
|
|
1736
|
-
logger: config.logger
|
|
1726
|
+
logger: config.logger,
|
|
1727
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1728
|
+
baseTable: config.baseTable
|
|
1737
1729
|
}));
|
|
1738
1730
|
}
|
|
1739
1731
|
};
|
|
@@ -3007,7 +2999,9 @@ const pullDbStructure = async (options, config) => {
|
|
|
3007
2999
|
options,
|
|
3008
3000
|
basePath: config.basePath,
|
|
3009
3001
|
cache,
|
|
3010
|
-
logger: config.logger
|
|
3002
|
+
logger: config.logger,
|
|
3003
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
3004
|
+
baseTable: config.baseTable
|
|
3011
3005
|
}));
|
|
3012
3006
|
}
|
|
3013
3007
|
const unsupportedEntries = Object.entries(ctx.unsupportedTypes);
|