rake-db 2.4.13 → 2.4.14

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 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 (config, db) => {
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(config, data, domains, {
2083
- schemaName: it.schemaName,
2084
- name: it.name,
2085
- type: it.type,
2086
- typeSchema: it.typeSchema,
2087
- isArray: it.isArray,
2088
- isSerial: false
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(config, ast, data, domains, table, pendingTables);
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(config, ast, data, domains, table, pendingTables, innerFKeys);
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 = (config, data, domains, _a) => {
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 = config.logger) == null ? void 0 : _a2.warn(
2238
- `${tableName ? "Column" : "Domain"} ${schemaName}${tableName ? `.${tableName}` : ""}.${name} has unsupported type \`${type}\`, append \`as\` method manually to it to treat it as other column type`
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 = (config, ast, data, domains, table, pendingTables, innerFKeys = data.foreignKeys) => {
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(config, data, domains, __spreadProps(__spreadValues({}, item), {
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(config, ast, data, domains, item.table, pendingTables);
2369
+ pushTableAst(
2370
+ unsupportedTypes,
2371
+ ast,
2372
+ data,
2373
+ domains,
2374
+ item.table,
2375
+ pendingTables
2376
+ );
2357
2377
  }
2358
2378
  }
2359
2379
  };
@@ -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 ast = await structureToAst(config, db);
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
+
2581
+ Append \`as\` method manually to ${count > 1 ? "these" : "this"} column${count > 1 ? "s" : ""} to treat ${count > 1 ? "them" : "it"} as other column type`
2582
+ );
2583
+ }
2584
+ (_c = config.logger) == null ? void 0 : _c.log("Database pulled successfully");
2549
2585
  };
2550
2586
 
2551
2587
  const rakeDb = async (options, partialConfig = {}, args = process.argv.slice(2)) => {