rake-db 2.4.13 → 2.4.15
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 +1 -0
- package/dist/index.js +60 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ declare type TextColumnCreator = () => TextColumn;
|
|
|
40
40
|
declare type MigrationColumnTypes = Omit<ColumnTypes, 'text' | 'string' | 'enum'> & {
|
|
41
41
|
text: TextColumnCreator;
|
|
42
42
|
string: TextColumnCreator;
|
|
43
|
+
citext: TextColumnCreator;
|
|
43
44
|
enum: (name: string) => EnumColumn;
|
|
44
45
|
};
|
|
45
46
|
declare type ColumnsShapeCallback = (t: MigrationColumnTypes & {
|
package/dist/index.js
CHANGED
|
@@ -2051,7 +2051,7 @@ const fkeyActionMap = {
|
|
|
2051
2051
|
n: "SET NULL",
|
|
2052
2052
|
d: "SET DEFAULT"
|
|
2053
2053
|
};
|
|
2054
|
-
const structureToAst = async (
|
|
2054
|
+
const structureToAst = async (unsupportedTypes, db) => {
|
|
2055
2055
|
const ast = [];
|
|
2056
2056
|
const data = await getData(db);
|
|
2057
2057
|
for (const name of data.schemas) {
|
|
@@ -2079,19 +2079,24 @@ const structureToAst = async (config, db) => {
|
|
|
2079
2079
|
}
|
|
2080
2080
|
const domains = {};
|
|
2081
2081
|
for (const it of data.domains) {
|
|
2082
|
-
domains[`${it.schemaName}.${it.name}`] = getColumn(
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2082
|
+
domains[`${it.schemaName}.${it.name}`] = getColumn(
|
|
2083
|
+
unsupportedTypes,
|
|
2084
|
+
data,
|
|
2085
|
+
domains,
|
|
2086
|
+
{
|
|
2087
|
+
schemaName: it.schemaName,
|
|
2088
|
+
name: it.name,
|
|
2089
|
+
type: it.type,
|
|
2090
|
+
typeSchema: it.typeSchema,
|
|
2091
|
+
isArray: it.isArray,
|
|
2092
|
+
isSerial: false
|
|
2093
|
+
}
|
|
2094
|
+
);
|
|
2090
2095
|
}
|
|
2091
2096
|
for (const key in pendingTables) {
|
|
2092
2097
|
const { table, dependsOn } = pendingTables[key];
|
|
2093
2098
|
if (!dependsOn.size) {
|
|
2094
|
-
pushTableAst(
|
|
2099
|
+
pushTableAst(unsupportedTypes, ast, data, domains, table, pendingTables);
|
|
2095
2100
|
}
|
|
2096
2101
|
}
|
|
2097
2102
|
const outerFKeys = [];
|
|
@@ -2139,7 +2144,15 @@ const structureToAst = async (config, db) => {
|
|
|
2139
2144
|
outerFKeys.push([fkey, table]);
|
|
2140
2145
|
}
|
|
2141
2146
|
}
|
|
2142
|
-
pushTableAst(
|
|
2147
|
+
pushTableAst(
|
|
2148
|
+
unsupportedTypes,
|
|
2149
|
+
ast,
|
|
2150
|
+
data,
|
|
2151
|
+
domains,
|
|
2152
|
+
table,
|
|
2153
|
+
pendingTables,
|
|
2154
|
+
innerFKeys
|
|
2155
|
+
);
|
|
2143
2156
|
}
|
|
2144
2157
|
for (const [fkey, table] of outerFKeys) {
|
|
2145
2158
|
ast.push(__spreadProps(__spreadValues({}, foreignKeyToAst(fkey)), {
|
|
@@ -2199,7 +2212,7 @@ const getIsSerial = (item) => {
|
|
|
2199
2212
|
}
|
|
2200
2213
|
return false;
|
|
2201
2214
|
};
|
|
2202
|
-
const getColumn = (
|
|
2215
|
+
const getColumn = (unsupportedTypes, data, domains, _a) => {
|
|
2203
2216
|
var _b = _a, {
|
|
2204
2217
|
schemaName,
|
|
2205
2218
|
tableName,
|
|
@@ -2234,8 +2247,8 @@ const getColumn = (config, data, domains, _a) => {
|
|
|
2234
2247
|
column = new RakeDbEnumColumn({}, type, enumType.values);
|
|
2235
2248
|
} else {
|
|
2236
2249
|
column = new pqb.CustomTypeColumn({}, type);
|
|
2237
|
-
(_a2 =
|
|
2238
|
-
`${
|
|
2250
|
+
((_a2 = unsupportedTypes[type]) != null ? _a2 : unsupportedTypes[type] = []).push(
|
|
2251
|
+
`${schemaName}${tableName ? `.${tableName}` : ""}.${name}`
|
|
2239
2252
|
);
|
|
2240
2253
|
}
|
|
2241
2254
|
}
|
|
@@ -2247,7 +2260,7 @@ const getColumnType = (type, isSerial) => {
|
|
|
2247
2260
|
return type;
|
|
2248
2261
|
return type === "int2" ? "smallserial" : type === "int4" ? "serial" : "bigserial";
|
|
2249
2262
|
};
|
|
2250
|
-
const pushTableAst = (
|
|
2263
|
+
const pushTableAst = (unsupportedTypes, ast, data, domains, table, pendingTables, innerFKeys = data.foreignKeys) => {
|
|
2251
2264
|
const { schemaName, name } = table;
|
|
2252
2265
|
const key = `${schemaName}.${table.name}`;
|
|
2253
2266
|
delete pendingTables[key];
|
|
@@ -2270,7 +2283,7 @@ const pushTableAst = (config, ast, data, domains, table, pendingTables, innerFKe
|
|
|
2270
2283
|
if (isSerial) {
|
|
2271
2284
|
item = __spreadProps(__spreadValues({}, item), { default: void 0 });
|
|
2272
2285
|
}
|
|
2273
|
-
let column = getColumn(
|
|
2286
|
+
let column = getColumn(unsupportedTypes, data, domains, __spreadProps(__spreadValues({}, item), {
|
|
2274
2287
|
type: item.type,
|
|
2275
2288
|
isArray: item.isArray,
|
|
2276
2289
|
isSerial
|
|
@@ -2353,7 +2366,14 @@ const pushTableAst = (config, ast, data, domains, table, pendingTables, innerFKe
|
|
|
2353
2366
|
for (const otherKey in pendingTables) {
|
|
2354
2367
|
const item = pendingTables[otherKey];
|
|
2355
2368
|
if (item.dependsOn.delete(key) && item.dependsOn.size === 0) {
|
|
2356
|
-
pushTableAst(
|
|
2369
|
+
pushTableAst(
|
|
2370
|
+
unsupportedTypes,
|
|
2371
|
+
ast,
|
|
2372
|
+
data,
|
|
2373
|
+
domains,
|
|
2374
|
+
item.table,
|
|
2375
|
+
pendingTables
|
|
2376
|
+
);
|
|
2357
2377
|
}
|
|
2358
2378
|
}
|
|
2359
2379
|
};
|
|
@@ -2403,7 +2423,7 @@ const astToMigration = (config, ast) => {
|
|
|
2403
2423
|
if (first.length) {
|
|
2404
2424
|
code += `
|
|
2405
2425
|
change(async (db) => {
|
|
2406
|
-
${
|
|
2426
|
+
${orchidCore.codeToString(first, " ", " ")}
|
|
2407
2427
|
});
|
|
2408
2428
|
`;
|
|
2409
2429
|
}
|
|
@@ -2411,7 +2431,7 @@ ${pqb.codeToString(first, " ", " ")}
|
|
|
2411
2431
|
for (const table of tables) {
|
|
2412
2432
|
code += `
|
|
2413
2433
|
change(async (db) => {
|
|
2414
|
-
${
|
|
2434
|
+
${orchidCore.codeToString(table, " ", " ")}
|
|
2415
2435
|
});
|
|
2416
2436
|
`;
|
|
2417
2437
|
}
|
|
@@ -2419,7 +2439,7 @@ ${pqb.codeToString(table, " ", " ")}
|
|
|
2419
2439
|
if (foreignKeys.length) {
|
|
2420
2440
|
code += `
|
|
2421
2441
|
change(async (db) => {
|
|
2422
|
-
${
|
|
2442
|
+
${orchidCore.codeToString(foreignKeys, " ", " ")}
|
|
2423
2443
|
});
|
|
2424
2444
|
`;
|
|
2425
2445
|
}
|
|
@@ -2459,9 +2479,9 @@ const createDomain = (ast) => {
|
|
|
2459
2479
|
if (ast.collation)
|
|
2460
2480
|
props.push(`collation: ${orchidCore.singleQuote(ast.collation)},`);
|
|
2461
2481
|
if (ast.default)
|
|
2462
|
-
props.push(`default: ${
|
|
2482
|
+
props.push(`default: ${orchidCore.rawToCode("db", ast.default)},`);
|
|
2463
2483
|
if (ast.check)
|
|
2464
|
-
props.push(`check: ${
|
|
2484
|
+
props.push(`check: ${orchidCore.rawToCode("db", ast.check)},`);
|
|
2465
2485
|
orchidCore.addCode(code, ", {");
|
|
2466
2486
|
code.push(props);
|
|
2467
2487
|
orchidCore.addCode(code, "}");
|
|
@@ -2525,10 +2545,11 @@ const createForeignKey = (item) => {
|
|
|
2525
2545
|
};
|
|
2526
2546
|
|
|
2527
2547
|
const pullDbStructure = async (options, config) => {
|
|
2528
|
-
var _a;
|
|
2548
|
+
var _a, _b, _c;
|
|
2529
2549
|
const adapter = new pqb.Adapter(options);
|
|
2530
2550
|
const db = new DbStructure(adapter);
|
|
2531
|
-
const
|
|
2551
|
+
const unsupportedTypes = {};
|
|
2552
|
+
const ast = await structureToAst(unsupportedTypes, db);
|
|
2532
2553
|
await adapter.close();
|
|
2533
2554
|
const result = astToMigration(config, ast);
|
|
2534
2555
|
if (!result)
|
|
@@ -2546,6 +2567,21 @@ const pullDbStructure = async (options, config) => {
|
|
|
2546
2567
|
logger: config.logger
|
|
2547
2568
|
}));
|
|
2548
2569
|
}
|
|
2570
|
+
const unsupportedEntries = Object.entries(unsupportedTypes);
|
|
2571
|
+
const len = unsupportedEntries.length;
|
|
2572
|
+
if (len) {
|
|
2573
|
+
let count = 0;
|
|
2574
|
+
(_b = config.logger) == null ? void 0 : _b.warn(
|
|
2575
|
+
`Found unsupported types:
|
|
2576
|
+
${unsupportedEntries.map(([type, columns]) => {
|
|
2577
|
+
count += columns.length;
|
|
2578
|
+
return `- ${type} is used for column${columns.length > 1 ? "s" : ""} ${columns.join(", ")}`;
|
|
2579
|
+
}).join("\n")}
|
|
2580
|
+
Append \`as\` method manually to ${count > 1 ? "these" : "this"} column${count > 1 ? "s" : ""} to treat ${count > 1 ? "them" : "it"} as other column type`
|
|
2581
|
+
);
|
|
2582
|
+
}
|
|
2583
|
+
(_c = config.logger) == null ? void 0 : _c.log("Database pulled successfully");
|
|
2584
|
+
adapter.close();
|
|
2549
2585
|
};
|
|
2550
2586
|
|
|
2551
2587
|
const rakeDb = async (options, partialConfig = {}, args = process.argv.slice(2)) => {
|