rake-db 2.4.9 → 2.4.10

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.js CHANGED
@@ -2043,7 +2043,7 @@ const fkeyActionMap = {
2043
2043
  n: "SET NULL",
2044
2044
  d: "SET DEFAULT"
2045
2045
  };
2046
- const structureToAst = async (db) => {
2046
+ const structureToAst = async (config, db) => {
2047
2047
  const ast = [];
2048
2048
  const data = await getData(db);
2049
2049
  for (const name of data.schemas) {
@@ -2071,7 +2071,7 @@ const structureToAst = async (db) => {
2071
2071
  }
2072
2072
  const domains = {};
2073
2073
  for (const it of data.domains) {
2074
- domains[`${it.schemaName}.${it.name}`] = getColumn(data, domains, {
2074
+ domains[`${it.schemaName}.${it.name}`] = getColumn(config, data, domains, {
2075
2075
  schemaName: it.schemaName,
2076
2076
  name: it.name,
2077
2077
  type: it.type,
@@ -2083,7 +2083,7 @@ const structureToAst = async (db) => {
2083
2083
  for (const key in pendingTables) {
2084
2084
  const { table, dependsOn } = pendingTables[key];
2085
2085
  if (!dependsOn.size) {
2086
- pushTableAst(ast, data, domains, table, pendingTables);
2086
+ pushTableAst(config, ast, data, domains, table, pendingTables);
2087
2087
  }
2088
2088
  }
2089
2089
  const outerFKeys = [];
@@ -2131,7 +2131,7 @@ const structureToAst = async (db) => {
2131
2131
  outerFKeys.push([fkey, table]);
2132
2132
  }
2133
2133
  }
2134
- pushTableAst(ast, data, domains, table, pendingTables, innerFKeys);
2134
+ pushTableAst(config, ast, data, domains, table, pendingTables, innerFKeys);
2135
2135
  }
2136
2136
  for (const [fkey, table] of outerFKeys) {
2137
2137
  ast.push(__spreadProps(__spreadValues({}, foreignKeyToAst(fkey)), {
@@ -2191,7 +2191,7 @@ const getIsSerial = (item) => {
2191
2191
  }
2192
2192
  return false;
2193
2193
  };
2194
- const getColumn = (data, domains, _a) => {
2194
+ const getColumn = (config, data, domains, _a) => {
2195
2195
  var _b = _a, {
2196
2196
  schemaName,
2197
2197
  tableName,
@@ -2209,6 +2209,7 @@ const getColumn = (data, domains, _a) => {
2209
2209
  "isArray",
2210
2210
  "isSerial"
2211
2211
  ]);
2212
+ var _a2;
2212
2213
  let column;
2213
2214
  const klass = pqb.columnsByType[getColumnType(type, isSerial)];
2214
2215
  if (klass) {
@@ -2221,12 +2222,14 @@ const getColumn = (data, domains, _a) => {
2221
2222
  const enumType = data.enums.find(
2222
2223
  (item) => item.name === type && item.schemaName === typeSchema
2223
2224
  );
2224
- if (!enumType) {
2225
- throw new Error(
2226
- `Cannot handle ${tableName ? "column" : "domain"} ${schemaName}${tableName ? `.${tableName}` : ""}.${name}: column type \`${type}\` is not supported`
2225
+ if (enumType) {
2226
+ column = new RakeDbEnumColumn({}, type, enumType.values);
2227
+ } else {
2228
+ column = new pqb.CustomTypeColumn({}, type);
2229
+ (_a2 = config.logger) == null ? void 0 : _a2.warn(
2230
+ `${tableName ? "Column" : "Domain"} ${schemaName}${tableName ? `.${tableName}` : ""}.${name} has unsupported type \`${type}\`, append \`as\` method manually to it to treat it as other column type`
2227
2231
  );
2228
2232
  }
2229
- column = new RakeDbEnumColumn({}, type, enumType.values);
2230
2233
  }
2231
2234
  }
2232
2235
  return isArray ? new pqb.ArrayColumn({}, column) : column;
@@ -2236,7 +2239,7 @@ const getColumnType = (type, isSerial) => {
2236
2239
  return type;
2237
2240
  return type === "int2" ? "smallserial" : type === "int4" ? "serial" : "bigserial";
2238
2241
  };
2239
- const pushTableAst = (ast, data, domains, table, pendingTables, innerFKeys = data.foreignKeys) => {
2242
+ const pushTableAst = (config, ast, data, domains, table, pendingTables, innerFKeys = data.foreignKeys) => {
2240
2243
  const { schemaName, name } = table;
2241
2244
  const key = `${schemaName}.${table.name}`;
2242
2245
  delete pendingTables[key];
@@ -2260,7 +2263,7 @@ const pushTableAst = (ast, data, domains, table, pendingTables, innerFKeys = dat
2260
2263
  item = __spreadProps(__spreadValues({}, item), { default: void 0 });
2261
2264
  }
2262
2265
  const isArray = item.dataType === "ARRAY";
2263
- let column = getColumn(data, domains, __spreadProps(__spreadValues({}, item), {
2266
+ let column = getColumn(config, data, domains, __spreadProps(__spreadValues({}, item), {
2264
2267
  type: isArray ? item.type.slice(1) : item.type,
2265
2268
  isArray,
2266
2269
  isSerial
@@ -2343,7 +2346,7 @@ const pushTableAst = (ast, data, domains, table, pendingTables, innerFKeys = dat
2343
2346
  for (const otherKey in pendingTables) {
2344
2347
  const item = pendingTables[otherKey];
2345
2348
  if (item.dependsOn.delete(key) && item.dependsOn.size === 0) {
2346
- pushTableAst(ast, data, domains, item.table, pendingTables);
2349
+ pushTableAst(config, ast, data, domains, item.table, pendingTables);
2347
2350
  }
2348
2351
  }
2349
2352
  };
@@ -2518,7 +2521,7 @@ const pullDbStructure = async (options, config) => {
2518
2521
  var _a;
2519
2522
  const adapter = new pqb.Adapter(options);
2520
2523
  const db = new DbStructure(adapter);
2521
- const ast = await structureToAst(db);
2524
+ const ast = await structureToAst(config, db);
2522
2525
  await adapter.close();
2523
2526
  const result = astToMigration(config, ast);
2524
2527
  if (!result)