orchid-orm 1.31.7 → 1.32.1

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.
@@ -1,7 +1,7 @@
1
1
  import { promptSelect, colors, getSchemaAndTableFromName, getDbTableColumnsChecks, dbColumnToAst, instantiateDbColumn, concatSchemaAndName, encodeColumnDefault, getIndexName, getConstraintName, tableToAst, getDbStructureTableData, makeDomainsMap, astToMigration, createMigrationInterface, introspectDbSchema, exhaustive, pluralize, makeStructureToAstCtx, makeFileVersion, writeMigrationFile, migrate, structureToAst, saveMigratedVersion, rakeDbCommands } from 'rake-db';
2
2
  export * from 'rake-db';
3
+ import { toSnakeCase, deepCompare, toArray, columnToCode, addCode, codeToString, toCamelCase, toPascalCase, getImportPath, singleQuote, quoteObjectKey, pathToLog } from 'orchid-core';
3
4
  import { EnumColumn, DomainColumn, RawSQL, ArrayColumn, VirtualColumn, UnknownColumn, defaultSchemaConfig, columnsShapeToCode, pushTableDataCode, Adapter } from 'pqb';
4
- import { deepCompare, toArray, addCode, codeToString, toCamelCase, toPascalCase, getImportPath, singleQuote, quoteObjectKey, pathToLog } from 'orchid-core';
5
5
  import path from 'node:path';
6
6
  import { pathToFileURL } from 'url';
7
7
  import fs from 'fs/promises';
@@ -100,7 +100,16 @@ const promptCreateOrRename = (kind, name, drop, verifying) => {
100
100
  };
101
101
  const checkForColumnChange = (shape, key) => {
102
102
  const item = shape[key];
103
- return item && (Array.isArray(item) || item.type !== "rename");
103
+ if (item) {
104
+ return item && (Array.isArray(item) || item.type !== "rename");
105
+ }
106
+ for (const k in shape) {
107
+ const item2 = shape[k];
108
+ if (Array.isArray(item2) || item2.type !== "rename") {
109
+ return true;
110
+ }
111
+ }
112
+ return false;
104
113
  };
105
114
 
106
115
  const processSchemas = async (ast, schemas, dbStructure, verifying) => {
@@ -172,19 +181,19 @@ const renameSchemaInStructures = (items, from, to) => {
172
181
  }
173
182
  };
174
183
 
175
- var __defProp$6 = Object.defineProperty;
176
- var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
177
- var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
178
- var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
179
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
180
- var __spreadValues$6 = (a, b) => {
184
+ var __defProp$7 = Object.defineProperty;
185
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
186
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
187
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
188
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
189
+ var __spreadValues$7 = (a, b) => {
181
190
  for (var prop in b || (b = {}))
182
- if (__hasOwnProp$6.call(b, prop))
183
- __defNormalProp$6(a, prop, b[prop]);
184
- if (__getOwnPropSymbols$6)
185
- for (var prop of __getOwnPropSymbols$6(b)) {
186
- if (__propIsEnum$6.call(b, prop))
187
- __defNormalProp$6(a, prop, b[prop]);
191
+ if (__hasOwnProp$7.call(b, prop))
192
+ __defNormalProp$7(a, prop, b[prop]);
193
+ if (__getOwnPropSymbols$7)
194
+ for (var prop of __getOwnPropSymbols$7(b)) {
195
+ if (__propIsEnum$7.call(b, prop))
196
+ __defNormalProp$7(a, prop, b[prop]);
188
197
  }
189
198
  return a;
190
199
  };
@@ -218,7 +227,7 @@ const processExtensions = (ast, dbStructure, currentSchema, extensions) => {
218
227
  }
219
228
  if (codeExtensions == null ? void 0 : codeExtensions.length) {
220
229
  ast.push(
221
- ...codeExtensions.map((ext) => __spreadValues$6({
230
+ ...codeExtensions.map((ext) => __spreadValues$7({
222
231
  type: "extension",
223
232
  action: "create"
224
233
  }, ext))
@@ -226,23 +235,23 @@ const processExtensions = (ast, dbStructure, currentSchema, extensions) => {
226
235
  }
227
236
  };
228
237
 
229
- var __defProp$5 = Object.defineProperty;
230
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
231
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
232
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
233
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
234
- var __spreadValues$5 = (a, b) => {
238
+ var __defProp$6 = Object.defineProperty;
239
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
240
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
241
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
242
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
243
+ var __spreadValues$6 = (a, b) => {
235
244
  for (var prop in b || (b = {}))
236
- if (__hasOwnProp$5.call(b, prop))
237
- __defNormalProp$5(a, prop, b[prop]);
238
- if (__getOwnPropSymbols$5)
239
- for (var prop of __getOwnPropSymbols$5(b)) {
240
- if (__propIsEnum$5.call(b, prop))
241
- __defNormalProp$5(a, prop, b[prop]);
245
+ if (__hasOwnProp$6.call(b, prop))
246
+ __defNormalProp$6(a, prop, b[prop]);
247
+ if (__getOwnPropSymbols$6)
248
+ for (var prop of __getOwnPropSymbols$6(b)) {
249
+ if (__propIsEnum$6.call(b, prop))
250
+ __defNormalProp$6(a, prop, b[prop]);
242
251
  }
243
252
  return a;
244
253
  };
245
- const processColumns = async (adapter, structureToAstCtx, dbStructure, domainsMap, changeTableData, ast, currentSchema, compareSql, typeCastsCache, verifying) => {
254
+ const processColumns = async (adapter, config, structureToAstCtx, dbStructure, domainsMap, changeTableData, ast, currentSchema, compareSql, typeCastsCache, verifying) => {
246
255
  const { dbTable } = changeTableData;
247
256
  const dbColumns = Object.fromEntries(
248
257
  dbTable.columns.map((column) => [column.name, column])
@@ -255,6 +264,7 @@ const processColumns = async (adapter, structureToAstCtx, dbStructure, domainsMa
255
264
  changeTableData
256
265
  );
257
266
  await addOrRenameColumns(
267
+ config,
258
268
  dbStructure,
259
269
  changeTableData,
260
270
  columnsToAdd,
@@ -264,6 +274,7 @@ const processColumns = async (adapter, structureToAstCtx, dbStructure, domainsMa
264
274
  );
265
275
  await changeColumns(
266
276
  adapter,
277
+ config,
267
278
  structureToAstCtx,
268
279
  dbStructure,
269
280
  domainsMap,
@@ -283,6 +294,7 @@ const groupColumns = (structureToAstCtx, dbStructure, domainsMap, dbColumns, cha
283
294
  const columnsToAdd = [];
284
295
  const columnsToDrop = [];
285
296
  const columnsToChange = /* @__PURE__ */ new Map();
297
+ const columnsToChangeByDbName = /* @__PURE__ */ new Map();
286
298
  const { codeTable, dbTable, dbTableData } = changeTableData;
287
299
  const checks = getDbTableColumnsChecks(changeTableData.dbTableData);
288
300
  for (const key in codeTable.shape) {
@@ -291,13 +303,14 @@ const groupColumns = (structureToAstCtx, dbStructure, domainsMap, dbColumns, cha
291
303
  continue;
292
304
  const name = (_a = column.data.name) != null ? _a : key;
293
305
  if (dbColumns[name]) {
294
- columnsToChange.set(name, column);
306
+ columnsToChange.set(key, { key, dbName: name, column });
307
+ columnsToChangeByDbName.set(name, true);
295
308
  } else {
296
- columnsToAdd.push({ key: name, column });
309
+ columnsToAdd.push({ key, column });
297
310
  }
298
311
  }
299
312
  for (const name in dbColumns) {
300
- if (columnsToChange.has(name))
313
+ if (columnsToChangeByDbName.has(name))
301
314
  continue;
302
315
  const [key, column] = dbColumnToAst(
303
316
  structureToAstCtx,
@@ -317,46 +330,52 @@ const groupColumns = (structureToAstCtx, dbStructure, domainsMap, dbColumns, cha
317
330
  columnsToChange
318
331
  };
319
332
  };
320
- const addOrRenameColumns = async (dbStructure, {
333
+ const addOrRenameColumns = async (config, dbStructure, {
321
334
  dbTableData,
322
335
  schema,
323
336
  changeTableAst: { name: tableName, shape }
324
337
  }, columnsToAdd, columnsToDrop, columnsToChange, verifying) => {
325
- var _a, _b;
338
+ var _a, _b, _c, _d, _e;
326
339
  for (const { key, column } of columnsToAdd) {
327
340
  if (columnsToDrop.length) {
341
+ const codeName = (_a = column.data.name) != null ? _a : key;
328
342
  const index = await promptCreateOrRename(
329
343
  "column",
330
- (_a = column.data.name) != null ? _a : key,
344
+ codeName,
331
345
  columnsToDrop.map((x) => x.key),
332
346
  verifying
333
347
  );
334
348
  if (index) {
335
349
  const drop = columnsToDrop[index - 1];
336
350
  columnsToDrop.splice(index - 1, 1);
337
- const from = drop.key;
338
- columnsToChange.set(from, column.name(key));
351
+ const from = (_b = drop.column.data.name) != null ? _b : drop.key;
352
+ columnsToChange.set((_c = drop.column.data.name) != null ? _c : from, {
353
+ key,
354
+ dbName: (_d = drop.column.data.name) != null ? _d : from,
355
+ column: column.name(codeName)
356
+ });
357
+ const to = config.snakeCase ? toSnakeCase(key) : key;
339
358
  if (dbTableData.primaryKey) {
340
- renameColumn(dbTableData.primaryKey.columns, from, key);
359
+ renameColumn(dbTableData.primaryKey.columns, from, to);
341
360
  }
342
361
  for (const index2 of dbTableData.indexes) {
343
362
  for (const column2 of index2.columns) {
344
363
  if ("column" in column2 && column2.column === from) {
345
- column2.column = key;
364
+ column2.column = to;
346
365
  }
347
366
  }
348
367
  }
349
368
  for (const c of dbTableData.constraints) {
350
- if ((_b = c.check) == null ? void 0 : _b.columns) {
351
- renameColumn(c.check.columns, from, key);
369
+ if ((_e = c.check) == null ? void 0 : _e.columns) {
370
+ renameColumn(c.check.columns, from, to);
352
371
  }
353
372
  if (c.references) {
354
- renameColumn(c.references.columns, from, key);
373
+ renameColumn(c.references.columns, from, to);
355
374
  }
356
375
  }
357
376
  for (const c of dbStructure.constraints) {
358
377
  if (c.references && c.references.foreignSchema === schema && c.references.foreignTable === tableName) {
359
- renameColumn(c.references.foreignColumns, from, key);
378
+ renameColumn(c.references.foreignColumns, from, to);
360
379
  }
361
380
  }
362
381
  continue;
@@ -376,11 +395,14 @@ const dropColumns = ({ changeTableAst: { shape } }, columnsToDrop) => {
376
395
  };
377
396
  }
378
397
  };
379
- const changeColumns = async (adapter, structureToAstCtx, dbStructure, domainsMap, ast, currentSchema, dbColumns, columnsToChange, compareSql, changeTableData, typeCastsCache, verifying) => {
380
- var _a, _b, _c, _d, _e, _f;
381
- const { shape } = changeTableData.changeTableAst;
382
- for (const [name, codeColumn] of columnsToChange) {
383
- const dbColumnStructure = dbColumns[name];
398
+ const changeColumns = async (adapter, config, structureToAstCtx, dbStructure, domainsMap, ast, currentSchema, dbColumns, columnsToChange, compareSql, changeTableData, typeCastsCache, verifying) => {
399
+ var _a, _b, _c, _d, _e;
400
+ for (const [
401
+ key,
402
+ { key: codeKey, dbName, column: codeColumn }
403
+ ] of columnsToChange) {
404
+ const dbColumnStructure = dbColumns[dbName];
405
+ const { shape } = changeTableData.changeTableAst;
384
406
  let changed = false;
385
407
  const dbColumn = instantiateDbColumn(
386
408
  structureToAstCtx,
@@ -429,7 +451,7 @@ JOIN pg_type AS t ON t.oid = casttarget`);
429
451
  throw new AbortSignal();
430
452
  const tableName = concatSchemaAndName(changeTableData.changeTableAst);
431
453
  const abort = await promptSelect({
432
- message: `Cannot cast type of ${tableName}'s column ${name} from ${dbType} to ${codeType}`,
454
+ message: `Cannot cast type of ${tableName}'s column ${key} from ${dbType} to ${codeType}`,
433
455
  options: [
434
456
  `${colors.yellowBold(
435
457
  `-/+`
@@ -442,7 +464,8 @@ JOIN pg_type AS t ON t.oid = casttarget`);
442
464
  if (abort) {
443
465
  throw new AbortSignal();
444
466
  }
445
- shape[name] = [
467
+ dbColumn.data.name = codeColumn.data.name;
468
+ shape[key] = [
446
469
  {
447
470
  type: "drop",
448
471
  item: dbColumn
@@ -452,7 +475,7 @@ JOIN pg_type AS t ON t.oid = casttarget`);
452
475
  item: codeColumn
453
476
  }
454
477
  ];
455
- continue;
478
+ return;
456
479
  }
457
480
  }
458
481
  changed = true;
@@ -462,15 +485,15 @@ JOIN pg_type AS t ON t.oid = casttarget`);
462
485
  if (!changed) {
463
486
  if (!dbData.isNullable)
464
487
  dbData.isNullable = void 0;
465
- for (const key of ["isNullable", "comment"]) {
466
- if (dbData[key] !== codeData[key]) {
488
+ for (const key2 of ["isNullable", "comment"]) {
489
+ if (dbData[key2] !== codeData[key2]) {
467
490
  changed = true;
468
491
  break;
469
492
  }
470
493
  }
471
494
  }
472
495
  if (!changed) {
473
- for (const key of [
496
+ for (const key2 of [
474
497
  "maxChars",
475
498
  "collation",
476
499
  "compression",
@@ -478,7 +501,7 @@ JOIN pg_type AS t ON t.oid = casttarget`);
478
501
  "numericScale",
479
502
  "dateTimePrecision"
480
503
  ]) {
481
- if (key in codeData && dbData[key] !== codeData[key]) {
504
+ if (key2 in codeData && dbData[key2] !== codeData[key2]) {
482
505
  changed = true;
483
506
  break;
484
507
  }
@@ -486,7 +509,7 @@ JOIN pg_type AS t ON t.oid = casttarget`);
486
509
  }
487
510
  if (!changed && !deepCompare(
488
511
  dbData.identity,
489
- codeData.identity ? __spreadValues$5({
512
+ codeData.identity ? __spreadValues$6({
490
513
  always: false,
491
514
  start: 1,
492
515
  increment: 1,
@@ -518,7 +541,7 @@ JOIN pg_type AS t ON t.oid = casttarget`);
518
541
  inDb: dbDefault,
519
542
  inCode: codeDefault,
520
543
  change: () => {
521
- changeColumn(shape, name, dbColumn, codeColumn);
544
+ changeColumn(shape, key, dbColumn, codeColumn);
522
545
  if (!changeTableData.pushedAst) {
523
546
  changeTableData.pushedAst = true;
524
547
  ast.push(changeTableData.changeTableAst);
@@ -528,14 +551,13 @@ JOIN pg_type AS t ON t.oid = casttarget`);
528
551
  }
529
552
  }
530
553
  if (changed) {
531
- changeColumn(shape, name, dbColumn, codeColumn);
554
+ changeColumn(shape, key, dbColumn, codeColumn);
532
555
  } else {
533
- const from = (_e = dbColumn.data.name) != null ? _e : name;
534
- const to = (_f = codeColumn.data.name) != null ? _f : name;
535
- if (from !== to) {
536
- shape[from] = {
556
+ const to = (_e = codeColumn.data.name) != null ? _e : codeKey;
557
+ if (dbName !== to) {
558
+ shape[config.snakeCase ? dbName === toSnakeCase(codeKey) ? codeKey : dbName : dbName] = {
537
559
  type: "rename",
538
- name: to
560
+ name: config.snakeCase ? to === toSnakeCase(codeKey) ? codeKey : to : to
539
561
  };
540
562
  }
541
563
  }
@@ -730,19 +752,19 @@ const createAst = (codeDomain) => ({
730
752
  baseType: codeDomain.column
731
753
  });
732
754
 
733
- var __defProp$4 = Object.defineProperty;
734
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
735
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
736
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
737
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
738
- var __spreadValues$4 = (a, b) => {
755
+ var __defProp$5 = Object.defineProperty;
756
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
757
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
758
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
759
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
760
+ var __spreadValues$5 = (a, b) => {
739
761
  for (var prop in b || (b = {}))
740
- if (__hasOwnProp$4.call(b, prop))
741
- __defNormalProp$4(a, prop, b[prop]);
742
- if (__getOwnPropSymbols$4)
743
- for (var prop of __getOwnPropSymbols$4(b)) {
744
- if (__propIsEnum$4.call(b, prop))
745
- __defNormalProp$4(a, prop, b[prop]);
762
+ if (__hasOwnProp$5.call(b, prop))
763
+ __defNormalProp$5(a, prop, b[prop]);
764
+ if (__getOwnPropSymbols$5)
765
+ for (var prop of __getOwnPropSymbols$5(b)) {
766
+ if (__propIsEnum$5.call(b, prop))
767
+ __defNormalProp$5(a, prop, b[prop]);
746
768
  }
747
769
  return a;
748
770
  };
@@ -822,7 +844,7 @@ const processEnums = async (ast, enums, dbStructure, currentSchema, verifying) =
822
844
  continue;
823
845
  }
824
846
  }
825
- ast.push(__spreadValues$4({
847
+ ast.push(__spreadValues$5({
826
848
  type: "enum",
827
849
  action: "create"
828
850
  }, codeEnum));
@@ -883,20 +905,20 @@ const renameColumnsTypeSchema = (dbStructure, from, to) => {
883
905
  }
884
906
  };
885
907
 
886
- const processPrimaryKey = (ast, changeTableData) => {
908
+ const processPrimaryKey = (config, ast, changeTableData) => {
887
909
  var _a;
888
910
  const { codeTable } = changeTableData;
889
911
  const columnsPrimaryKey = [];
890
912
  for (const key in codeTable.shape) {
891
913
  const column = codeTable.shape[key];
892
914
  if (column.data.primaryKey) {
893
- columnsPrimaryKey.push((_a = column.data.name) != null ? _a : key);
915
+ columnsPrimaryKey.push({ key, name: (_a = column.data.name) != null ? _a : key });
894
916
  }
895
917
  }
896
- changePrimaryKey(columnsPrimaryKey, changeTableData);
918
+ changePrimaryKey(config, columnsPrimaryKey, changeTableData);
897
919
  renamePrimaryKey(ast, changeTableData);
898
920
  };
899
- const changePrimaryKey = (columnsPrimaryKey, {
921
+ const changePrimaryKey = (config, columnsPrimaryKey, {
900
922
  codeTable,
901
923
  dbTableData: { primaryKey: dbPrimaryKey },
902
924
  changeTableAst: { shape, add, drop }
@@ -904,19 +926,29 @@ const changePrimaryKey = (columnsPrimaryKey, {
904
926
  var _a;
905
927
  const tablePrimaryKey = codeTable.internal.tableData.primaryKey;
906
928
  const primaryKey = [
907
- .../* @__PURE__ */ new Set([...columnsPrimaryKey, ...(_a = tablePrimaryKey == null ? void 0 : tablePrimaryKey.columns) != null ? _a : []])
929
+ .../* @__PURE__ */ new Set([
930
+ ...columnsPrimaryKey,
931
+ ...(_a = config.snakeCase ? tablePrimaryKey == null ? void 0 : tablePrimaryKey.columns.map((key) => ({
932
+ key,
933
+ name: toSnakeCase(key)
934
+ })) : tablePrimaryKey == null ? void 0 : tablePrimaryKey.columns.map((key) => ({ key, name: key }))) != null ? _a : []
935
+ ])
908
936
  ];
909
- if (!dbPrimaryKey || primaryKey.length !== dbPrimaryKey.columns.length || primaryKey.some((a) => !dbPrimaryKey.columns.some((b) => a === b))) {
937
+ if (!dbPrimaryKey || primaryKey.length !== dbPrimaryKey.columns.length || primaryKey.some(
938
+ ({ name }) => !dbPrimaryKey.columns.some((dbName) => name === dbName)
939
+ )) {
910
940
  const toDrop = dbPrimaryKey == null ? void 0 : dbPrimaryKey.columns.filter(
911
941
  (key) => !checkForColumnChange(shape, key)
912
942
  );
913
943
  if (toDrop == null ? void 0 : toDrop.length) {
914
944
  drop.primaryKey = { columns: toDrop, name: dbPrimaryKey == null ? void 0 : dbPrimaryKey.name };
915
945
  }
916
- const toAdd = primaryKey.filter((key) => !checkForColumnChange(shape, key));
946
+ const toAdd = primaryKey.filter(
947
+ ({ key }) => !checkForColumnChange(shape, key)
948
+ );
917
949
  if (toAdd.length) {
918
950
  add.primaryKey = {
919
- columns: toAdd,
951
+ columns: toAdd.map((c) => c.key),
920
952
  name: tablePrimaryKey == null ? void 0 : tablePrimaryKey.name
921
953
  };
922
954
  }
@@ -941,40 +973,43 @@ const renamePrimaryKey = (ast, {
941
973
  }
942
974
  };
943
975
 
944
- var __defProp$3 = Object.defineProperty;
945
- var __defProps$3 = Object.defineProperties;
946
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
947
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
948
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
949
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
950
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
951
- var __spreadValues$3 = (a, b) => {
976
+ var __defProp$4 = Object.defineProperty;
977
+ var __defProps$4 = Object.defineProperties;
978
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
979
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
980
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
981
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
982
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
983
+ var __spreadValues$4 = (a, b) => {
952
984
  for (var prop in b || (b = {}))
953
- if (__hasOwnProp$3.call(b, prop))
954
- __defNormalProp$3(a, prop, b[prop]);
955
- if (__getOwnPropSymbols$3)
956
- for (var prop of __getOwnPropSymbols$3(b)) {
957
- if (__propIsEnum$3.call(b, prop))
958
- __defNormalProp$3(a, prop, b[prop]);
985
+ if (__hasOwnProp$4.call(b, prop))
986
+ __defNormalProp$4(a, prop, b[prop]);
987
+ if (__getOwnPropSymbols$4)
988
+ for (var prop of __getOwnPropSymbols$4(b)) {
989
+ if (__propIsEnum$4.call(b, prop))
990
+ __defNormalProp$4(a, prop, b[prop]);
959
991
  }
960
992
  return a;
961
993
  };
962
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
994
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
963
995
  var __objRest = (source, exclude) => {
964
996
  var target = {};
965
997
  for (var prop in source)
966
- if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
998
+ if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
967
999
  target[prop] = source[prop];
968
- if (source != null && __getOwnPropSymbols$3)
969
- for (var prop of __getOwnPropSymbols$3(source)) {
970
- if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
1000
+ if (source != null && __getOwnPropSymbols$4)
1001
+ for (var prop of __getOwnPropSymbols$4(source)) {
1002
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
971
1003
  target[prop] = source[prop];
972
1004
  }
973
1005
  return target;
974
1006
  };
975
1007
  const processIndexes = (config, changeTableData, delayedAst, ast, compareExpressions) => {
976
- const codeIndexes = collectCodeIndexes(changeTableData);
977
- const codeComparableIndexes = collectCodeComparableIndexes(codeIndexes);
1008
+ const codeIndexes = collectCodeIndexes(config, changeTableData);
1009
+ const codeComparableIndexes = collectCodeComparableIndexes(
1010
+ config,
1011
+ codeIndexes
1012
+ );
978
1013
  const skipCodeIndexes = /* @__PURE__ */ new Map();
979
1014
  const holdCodeIndexes = /* @__PURE__ */ new Map();
980
1015
  let wait = 0;
@@ -1069,13 +1104,13 @@ const processIndexes = (config, changeTableData, delayedAst, ast, compareExpress
1069
1104
  (index, i) => !skipCodeIndexes.has(i) && !holdCodeIndexes.has(index)
1070
1105
  );
1071
1106
  if (addIndexes.length) {
1072
- changeTableData.changeTableAst.add.indexes = addIndexes;
1107
+ changeTableData.changeTableAst.add.indexes = addIndexes.map((x) => __spreadProps$4(__spreadValues$4({}, x), {
1108
+ columns: x.columnKeys,
1109
+ options: x.options.include ? __spreadProps$4(__spreadValues$4({}, x.options), { include: x.includeKeys }) : x.options
1110
+ }));
1073
1111
  }
1074
1112
  };
1075
- const collectCodeIndexes = ({
1076
- codeTable,
1077
- changeTableAst: { shape }
1078
- }) => {
1113
+ const collectCodeIndexes = (config, { codeTable, changeTableAst: { shape } }) => {
1079
1114
  var _a;
1080
1115
  const codeIndexes = [];
1081
1116
  for (const key in codeTable.shape) {
@@ -1093,26 +1128,52 @@ const collectCodeIndexes = ({
1093
1128
  } = _c, _e = _d, { collate, opclass, order, weight } = _e, options = __objRest(_e, ["collate", "opclass", "order", "weight"]), index = __objRest(_c, [
1094
1129
  "options"
1095
1130
  ]);
1096
- return __spreadValues$3({
1097
- columns: [{ collate, opclass, order, weight, column: name }],
1098
- options
1099
- }, index);
1131
+ return __spreadProps$4(__spreadValues$4({
1132
+ columns: [
1133
+ {
1134
+ collate,
1135
+ opclass,
1136
+ order,
1137
+ weight,
1138
+ column: name
1139
+ }
1140
+ ]
1141
+ }, index), {
1142
+ options: options.include ? config.snakeCase ? __spreadProps$4(__spreadValues$4({}, options), {
1143
+ include: toArray(options.include).map(toSnakeCase)
1144
+ }) : options : options,
1145
+ columnKeys: [{ collate, opclass, order, weight, column: key }],
1146
+ includeKeys: options.include
1147
+ });
1100
1148
  }
1101
1149
  )
1102
1150
  );
1103
1151
  }
1104
1152
  if (codeTable.internal.tableData.indexes) {
1105
- codeIndexes.push(...codeTable.internal.tableData.indexes);
1153
+ codeIndexes.push(
1154
+ ...codeTable.internal.tableData.indexes.map((x) => __spreadProps$4(__spreadValues$4({}, x), {
1155
+ columns: config.snakeCase ? x.columns.map(
1156
+ (c) => "column" in c ? __spreadProps$4(__spreadValues$4({}, c), { column: toSnakeCase(c.column) }) : c
1157
+ ) : x.columns,
1158
+ columnKeys: x.columns,
1159
+ options: x.options.include && config.snakeCase ? __spreadProps$4(__spreadValues$4({}, x.options), {
1160
+ include: toArray(x.options.include).map(toSnakeCase)
1161
+ }) : x.options,
1162
+ includeKeys: x.options.include
1163
+ }))
1164
+ );
1106
1165
  }
1107
1166
  return codeIndexes;
1108
1167
  };
1109
- const collectCodeComparableIndexes = (codeIndexes) => {
1168
+ const collectCodeComparableIndexes = (config, codeIndexes) => {
1110
1169
  return codeIndexes.map((codeIndex) => {
1111
1170
  normalizeIndex(codeIndex.options);
1112
- return indexToComparable(__spreadProps$3(__spreadValues$3({}, codeIndex.options), {
1113
- include: codeIndex.options.include === void 0 ? void 0 : toArray(codeIndex.options.include),
1171
+ return indexToComparable(__spreadProps$4(__spreadValues$4({}, codeIndex.options), {
1172
+ include: codeIndex.options.include === void 0 ? void 0 : config.snakeCase ? toArray(codeIndex.options.include).map(toSnakeCase) : toArray(codeIndex.options.include),
1114
1173
  columns: codeIndex.columns,
1115
- name: codeIndex.name
1174
+ name: codeIndex.name,
1175
+ columnKeys: codeIndex.columnKeys,
1176
+ includeKeys: codeIndex.includeKeys
1116
1177
  }));
1117
1178
  });
1118
1179
  };
@@ -1127,7 +1188,7 @@ const normalizeIndex = (index) => {
1127
1188
  const indexToComparable = (index) => {
1128
1189
  let hasExpression = false;
1129
1190
  const columns = index.columns.map((column) => {
1130
- const result = __spreadProps$3(__spreadValues$3({}, column), {
1191
+ const result = __spreadProps$4(__spreadValues$4({}, column), {
1131
1192
  expression: void 0,
1132
1193
  hasExpression: "expression" in column
1133
1194
  });
@@ -1135,7 +1196,7 @@ const indexToComparable = (index) => {
1135
1196
  hasExpression = true;
1136
1197
  return result;
1137
1198
  });
1138
- return __spreadProps$3(__spreadValues$3({}, index), {
1199
+ return __spreadProps$4(__spreadValues$4({}, index), {
1139
1200
  schemaName: void 0,
1140
1201
  tableName: void 0,
1141
1202
  with: void 0,
@@ -1160,8 +1221,12 @@ const findMatchingIndexWithoutSql = (dbIndex, codeComparableIndexes, codeIndexes
1160
1221
  let b = codeIndex;
1161
1222
  const codeName = (_c = b.name) != null ? _c : getIndexName(tableName, dbColumns);
1162
1223
  if (a.name !== b.name) {
1163
- a = __spreadProps$3(__spreadValues$3({}, a), { name: void 0 });
1164
- b = __spreadProps$3(__spreadValues$3({}, b), { name: void 0 });
1224
+ a = __spreadProps$4(__spreadValues$4({}, a), { name: void 0 });
1225
+ b = __spreadProps$4(__spreadValues$4({}, b), {
1226
+ name: void 0,
1227
+ columnKeys: void 0,
1228
+ includeKeys: void 0
1229
+ });
1165
1230
  if (a.language && !b.language) {
1166
1231
  b.language = (_d = config.language) != null ? _d : "english";
1167
1232
  }
@@ -1171,9 +1236,16 @@ const findMatchingIndexWithoutSql = (dbIndex, codeComparableIndexes, codeIndexes
1171
1236
  dbIndexWithoutColumns.name !== codeName ? codeName : void 0
1172
1237
  );
1173
1238
  }
1174
- } else if (deepCompare(dbIndexWithoutColumns, codeIndex)) {
1175
- found.push(codeIndexes[i]);
1176
- rename.push(void 0);
1239
+ } else {
1240
+ const _e = codeIndex, codeIndexWithoutKeys = __objRest(_e, [
1241
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1242
+ "columnKeys",
1243
+ "includeKeys"
1244
+ ]);
1245
+ if (deepCompare(dbIndexWithoutColumns, codeIndexWithoutKeys)) {
1246
+ found.push(codeIndexes[i]);
1247
+ rename.push(void 0);
1248
+ }
1177
1249
  }
1178
1250
  if (found.length && !checkIfIndexHasSql(codeIndex)) {
1179
1251
  skipCodeIndexes.set(i, true);
@@ -1203,6 +1275,25 @@ const handleIndexChange = (ast, { changeTableAst, schema, codeTable }, dbIndex,
1203
1275
  }
1204
1276
  };
1205
1277
 
1278
+ var __defProp$3 = Object.defineProperty;
1279
+ var __defProps$3 = Object.defineProperties;
1280
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
1281
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
1282
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
1283
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
1284
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1285
+ var __spreadValues$3 = (a, b) => {
1286
+ for (var prop in b || (b = {}))
1287
+ if (__hasOwnProp$3.call(b, prop))
1288
+ __defNormalProp$3(a, prop, b[prop]);
1289
+ if (__getOwnPropSymbols$3)
1290
+ for (var prop of __getOwnPropSymbols$3(b)) {
1291
+ if (__propIsEnum$3.call(b, prop))
1292
+ __defNormalProp$3(a, prop, b[prop]);
1293
+ }
1294
+ return a;
1295
+ };
1296
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
1206
1297
  const mapMatchToDb = {
1207
1298
  FULL: "f",
1208
1299
  PARTIAL: "p",
@@ -1223,10 +1314,14 @@ const mapActionToCode = {};
1223
1314
  for (const key in mapActionToDb) {
1224
1315
  mapActionToCode[mapActionToDb[key]] = key;
1225
1316
  }
1226
- const processForeignKeys = (ast, changeTables, currentSchema, tableShapes) => {
1317
+ const processForeignKeys = (config, ast, changeTables, currentSchema, tableShapes) => {
1227
1318
  var _a, _b, _c;
1228
1319
  for (const changeTableData of changeTables) {
1229
- const codeForeignKeys = collectCodeFkeys(changeTableData, currentSchema);
1320
+ const codeForeignKeys = collectCodeFkeys(
1321
+ config,
1322
+ changeTableData,
1323
+ currentSchema
1324
+ );
1230
1325
  const { codeTable, dbTableData, changeTableAst, schema } = changeTableData;
1231
1326
  const { shape, add, drop } = changeTableAst;
1232
1327
  let changed = false;
@@ -1253,7 +1348,11 @@ const processForeignKeys = (ast, changeTables, currentSchema, tableShapes) => {
1253
1348
  if (deepCompare(dbReferences, codeReferences)) {
1254
1349
  found = true;
1255
1350
  codeForeignKeys.splice(i, 1);
1256
- const codeName = (_a = codeForeignKey.codeConstraint.name) != null ? _a : getConstraintName(codeTable.table, codeForeignKey);
1351
+ const codeName = (_a = codeForeignKey.codeConstraint.name) != null ? _a : getConstraintName(
1352
+ codeTable.table,
1353
+ codeForeignKey,
1354
+ config.snakeCase
1355
+ );
1257
1356
  if (codeName !== dbConstraint.name) {
1258
1357
  rename = codeName;
1259
1358
  }
@@ -1261,7 +1360,7 @@ const processForeignKeys = (ast, changeTables, currentSchema, tableShapes) => {
1261
1360
  }
1262
1361
  if (!found) {
1263
1362
  ((_b = drop.constraints) != null ? _b : drop.constraints = []).push(
1264
- dbForeignKeyToCodeForeignKey(dbConstraint, dbReferences)
1363
+ dbForeignKeyToCodeForeignKey(config, dbConstraint, dbReferences)
1265
1364
  );
1266
1365
  changed = true;
1267
1366
  } else if (rename) {
@@ -1287,7 +1386,7 @@ const processForeignKeys = (ast, changeTables, currentSchema, tableShapes) => {
1287
1386
  }
1288
1387
  }
1289
1388
  };
1290
- const collectCodeFkeys = ({ codeTable, changeTableAst: { shape } }, currentSchema) => {
1389
+ const collectCodeFkeys = (config, { codeTable, changeTableAst: { shape } }, currentSchema) => {
1291
1390
  var _a;
1292
1391
  const codeForeignKeys = [];
1293
1392
  for (const key in codeTable.shape) {
@@ -1301,33 +1400,48 @@ const collectCodeFkeys = ({ codeTable, changeTableAst: { shape } }, currentSchem
1301
1400
  ...column.data.foreignKeys.map((x) => {
1302
1401
  var _a2;
1303
1402
  const columns = [name];
1304
- const references = {
1305
- columns,
1306
- fnOrTable: fnOrTableToString(x.fnOrTable),
1307
- foreignColumns: x.foreignColumns,
1308
- options: x.options
1309
- };
1403
+ const fnOrTable = fnOrTableToString(x.fnOrTable);
1310
1404
  return parseForeignKey(
1405
+ config,
1311
1406
  {
1312
1407
  name: (_a2 = x.options) == null ? void 0 : _a2.name,
1313
- references
1408
+ references: {
1409
+ columns: [key],
1410
+ fnOrTable,
1411
+ foreignColumns: x.foreignColumns,
1412
+ options: x.options
1413
+ }
1414
+ },
1415
+ {
1416
+ columns,
1417
+ fnOrTable,
1418
+ foreignColumns: x.foreignColumns,
1419
+ options: x.options
1314
1420
  },
1315
- references,
1316
1421
  currentSchema
1317
1422
  );
1318
1423
  })
1319
1424
  );
1320
1425
  }
1321
1426
  if (codeTable.internal.tableData.constraints) {
1322
- for (const constraint of codeTable.internal.tableData.constraints) {
1323
- const { references } = constraint;
1324
- if (!references)
1427
+ for (const tableConstraint of codeTable.internal.tableData.constraints) {
1428
+ const { references: refs } = tableConstraint;
1429
+ if (!refs)
1325
1430
  continue;
1326
- references.fnOrTable = fnOrTableToString(references.fnOrTable);
1431
+ const fnOrTable = fnOrTableToString(refs.fnOrTable);
1327
1432
  codeForeignKeys.push(
1328
1433
  parseForeignKey(
1329
- constraint,
1330
- references,
1434
+ config,
1435
+ __spreadProps$3(__spreadValues$3({}, tableConstraint), {
1436
+ references: __spreadProps$3(__spreadValues$3({}, refs), {
1437
+ fnOrTable
1438
+ })
1439
+ }),
1440
+ __spreadProps$3(__spreadValues$3({}, refs), {
1441
+ fnOrTable,
1442
+ columns: config.snakeCase ? refs.columns.map(toSnakeCase) : refs.columns,
1443
+ foreignColumns: config.snakeCase ? refs.foreignColumns.map(toSnakeCase) : refs.foreignColumns
1444
+ }),
1331
1445
  currentSchema
1332
1446
  )
1333
1447
  );
@@ -1342,7 +1456,7 @@ const fnOrTableToString = (fnOrTable) => {
1342
1456
  }
1343
1457
  return fnOrTable;
1344
1458
  };
1345
- const parseForeignKey = (codeConstraint, references, currentSchema) => {
1459
+ const parseForeignKey = (config, codeConstraint, references, currentSchema) => {
1346
1460
  const { fnOrTable, columns, foreignColumns, options } = references;
1347
1461
  const [schema, table] = getSchemaAndTableFromName(fnOrTable);
1348
1462
  return {
@@ -1350,7 +1464,7 @@ const parseForeignKey = (codeConstraint, references, currentSchema) => {
1350
1464
  foreignSchema: schema != null ? schema : currentSchema,
1351
1465
  foreignTable: table,
1352
1466
  columns,
1353
- foreignColumns,
1467
+ foreignColumns: config.snakeCase ? foreignColumns.map(toSnakeCase) : foreignColumns,
1354
1468
  match: mapMatchToDb[(options == null ? void 0 : options.match) || "SIMPLE"],
1355
1469
  onUpdate: mapActionToDb[(options == null ? void 0 : options.onUpdate) || "NO ACTION"],
1356
1470
  onDelete: mapActionToDb[(options == null ? void 0 : options.onDelete) || "NO ACTION"]
@@ -1358,8 +1472,12 @@ const parseForeignKey = (codeConstraint, references, currentSchema) => {
1358
1472
  codeConstraint
1359
1473
  };
1360
1474
  };
1361
- const dbForeignKeyToCodeForeignKey = (dbConstraint, dbReferences) => ({
1362
- name: dbConstraint.name === getConstraintName(dbConstraint.tableName, { references: dbReferences }) ? void 0 : dbConstraint.name,
1475
+ const dbForeignKeyToCodeForeignKey = (config, dbConstraint, dbReferences) => ({
1476
+ name: dbConstraint.name === getConstraintName(
1477
+ dbConstraint.tableName,
1478
+ { references: dbReferences },
1479
+ config.snakeCase
1480
+ ) ? void 0 : dbConstraint.name,
1363
1481
  references: {
1364
1482
  columns: dbReferences.columns,
1365
1483
  fnOrTable: `${dbReferences.foreignSchema}.${dbReferences.foreignTable}`,
@@ -1521,7 +1639,7 @@ const processTables = async (ast, structureToAstCtx, domainsMap, adapter, tables
1521
1639
  tableExpressions,
1522
1640
  verifying
1523
1641
  );
1524
- processForeignKeys(ast, changeTables, currentSchema, tableShapes);
1642
+ processForeignKeys(config, ast, changeTables, currentSchema, tableShapes);
1525
1643
  await Promise.all([
1526
1644
  applyCompareSql(compareSql, adapter),
1527
1645
  compareSqlExpressions(tableExpressions, adapter)
@@ -1731,6 +1849,7 @@ const makeTableShape = (table) => {
1731
1849
  const processTableChange = async (adapter, structureToAstCtx, dbStructure, domainsMap, ast, currentSchema, config, changeTableData, compareSql, compareExpressions, typeCastsCache, verifying) => {
1732
1850
  await processColumns(
1733
1851
  adapter,
1852
+ config,
1734
1853
  structureToAstCtx,
1735
1854
  dbStructure,
1736
1855
  domainsMap,
@@ -1742,7 +1861,7 @@ const processTableChange = async (adapter, structureToAstCtx, dbStructure, domai
1742
1861
  verifying
1743
1862
  );
1744
1863
  const delayedAst = [];
1745
- processPrimaryKey(delayedAst, changeTableData);
1864
+ processPrimaryKey(config, delayedAst, changeTableData);
1746
1865
  processIndexes(config, changeTableData, delayedAst, ast, compareExpressions);
1747
1866
  processChecks(ast, changeTableData, compareExpressions);
1748
1867
  const { changeTableAst } = changeTableData;
@@ -1832,7 +1951,7 @@ const verifyMigration = async (adapter, config, migrationCode, generateMigration
1832
1951
  };
1833
1952
 
1834
1953
  const report = (ast, config, currentSchema) => {
1835
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1954
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1836
1955
  if (!config.logger)
1837
1956
  return;
1838
1957
  const code = [];
@@ -1898,25 +2017,34 @@ const report = (ast, config, currentSchema) => {
1898
2017
  for (const change of changes) {
1899
2018
  if (change.type === "add" || change.type === "drop") {
1900
2019
  const column = change.item;
1901
- const name = (_g = column.data.name) != null ? _g : key;
1902
2020
  const { primaryKey, indexes, foreignKeys, check } = column.data;
1903
2021
  inner.push(
1904
- `${change.type === "add" ? green("+ add column") : red("- drop column")} ${name} ${(_h = column.data.alias) != null ? _h : getColumnDbType(column, currentSchema)}${column.data.isNullable ? " nullable" : ""}${primaryKey ? " primary key" : ""}${foreignKeys ? ` references ${foreignKeys.map((fk) => {
2022
+ `${change.type === "add" ? green("+ add column") : red("- drop column")} ${key} ${(_g = column.data.alias) != null ? _g : getColumnDbType(column, currentSchema)}${column.data.isNullable ? " nullable" : ""}${primaryKey ? " primary key" : ""}${foreignKeys ? ` references ${foreignKeys.map((fk) => {
1905
2023
  return `${fnOrTableToString(
1906
2024
  fk.fnOrTable
1907
2025
  )}(${fk.foreignColumns.join(", ")})`;
1908
2026
  }).join(", ")}` : ""}${(indexes == null ? void 0 : indexes.length) ? indexes.length === 1 ? ", has index" : `, has ${indexes.length} indexes` : ""}${check ? `, checks ${check.sql.toSQL({ values: [] })}` : ""}`
1909
2027
  );
1910
2028
  } else if (change.type === "change") {
1911
- const name = (_j = (_i = change.from.column) == null ? void 0 : _i.data.name) != null ? _j : key;
2029
+ const name = (_i = (_h = change.from.column) == null ? void 0 : _h.data.name) != null ? _i : key;
1912
2030
  const changes2 = [];
1913
2031
  inner.push(`${yellow("~ change column")} ${name}:`, changes2);
1914
2032
  changes2.push(`${yellow("from")}: `);
1915
- for (const code2 of change.from.column.toCode("t", true)) {
2033
+ const fromCode = columnToCode(
2034
+ key,
2035
+ change.from.column,
2036
+ config.snakeCase
2037
+ );
2038
+ for (const code2 of fromCode) {
1916
2039
  addCode(changes2, code2);
1917
2040
  }
1918
2041
  changes2.push(` ${yellow("to")}: `);
1919
- for (const code2 of change.to.column.toCode("t", true)) {
2042
+ const toCode = columnToCode(
2043
+ key,
2044
+ change.to.column,
2045
+ config.snakeCase
2046
+ );
2047
+ for (const code2 of toCode) {
1920
2048
  addCode(changes2, code2);
1921
2049
  }
1922
2050
  } else if (change.type === "rename") {
@@ -2405,11 +2533,12 @@ const processEnumColumn = (column, currentSchema, codeItems) => {
2405
2533
  codeItems.schemas.add(schema);
2406
2534
  };
2407
2535
  const processHasAndBelongsToManyColumn = (column, habtmTables, codeItems) => {
2536
+ var _a, _b;
2408
2537
  const q = column.joinTable;
2409
2538
  const prev = habtmTables.get(q.table);
2410
2539
  if (prev) {
2411
2540
  for (const key in q.shape) {
2412
- if (q.shape[key] !== prev.shape[key]) {
2541
+ if (q.shape[key].dataType !== ((_a = prev.shape[key]) == null ? void 0 : _a.dataType)) {
2413
2542
  throw new Error(
2414
2543
  `Column ${key} in ${q.table} in hasAndBelongsToMany relation does not match with the relation on the other side`
2415
2544
  );
@@ -2423,11 +2552,12 @@ const processHasAndBelongsToManyColumn = (column, habtmTables, codeItems) => {
2423
2552
  for (const key in joinTable.shape) {
2424
2553
  const column2 = Object.create(joinTable.shape[key]);
2425
2554
  column2.data = __spreadProps$1(__spreadValues$1({}, column2.data), {
2555
+ name: (_b = column2.data.name) != null ? _b : key,
2426
2556
  identity: void 0,
2427
2557
  primaryKey: void 0,
2428
2558
  default: void 0
2429
2559
  });
2430
- shape[key] = column2;
2560
+ shape[toCamelCase(key)] = column2;
2431
2561
  }
2432
2562
  joinTable.shape = shape;
2433
2563
  joinTable.internal = __spreadProps$1(__spreadValues$1({}, joinTable.internal), {