rake-db 2.3.16 → 2.3.18
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/.turbo/turbo-test.log +22 -0
- package/CHANGELOG.md +13 -0
- package/{db.ts → app/dbScript.ts} +5 -5
- package/{migrations → app/migrations}/20221017181504_createUser.ts +1 -1
- package/{migrations → app/migrations}/20221017200111_createProfile.ts +1 -1
- package/{migrations → app/migrations}/20221017200252_createChat.ts +1 -1
- package/{migrations → app/migrations}/20221017200326_createChatUser.ts +1 -1
- package/{migrations → app/migrations}/20221017200900_createMessage.ts +1 -1
- package/{migrations → app/migrations}/20221017201235_createGeoSchema.ts +1 -1
- package/{migrations → app/migrations}/20221017210011_createCountry.ts +1 -1
- package/{migrations → app/migrations}/20221017210133_createCity.ts +1 -1
- package/{migrations → app/migrations}/20221105202843_createUniqueTable.ts +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +39 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/commands/createOrDrop.ts +1 -1
- package/src/commands/generate.ts +1 -1
- package/src/commands/migrateOrRollback.test.ts +16 -13
- package/src/commands/migrateOrRollback.ts +2 -1
- package/src/common.test.ts +18 -17
- package/src/common.ts +44 -9
- package/src/migration/migration.ts +1 -0
- package/src/pull/pull.test.ts +2 -2
- package/src/rakeDb.test.ts +1 -1
- package/src/rakeDb.ts +2 -2
- package/src/test-utils.ts +3 -1
- package/tsconfig.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { singleQuote, quote, isRaw, getRaw, toArray, columnTypes, raw, getColumn
|
|
|
2
2
|
import Enquirer from 'enquirer';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { readdir, mkdir, writeFile } from 'fs/promises';
|
|
5
|
+
import { pathToFileURL } from 'url';
|
|
5
6
|
|
|
6
7
|
var __defProp$6 = Object.defineProperty;
|
|
7
8
|
var __defProps$5 = Object.defineProperties;
|
|
@@ -23,16 +24,45 @@ var __spreadValues$6 = (a, b) => {
|
|
|
23
24
|
};
|
|
24
25
|
var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
25
26
|
const migrationConfigDefaults = {
|
|
26
|
-
migrationsPath: path.
|
|
27
|
+
migrationsPath: path.join("src", "db", "migrations"),
|
|
27
28
|
migrationsTable: "schemaMigrations",
|
|
28
29
|
commands: {},
|
|
29
|
-
|
|
30
|
+
import: (path2) => import(path2),
|
|
30
31
|
log: true,
|
|
31
32
|
logger: console,
|
|
32
33
|
useCodeUpdater: true
|
|
33
34
|
};
|
|
34
|
-
const
|
|
35
|
-
|
|
35
|
+
const processRakeDbConfig = (config) => {
|
|
36
|
+
var _a;
|
|
37
|
+
const result = __spreadValues$6(__spreadValues$6({}, migrationConfigDefaults), config);
|
|
38
|
+
if (!result.basePath) {
|
|
39
|
+
let stack;
|
|
40
|
+
Error.prepareStackTrace = (_, s) => stack = s;
|
|
41
|
+
new Error().stack;
|
|
42
|
+
if (stack) {
|
|
43
|
+
const thisFile = (_a = stack[0]) == null ? void 0 : _a.getFileName();
|
|
44
|
+
for (const item of stack) {
|
|
45
|
+
const file = item.getFileName();
|
|
46
|
+
if (!file || file === thisFile || /\bnode_modules\b/.test(file)) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
result.basePath = path.dirname(file);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (!result.basePath) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
"Failed to determine path to db script. Please set basePath option of rakeDb"
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!path.isAbsolute(result.migrationsPath)) {
|
|
60
|
+
result.migrationsPath = path.resolve(
|
|
61
|
+
result.basePath,
|
|
62
|
+
result.migrationsPath
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
36
66
|
};
|
|
37
67
|
const getDatabaseAndUserFromOptions = (options) => {
|
|
38
68
|
if (options.databaseURL) {
|
|
@@ -139,7 +169,7 @@ const getMigrationFiles = async (config, up) => {
|
|
|
139
169
|
const { migrationsPath } = config;
|
|
140
170
|
let files;
|
|
141
171
|
try {
|
|
142
|
-
files = await readdir(
|
|
172
|
+
files = await readdir(migrationsPath);
|
|
143
173
|
} catch (_) {
|
|
144
174
|
return [];
|
|
145
175
|
}
|
|
@@ -1091,6 +1121,7 @@ const runCodeUpdater = (migration, ast) => {
|
|
|
1091
1121
|
return (_b = (_a = migration.options).appCodeUpdater) == null ? void 0 : _b.call(_a, {
|
|
1092
1122
|
ast,
|
|
1093
1123
|
options: migration.adapterOptions,
|
|
1124
|
+
basePath: migration.options.basePath,
|
|
1094
1125
|
cache: migration.appCodeUpdaterCache
|
|
1095
1126
|
});
|
|
1096
1127
|
};
|
|
@@ -1183,7 +1214,7 @@ const processMigration = async (db, up, file, config, options, appCodeUpdaterCac
|
|
|
1183
1214
|
if (callback) {
|
|
1184
1215
|
change(callback);
|
|
1185
1216
|
} else {
|
|
1186
|
-
await config.
|
|
1217
|
+
await config.import(pathToFileURL(file.path).toString());
|
|
1187
1218
|
changeCache[file.path] = getCurrentChangeCallback();
|
|
1188
1219
|
}
|
|
1189
1220
|
await getCurrentPromise();
|
|
@@ -1308,7 +1339,7 @@ const resetDb = async (arg, config) => {
|
|
|
1308
1339
|
};
|
|
1309
1340
|
|
|
1310
1341
|
const writeMigrationFile = async (config, name, content) => {
|
|
1311
|
-
await mkdir(
|
|
1342
|
+
await mkdir(config.migrationsPath, { recursive: true });
|
|
1312
1343
|
const filePath = path.resolve(
|
|
1313
1344
|
config.migrationsPath,
|
|
1314
1345
|
`${makeFileTimeStamp()}_${name}.ts`
|
|
@@ -2020,7 +2051,7 @@ const pullDbStructure = async (options, config) => {
|
|
|
2020
2051
|
|
|
2021
2052
|
const rakeDb = async (options, partialConfig = {}, args = process.argv.slice(2)) => {
|
|
2022
2053
|
var _a;
|
|
2023
|
-
const config =
|
|
2054
|
+
const config = processRakeDbConfig(partialConfig);
|
|
2024
2055
|
const command = (_a = args[0]) == null ? void 0 : _a.split(":")[0];
|
|
2025
2056
|
if (command === "create") {
|
|
2026
2057
|
await createDb(options, config);
|