relq 1.0.92 → 1.0.94

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.
@@ -297,8 +297,9 @@ function mergeRelationsIntoAST(result, relations) {
297
297
  if (fk.$onUpdate && fk.$onUpdate !== 'NO ACTION') {
298
298
  definition += ` ON UPDATE ${fk.$onUpdate}`;
299
299
  }
300
+ const constraintName = fk.$name || `${sourceTableSqlName}_${sourceColumns.join('_')}_fkey`;
300
301
  const constraint = {
301
- name: '',
302
+ name: constraintName,
302
303
  type: 'FOREIGN KEY',
303
304
  columns: sourceColumns,
304
305
  references: {
@@ -431,6 +432,19 @@ function tableToAST(table) {
431
432
  });
432
433
  }
433
434
  }
435
+ for (const col of columns) {
436
+ if (!col.isUnique)
437
+ continue;
438
+ const hasUniqueConstraint = constraints.some(c => c.type === 'UNIQUE' && c.columns.length === 1 && c.columns[0] === col.name);
439
+ if (!hasUniqueConstraint) {
440
+ constraints.push({
441
+ name: `${table.$name}_${col.name}_key`,
442
+ type: 'UNIQUE',
443
+ columns: [col.name],
444
+ trackingId: `${table.$name}_${col.name}_key`,
445
+ });
446
+ }
447
+ }
434
448
  return {
435
449
  name: table.$name,
436
450
  schema: table.$schema || 'public',
@@ -14,7 +14,8 @@ function createTargetColumnRefs(table) {
14
14
  const actualTableName = table.$name;
15
15
  for (const colName of Object.keys(table.$columns)) {
16
16
  const colDef = table.$columns[colName];
17
- const actualColName = colDef.$sqlName || colName;
17
+ const config = colDef?.$config || colDef;
18
+ const actualColName = config?.$sqlName || config?.$columnName || colDef?.$sqlName || colDef?.$columnName || colName;
18
19
  refs[colName] = createColumnRef(actualTableName, actualColName, colName);
19
20
  }
20
21
  return refs;
@@ -40,7 +41,8 @@ function createReferenceToBuilder(schema, currentTableKey) {
40
41
  const toSqlColumnName = (tsColName) => {
41
42
  const colDef = currentTable.$columns?.[tsColName];
42
43
  if (colDef) {
43
- return colDef.$sqlName || tsColName;
44
+ const config = colDef.$config || colDef;
45
+ return config.$sqlName || config.$columnName || colDef.$sqlName || colDef.$columnName || tsColName;
44
46
  }
45
47
  return tsColName;
46
48
  };
@@ -79,9 +81,11 @@ function createReferenceToBuilder(schema, currentTableKey) {
79
81
  $onDelete: options.onDelete,
80
82
  $onUpdate: options.onUpdate,
81
83
  $match: options.match,
84
+ $name: options.name,
82
85
  $deferrable: options.deferrable,
83
86
  $initiallyDeferred: options.initiallyDeferred,
84
87
  $trackingId: options.trackingId,
88
+ $comment: options.comment,
85
89
  };
86
90
  };
87
91
  },
@@ -5216,12 +5216,16 @@ export interface ForeignKeyRelationDef {
5216
5216
  $onUpdate?: ReferentialAction;
5217
5217
  /** MATCH type */
5218
5218
  $match?: MatchType;
5219
+ /** Explicit constraint name */
5220
+ $name?: string;
5219
5221
  /** DEFERRABLE flag */
5220
5222
  $deferrable?: boolean;
5221
5223
  /** INITIALLY DEFERRED flag */
5222
5224
  $initiallyDeferred?: boolean;
5223
5225
  /** Tracking ID for rename detection */
5224
5226
  $trackingId?: string;
5227
+ /** Comment for documentation */
5228
+ $comment?: string;
5225
5229
  }
5226
5230
  /** Relation definition type */
5227
5231
  export type RelationDef = ForeignKeyRelationDef;
@@ -4815,12 +4815,16 @@ export interface ForeignKeyRelationDef {
4815
4815
  $onUpdate?: ReferentialAction;
4816
4816
  /** MATCH type */
4817
4817
  $match?: MatchType;
4818
+ /** Explicit constraint name */
4819
+ $name?: string;
4818
4820
  /** DEFERRABLE flag */
4819
4821
  $deferrable?: boolean;
4820
4822
  /** INITIALLY DEFERRED flag */
4821
4823
  $initiallyDeferred?: boolean;
4822
4824
  /** Tracking ID for rename detection */
4823
4825
  $trackingId?: string;
4826
+ /** Comment for documentation */
4827
+ $comment?: string;
4824
4828
  }
4825
4829
  /** Relation definition type */
4826
4830
  export type RelationDef = ForeignKeyRelationDef;
@@ -263,8 +263,9 @@ function mergeRelationsIntoAST(result, relations) {
263
263
  if (fk.$onUpdate && fk.$onUpdate !== 'NO ACTION') {
264
264
  definition += ` ON UPDATE ${fk.$onUpdate}`;
265
265
  }
266
+ const constraintName = fk.$name || `${sourceTableSqlName}_${sourceColumns.join('_')}_fkey`;
266
267
  const constraint = {
267
- name: '',
268
+ name: constraintName,
268
269
  type: 'FOREIGN KEY',
269
270
  columns: sourceColumns,
270
271
  references: {
@@ -397,6 +398,19 @@ export function tableToAST(table) {
397
398
  });
398
399
  }
399
400
  }
401
+ for (const col of columns) {
402
+ if (!col.isUnique)
403
+ continue;
404
+ const hasUniqueConstraint = constraints.some(c => c.type === 'UNIQUE' && c.columns.length === 1 && c.columns[0] === col.name);
405
+ if (!hasUniqueConstraint) {
406
+ constraints.push({
407
+ name: `${table.$name}_${col.name}_key`,
408
+ type: 'UNIQUE',
409
+ columns: [col.name],
410
+ trackingId: `${table.$name}_${col.name}_key`,
411
+ });
412
+ }
413
+ }
400
414
  return {
401
415
  name: table.$name,
402
416
  schema: table.$schema || 'public',
@@ -10,7 +10,8 @@ function createTargetColumnRefs(table) {
10
10
  const actualTableName = table.$name;
11
11
  for (const colName of Object.keys(table.$columns)) {
12
12
  const colDef = table.$columns[colName];
13
- const actualColName = colDef.$sqlName || colName;
13
+ const config = colDef?.$config || colDef;
14
+ const actualColName = config?.$sqlName || config?.$columnName || colDef?.$sqlName || colDef?.$columnName || colName;
14
15
  refs[colName] = createColumnRef(actualTableName, actualColName, colName);
15
16
  }
16
17
  return refs;
@@ -36,7 +37,8 @@ export function createReferenceToBuilder(schema, currentTableKey) {
36
37
  const toSqlColumnName = (tsColName) => {
37
38
  const colDef = currentTable.$columns?.[tsColName];
38
39
  if (colDef) {
39
- return colDef.$sqlName || tsColName;
40
+ const config = colDef.$config || colDef;
41
+ return config.$sqlName || config.$columnName || colDef.$sqlName || colDef.$columnName || tsColName;
40
42
  }
41
43
  return tsColName;
42
44
  };
@@ -75,9 +77,11 @@ export function createReferenceToBuilder(schema, currentTableKey) {
75
77
  $onDelete: options.onDelete,
76
78
  $onUpdate: options.onUpdate,
77
79
  $match: options.match,
80
+ $name: options.name,
78
81
  $deferrable: options.deferrable,
79
82
  $initiallyDeferred: options.initiallyDeferred,
80
83
  $trackingId: options.trackingId,
84
+ $comment: options.comment,
81
85
  };
82
86
  };
83
87
  },
package/dist/index.d.ts CHANGED
@@ -6607,12 +6607,16 @@ export interface ForeignKeyRelationDef {
6607
6607
  $onUpdate?: ReferentialAction;
6608
6608
  /** MATCH type */
6609
6609
  $match?: MatchType;
6610
+ /** Explicit constraint name */
6611
+ $name?: string;
6610
6612
  /** DEFERRABLE flag */
6611
6613
  $deferrable?: boolean;
6612
6614
  /** INITIALLY DEFERRED flag */
6613
6615
  $initiallyDeferred?: boolean;
6614
6616
  /** Tracking ID for rename detection */
6615
6617
  $trackingId?: string;
6618
+ /** Comment for documentation */
6619
+ $comment?: string;
6616
6620
  }
6617
6621
  /** Relation definition type */
6618
6622
  export type RelationDef = ForeignKeyRelationDef;
@@ -6695,12 +6695,16 @@ export interface ForeignKeyRelationDef {
6695
6695
  $onUpdate?: ReferentialAction;
6696
6696
  /** MATCH type */
6697
6697
  $match?: MatchType;
6698
+ /** Explicit constraint name */
6699
+ $name?: string;
6698
6700
  /** DEFERRABLE flag */
6699
6701
  $deferrable?: boolean;
6700
6702
  /** INITIALLY DEFERRED flag */
6701
6703
  $initiallyDeferred?: boolean;
6702
6704
  /** Tracking ID for rename detection */
6703
6705
  $trackingId?: string;
6706
+ /** Comment for documentation */
6707
+ $comment?: string;
6704
6708
  }
6705
6709
  /** Relation definition type */
6706
6710
  export type RelationDef = ForeignKeyRelationDef;
@@ -6695,12 +6695,16 @@ export interface ForeignKeyRelationDef {
6695
6695
  $onUpdate?: ReferentialAction;
6696
6696
  /** MATCH type */
6697
6697
  $match?: MatchType;
6698
+ /** Explicit constraint name */
6699
+ $name?: string;
6698
6700
  /** DEFERRABLE flag */
6699
6701
  $deferrable?: boolean;
6700
6702
  /** INITIALLY DEFERRED flag */
6701
6703
  $initiallyDeferred?: boolean;
6702
6704
  /** Tracking ID for rename detection */
6703
6705
  $trackingId?: string;
6706
+ /** Comment for documentation */
6707
+ $comment?: string;
6704
6708
  }
6705
6709
  /** Relation definition type */
6706
6710
  export type RelationDef = ForeignKeyRelationDef;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "relq",
3
- "version": "1.0.92",
3
+ "version": "1.0.94",
4
4
  "description": "The Fully-Typed PostgreSQL ORM for TypeScript",
5
5
  "author": "Olajide Mathew O. <olajide.mathew@yuniq.solutions>",
6
6
  "license": "MIT",