@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.mjs
CHANGED
|
@@ -6524,6 +6524,11 @@ function resolveDataRows(data) {
|
|
|
6524
6524
|
}
|
|
6525
6525
|
return [ensurePlainObject(data, "data")];
|
|
6526
6526
|
}
|
|
6527
|
+
function buildAddConstraintIfMissingStatement(tableName, constraintName, constraintDefinition) {
|
|
6528
|
+
const escapedConstraintName = constraintName.replace(/'/g, "''");
|
|
6529
|
+
const escapedTableName = tableName.replace(/'/g, "''");
|
|
6530
|
+
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 $$;`;
|
|
6531
|
+
}
|
|
6527
6532
|
var DatabaseController = class _DatabaseController {
|
|
6528
6533
|
constructor() {
|
|
6529
6534
|
this.registrationsByActorName = /* @__PURE__ */ new Map();
|
|
@@ -7409,22 +7414,33 @@ var DatabaseController = class _DatabaseController {
|
|
|
7409
7414
|
);
|
|
7410
7415
|
}
|
|
7411
7416
|
if (table.primaryKey) {
|
|
7417
|
+
const primaryKeyName = `pk_${tableName}_${table.primaryKey.join("_")}`;
|
|
7412
7418
|
ddl.push(
|
|
7413
|
-
|
|
7414
|
-
|
|
7419
|
+
buildAddConstraintIfMissingStatement(
|
|
7420
|
+
tableName,
|
|
7421
|
+
primaryKeyName,
|
|
7422
|
+
`PRIMARY KEY (${table.primaryKey.map(snakeCase).join(", ")})`
|
|
7423
|
+
)
|
|
7415
7424
|
);
|
|
7416
7425
|
}
|
|
7417
7426
|
for (const uniqueFields of table.uniqueConstraints ?? []) {
|
|
7427
|
+
const uniqueConstraintName = `uq_${tableName}_${uniqueFields.join("_")}`;
|
|
7418
7428
|
ddl.push(
|
|
7419
|
-
|
|
7420
|
-
|
|
7429
|
+
buildAddConstraintIfMissingStatement(
|
|
7430
|
+
tableName,
|
|
7431
|
+
uniqueConstraintName,
|
|
7432
|
+
`UNIQUE (${uniqueFields.map(snakeCase).join(", ")})`
|
|
7433
|
+
)
|
|
7421
7434
|
);
|
|
7422
7435
|
}
|
|
7423
7436
|
for (const foreignKey of table.foreignKeys ?? []) {
|
|
7424
7437
|
const fkName = `fk_${tableName}_${foreignKey.fields.join("_")}`;
|
|
7425
7438
|
ddl.push(
|
|
7426
|
-
|
|
7427
|
-
|
|
7439
|
+
buildAddConstraintIfMissingStatement(
|
|
7440
|
+
tableName,
|
|
7441
|
+
fkName,
|
|
7442
|
+
`FOREIGN KEY (${foreignKey.fields.map(snakeCase).join(", ")}) REFERENCES ${foreignKey.tableName} (${foreignKey.referenceFields.map(snakeCase).join(", ")})`
|
|
7443
|
+
)
|
|
7428
7444
|
);
|
|
7429
7445
|
}
|
|
7430
7446
|
for (const [triggerName, trigger] of Object.entries(table.triggers ?? {})) {
|