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.mjs CHANGED
@@ -2023,7 +2023,7 @@ const fkeyActionMap = {
2023
2023
  n: "SET NULL",
2024
2024
  d: "SET DEFAULT"
2025
2025
  };
2026
- const structureToAst = async (config, db) => {
2026
+ const structureToAst = async (unsupportedTypes, db) => {
2027
2027
  const ast = [];
2028
2028
  const data = await getData(db);
2029
2029
  for (const name of data.schemas) {
@@ -2051,19 +2051,24 @@ const structureToAst = async (config, db) => {
2051
2051
  }
2052
2052
  const domains = {};
2053
2053
  for (const it of data.domains) {
2054
- domains[`${it.schemaName}.${it.name}`] = getColumn(config, data, domains, {
2055
- schemaName: it.schemaName,
2056
- name: it.name,
2057
- type: it.type,
2058
- typeSchema: it.typeSchema,
2059
- isArray: it.isArray,
2060
- isSerial: false
2061
- });
2054
+ domains[`${it.schemaName}.${it.name}`] = getColumn(
2055
+ unsupportedTypes,
2056
+ data,
2057
+ domains,
2058
+ {
2059
+ schemaName: it.schemaName,
2060
+ name: it.name,
2061
+ type: it.type,
2062
+ typeSchema: it.typeSchema,
2063
+ isArray: it.isArray,
2064
+ isSerial: false
2065
+ }
2066
+ );
2062
2067
  }
2063
2068
  for (const key in pendingTables) {
2064
2069
  const { table, dependsOn } = pendingTables[key];
2065
2070
  if (!dependsOn.size) {
2066
- pushTableAst(config, ast, data, domains, table, pendingTables);
2071
+ pushTableAst(unsupportedTypes, ast, data, domains, table, pendingTables);
2067
2072
  }
2068
2073
  }
2069
2074
  const outerFKeys = [];
@@ -2111,7 +2116,15 @@ const structureToAst = async (config, db) => {
2111
2116
  outerFKeys.push([fkey, table]);
2112
2117
  }
2113
2118
  }
2114
- pushTableAst(config, ast, data, domains, table, pendingTables, innerFKeys);
2119
+ pushTableAst(
2120
+ unsupportedTypes,
2121
+ ast,
2122
+ data,
2123
+ domains,
2124
+ table,
2125
+ pendingTables,
2126
+ innerFKeys
2127
+ );
2115
2128
  }
2116
2129
  for (const [fkey, table] of outerFKeys) {
2117
2130
  ast.push(__spreadProps(__spreadValues({}, foreignKeyToAst(fkey)), {
@@ -2171,7 +2184,7 @@ const getIsSerial = (item) => {
2171
2184
  }
2172
2185
  return false;
2173
2186
  };
2174
- const getColumn = (config, data, domains, _a) => {
2187
+ const getColumn = (unsupportedTypes, data, domains, _a) => {
2175
2188
  var _b = _a, {
2176
2189
  schemaName,
2177
2190
  tableName,
@@ -2206,8 +2219,8 @@ const getColumn = (config, data, domains, _a) => {
2206
2219
  column = new RakeDbEnumColumn({}, type, enumType.values);
2207
2220
  } else {
2208
2221
  column = new CustomTypeColumn({}, type);
2209
- (_a2 = config.logger) == null ? void 0 : _a2.warn(
2210
- `${tableName ? "Column" : "Domain"} ${schemaName}${tableName ? `.${tableName}` : ""}.${name} has unsupported type \`${type}\`, append \`as\` method manually to it to treat it as other column type`
2222
+ ((_a2 = unsupportedTypes[type]) != null ? _a2 : unsupportedTypes[type] = []).push(
2223
+ `${schemaName}${tableName ? `.${tableName}` : ""}.${name}`
2211
2224
  );
2212
2225
  }
2213
2226
  }
@@ -2219,7 +2232,7 @@ const getColumnType = (type, isSerial) => {
2219
2232
  return type;
2220
2233
  return type === "int2" ? "smallserial" : type === "int4" ? "serial" : "bigserial";
2221
2234
  };
2222
- const pushTableAst = (config, ast, data, domains, table, pendingTables, innerFKeys = data.foreignKeys) => {
2235
+ const pushTableAst = (unsupportedTypes, ast, data, domains, table, pendingTables, innerFKeys = data.foreignKeys) => {
2223
2236
  const { schemaName, name } = table;
2224
2237
  const key = `${schemaName}.${table.name}`;
2225
2238
  delete pendingTables[key];
@@ -2242,7 +2255,7 @@ const pushTableAst = (config, ast, data, domains, table, pendingTables, innerFKe
2242
2255
  if (isSerial) {
2243
2256
  item = __spreadProps(__spreadValues({}, item), { default: void 0 });
2244
2257
  }
2245
- let column = getColumn(config, data, domains, __spreadProps(__spreadValues({}, item), {
2258
+ let column = getColumn(unsupportedTypes, data, domains, __spreadProps(__spreadValues({}, item), {
2246
2259
  type: item.type,
2247
2260
  isArray: item.isArray,
2248
2261
  isSerial
@@ -2325,7 +2338,14 @@ const pushTableAst = (config, ast, data, domains, table, pendingTables, innerFKe
2325
2338
  for (const otherKey in pendingTables) {
2326
2339
  const item = pendingTables[otherKey];
2327
2340
  if (item.dependsOn.delete(key) && item.dependsOn.size === 0) {
2328
- pushTableAst(config, ast, data, domains, item.table, pendingTables);
2341
+ pushTableAst(
2342
+ unsupportedTypes,
2343
+ ast,
2344
+ data,
2345
+ domains,
2346
+ item.table,
2347
+ pendingTables
2348
+ );
2329
2349
  }
2330
2350
  }
2331
2351
  };
@@ -2497,10 +2517,11 @@ const createForeignKey = (item) => {
2497
2517
  };
2498
2518
 
2499
2519
  const pullDbStructure = async (options, config) => {
2500
- var _a;
2520
+ var _a, _b, _c;
2501
2521
  const adapter = new Adapter(options);
2502
2522
  const db = new DbStructure(adapter);
2503
- const ast = await structureToAst(config, db);
2523
+ const unsupportedTypes = {};
2524
+ const ast = await structureToAst(unsupportedTypes, db);
2504
2525
  await adapter.close();
2505
2526
  const result = astToMigration(config, ast);
2506
2527
  if (!result)
@@ -2518,6 +2539,21 @@ const pullDbStructure = async (options, config) => {
2518
2539
  logger: config.logger
2519
2540
  }));
2520
2541
  }
2542
+ const unsupportedEntries = Object.entries(unsupportedTypes);
2543
+ const len = unsupportedEntries.length;
2544
+ if (len) {
2545
+ let count = 0;
2546
+ (_b = config.logger) == null ? void 0 : _b.warn(
2547
+ `Found unsupported types:
2548
+ ${unsupportedEntries.map(([type, columns]) => {
2549
+ count += columns.length;
2550
+ return `${type} is used for column${columns.length > 1 ? "s" : ""} ${columns.join(", ")}`;
2551
+ }).join("\n")}
2552
+
2553
+ Append \`as\` method manually to ${count > 1 ? "these" : "this"} column${count > 1 ? "s" : ""} to treat ${count > 1 ? "them" : "it"} as other column type`
2554
+ );
2555
+ }
2556
+ (_c = config.logger) == null ? void 0 : _c.log("Database pulled successfully");
2521
2557
  };
2522
2558
 
2523
2559
  const rakeDb = async (options, partialConfig = {}, args = process.argv.slice(2)) => {