orchid-orm 1.31.7 → 1.32.0

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