@cadenza.io/service 1.7.0 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -268,11 +268,10 @@ interface TableDefinition {
268
268
  primaryKey?: string[];
269
269
  fullTextIndexes?: string[][];
270
270
  foreignKeys?: {
271
- [tableName: string]: {
272
- fields: string[];
273
- referenceFields: string[];
274
- };
275
- };
271
+ tableName: string;
272
+ fields: string[];
273
+ referenceFields: string[];
274
+ }[];
276
275
  triggers?: Record<string, {
277
276
  when: "before" | "after";
278
277
  event: "insert" | "update" | "delete";
package/dist/index.d.ts CHANGED
@@ -268,11 +268,10 @@ interface TableDefinition {
268
268
  primaryKey?: string[];
269
269
  fullTextIndexes?: string[][];
270
270
  foreignKeys?: {
271
- [tableName: string]: {
272
- fields: string[];
273
- referenceFields: string[];
274
- };
275
- };
271
+ tableName: string;
272
+ fields: string[];
273
+ referenceFields: string[];
274
+ }[];
276
275
  triggers?: Record<string, {
277
276
  when: "before" | "after";
278
277
  event: "insert" | "update" | "delete";
package/dist/index.js CHANGED
@@ -2454,16 +2454,13 @@ var DatabaseController = class _DatabaseController {
2454
2454
  (ctx) => {
2455
2455
  const { ddl, table, tableName, schema, options } = ctx;
2456
2456
  if (table.foreignKeys) {
2457
- for (const [
2458
- foreignTableName,
2459
- foreignKey
2460
- ] of Object.entries(table.foreignKeys)) {
2457
+ for (const foreignKey of table.foreignKeys) {
2461
2458
  const foreignKeyName = `fk_${tableName}_${foreignKey.fields.join("_")}`;
2462
2459
  ddl.push(
2463
2460
  `ALTER TABLE ${tableName} DROP CONSTRAINT IF EXISTS ${foreignKeyName};`,
2464
2461
  `ALTER TABLE ${tableName} ADD CONSTRAINT ${foreignKeyName} FOREIGN KEY (${foreignKey.fields.join(
2465
2462
  ", "
2466
- )}) REFERENCES ${foreignTableName} (${foreignKey.referenceFields.join(
2463
+ )}) REFERENCES ${foreignKey.tableName} (${foreignKey.referenceFields.join(
2467
2464
  ", "
2468
2465
  )});`
2469
2466
  );
@@ -2607,7 +2604,7 @@ var DatabaseController = class _DatabaseController {
2607
2604
  });
2608
2605
  }
2609
2606
  sortTablesByReferences(ctx) {
2610
- var _a2;
2607
+ var _a2, _b2;
2611
2608
  const schema = ctx.schema;
2612
2609
  const graph = /* @__PURE__ */ new Map();
2613
2610
  const allTables = Object.keys(schema.tables);
@@ -2621,6 +2618,14 @@ var DatabaseController = class _DatabaseController {
2621
2618
  }
2622
2619
  }
2623
2620
  }
2621
+ if (table.foreignKeys) {
2622
+ for (const foreignKey of table.foreignKeys) {
2623
+ const refTable = foreignKey.tableName;
2624
+ if (refTable !== tableName && allTables.includes(refTable)) {
2625
+ (_b2 = graph.get(refTable)) == null ? void 0 : _b2.add(tableName);
2626
+ }
2627
+ }
2628
+ }
2624
2629
  }
2625
2630
  const visited = /* @__PURE__ */ new Set();
2626
2631
  const tempMark = /* @__PURE__ */ new Set();