rake-db 2.22.8 → 2.22.9

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
@@ -1,5 +1,5 @@
1
1
  import { quote, EnumColumn, defaultSchemaConfig, getColumnTypes, parseTableData, tableDataMethods, ColumnType, parseTableDataInput, UnknownColumn, raw, TransactionAdapter, logParamToLogObject, createDb as createDb$1, Adapter, makeColumnTypes, makeColumnsByType, RawSQL, DomainColumn, CustomTypeColumn, ArrayColumn, instantiateColumn, pushTableDataCode, primaryKeyInnerToCode, indexInnerToCode, constraintInnerToCode, referencesArgsToCode, TimestampTZColumn, TimestampColumn } from 'pqb';
2
- import { singleQuote, toSnakeCase, isRawSQL, toArray, snakeCaseKey, emptyObject, setCurrentColumnName, consumeColumnName, ColumnTypeBase, setDefaultLanguage, deepCompare, getImportPath, pathToLog, emptyArray, getStackTrace, toCamelCase, codeToString, addCode, quoteObjectKey, columnToCode, backtickQuote } from 'orchid-core';
2
+ import { singleQuote, toSnakeCase, isRawSQL, toArray, snakeCaseKey, emptyObject, setCurrentColumnName, consumeColumnName, ColumnTypeBase, setDefaultLanguage, deepCompare, getImportPath, pathToLog, emptyArray, getStackTrace, toCamelCase, codeToString, addCode, quoteObjectKey, backtickQuote } from 'orchid-core';
3
3
  import path, { join } from 'path';
4
4
  import { pathToFileURL, fileURLToPath } from 'node:url';
5
5
  import fs, { mkdir, writeFile, readdir, stat, readFile } from 'fs/promises';
@@ -1210,7 +1210,7 @@ const handleTableItemChange = (key, item, ast, alterTable, renameItems, values,
1210
1210
  for (let i = 0; i < indexesLen; i++) {
1211
1211
  const fromIndex = (_v = from.indexes) == null ? void 0 : _v[i];
1212
1212
  const toIndex = (_w = to.indexes) == null ? void 0 : _w[i];
1213
- if ((fromIndex || toIndex) && (!fromIndex || !toIndex || fromIndex.options.collate !== toIndex.options.collate || fromIndex.options.opclass !== toIndex.options.opclass || fromIndex.options.order !== toIndex.options.order || fromIndex.name !== toIndex.name || fromIndex.options.unique !== toIndex.options.unique || fromIndex.options.using !== toIndex.options.using || fromIndex.options.include !== toIndex.options.include || Array.isArray(fromIndex.options.include) && Array.isArray(toIndex.options.include) && fromIndex.options.include.join(",") !== toIndex.options.include.join(",") || fromIndex.options.with !== toIndex.options.with || fromIndex.options.tablespace !== toIndex.options.tablespace || fromIndex.options.where !== toIndex.options.where || fromIndex.options.dropMode !== toIndex.options.dropMode)) {
1213
+ if ((fromIndex || toIndex) && (!fromIndex || !toIndex || !deepCompare(fromIndex, toIndex))) {
1214
1214
  if (fromIndex) {
1215
1215
  dropIndexes.push(__spreadProps$5(__spreadValues$7({}, fromIndex), {
1216
1216
  columns: [
@@ -4982,11 +4982,17 @@ const astEncoders = {
4982
4982
  ast.shape.createdAt,
4983
4983
  ast.shape.updatedAt
4984
4984
  );
4985
+ const toCodeCtx = {
4986
+ t: "t",
4987
+ table: ast.name,
4988
+ migration: true,
4989
+ snakeCase: config.snakeCase
4990
+ };
4985
4991
  for (const key in ast.shape) {
4986
4992
  if (timestamps.hasAnyTimestamps && (key === "createdAt" || key === "updatedAt"))
4987
4993
  continue;
4988
4994
  const line = [`${quoteObjectKey(key)}: `];
4989
- const columnCode = columnToCode(key, ast.shape[key], config.snakeCase);
4995
+ const columnCode = ast.shape[key].toCode(toCodeCtx, key);
4990
4996
  for (const part of columnCode) {
4991
4997
  addCode(line, part);
4992
4998
  }
@@ -5036,6 +5042,12 @@ const astEncoders = {
5036
5042
  );
5037
5043
  }
5038
5044
  );
5045
+ const toCodeCtx = {
5046
+ t: "t",
5047
+ table: ast.name,
5048
+ migration: true,
5049
+ snakeCase: config.snakeCase
5050
+ };
5039
5051
  for (const key in ast.shape) {
5040
5052
  const changes = toArray(ast.shape[key]);
5041
5053
  for (const change of changes) {
@@ -5048,7 +5060,7 @@ const astEncoders = {
5048
5060
  (_a = change.item.data.name) != null ? _a : key
5049
5061
  )})` : `${quoteObjectKey(key)}: t.${change.type}(`
5050
5062
  ];
5051
- const columnCode = columnToCode(key, change.item, config.snakeCase);
5063
+ const columnCode = change.item.toCode(toCodeCtx, key);
5052
5064
  for (let i = 0; i < columnCode.length; i++) {
5053
5065
  let part = columnCode[i];
5054
5066
  if (recreate && !i)
@@ -5063,16 +5075,20 @@ const astEncoders = {
5063
5075
  const line = [
5064
5076
  `${quoteObjectKey(key)}: t${change.name ? `.name(${singleQuote(change.name)})` : ""}.change(`
5065
5077
  ];
5066
- const fromCode = columnToCode(
5067
- key,
5068
- change.from.column,
5069
- config.snakeCase
5078
+ const fromCode = change.from.column.toCode(
5079
+ {
5080
+ t: "t",
5081
+ table: ast.name,
5082
+ migration: true,
5083
+ snakeCase: config.snakeCase
5084
+ },
5085
+ key
5070
5086
  );
5071
5087
  for (const part of fromCode) {
5072
5088
  addCode(line, part);
5073
5089
  }
5074
5090
  addCode(line, ", ");
5075
- const toCode = columnToCode(key, change.to.column, config.snakeCase);
5091
+ const toCode = change.to.column.toCode(toCodeCtx, key);
5076
5092
  for (const part of toCode) {
5077
5093
  addCode(line, part);
5078
5094
  }
@@ -5196,9 +5212,13 @@ const astEncoders = {
5196
5212
  )}, [${ast.fromValues.map(singleQuote).join(", ")}], [${ast.toValues.map(singleQuote).join(", ")}]);`;
5197
5213
  },
5198
5214
  domain(ast) {
5215
+ var _a;
5199
5216
  return `await db.${ast.action}Domain(${quoteSchemaTable(
5200
5217
  ast
5201
- )}, (t) => ${ast.baseType.toCode("t")});`;
5218
+ )}, (t) => ${ast.baseType.toCode(
5219
+ { t: "t", table: ast.name },
5220
+ (_a = ast.baseType.data.name) != null ? _a : ""
5221
+ )});`;
5202
5222
  },
5203
5223
  collation(ast) {
5204
5224
  const params = [];