@cadenza.io/service 2.17.26 → 2.17.27
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.js +22 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6575,6 +6575,11 @@ function resolveDataRows(data) {
|
|
|
6575
6575
|
}
|
|
6576
6576
|
return [ensurePlainObject(data, "data")];
|
|
6577
6577
|
}
|
|
6578
|
+
function buildAddConstraintIfMissingStatement(tableName, constraintName, constraintDefinition) {
|
|
6579
|
+
const escapedConstraintName = constraintName.replace(/'/g, "''");
|
|
6580
|
+
const escapedTableName = tableName.replace(/'/g, "''");
|
|
6581
|
+
return `DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = '${escapedConstraintName}' AND conrelid = '${escapedTableName}'::regclass) THEN ALTER TABLE ${tableName} ADD CONSTRAINT ${constraintName} ${constraintDefinition}; END IF; END $$;`;
|
|
6582
|
+
}
|
|
6578
6583
|
var DatabaseController = class _DatabaseController {
|
|
6579
6584
|
constructor() {
|
|
6580
6585
|
this.registrationsByActorName = /* @__PURE__ */ new Map();
|
|
@@ -7460,22 +7465,33 @@ var DatabaseController = class _DatabaseController {
|
|
|
7460
7465
|
);
|
|
7461
7466
|
}
|
|
7462
7467
|
if (table.primaryKey) {
|
|
7468
|
+
const primaryKeyName = `pk_${tableName}_${table.primaryKey.join("_")}`;
|
|
7463
7469
|
ddl.push(
|
|
7464
|
-
|
|
7465
|
-
|
|
7470
|
+
buildAddConstraintIfMissingStatement(
|
|
7471
|
+
tableName,
|
|
7472
|
+
primaryKeyName,
|
|
7473
|
+
`PRIMARY KEY (${table.primaryKey.map(import_lodash_es.snakeCase).join(", ")})`
|
|
7474
|
+
)
|
|
7466
7475
|
);
|
|
7467
7476
|
}
|
|
7468
7477
|
for (const uniqueFields of table.uniqueConstraints ?? []) {
|
|
7478
|
+
const uniqueConstraintName = `uq_${tableName}_${uniqueFields.join("_")}`;
|
|
7469
7479
|
ddl.push(
|
|
7470
|
-
|
|
7471
|
-
|
|
7480
|
+
buildAddConstraintIfMissingStatement(
|
|
7481
|
+
tableName,
|
|
7482
|
+
uniqueConstraintName,
|
|
7483
|
+
`UNIQUE (${uniqueFields.map(import_lodash_es.snakeCase).join(", ")})`
|
|
7484
|
+
)
|
|
7472
7485
|
);
|
|
7473
7486
|
}
|
|
7474
7487
|
for (const foreignKey of table.foreignKeys ?? []) {
|
|
7475
7488
|
const fkName = `fk_${tableName}_${foreignKey.fields.join("_")}`;
|
|
7476
7489
|
ddl.push(
|
|
7477
|
-
|
|
7478
|
-
|
|
7490
|
+
buildAddConstraintIfMissingStatement(
|
|
7491
|
+
tableName,
|
|
7492
|
+
fkName,
|
|
7493
|
+
`FOREIGN KEY (${foreignKey.fields.map(import_lodash_es.snakeCase).join(", ")}) REFERENCES ${foreignKey.tableName} (${foreignKey.referenceFields.map(import_lodash_es.snakeCase).join(", ")})`
|
|
7494
|
+
)
|
|
7479
7495
|
);
|
|
7480
7496
|
}
|
|
7481
7497
|
for (const [triggerName, trigger] of Object.entries(table.triggers ?? {})) {
|