@cadenza.io/service 1.6.11 → 1.6.13

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 CHANGED
@@ -2392,14 +2392,13 @@ var DatabaseController = class _DatabaseController {
2392
2392
  "Generates auto-tasks for database schema"
2393
2393
  ),
2394
2394
  CadenzaService.createMetaTask("Generate DDL from table", (ctx) => {
2395
- var _a2;
2396
2395
  const { ddl, table, tableName, schema, options } = ctx;
2397
2396
  const fieldDefs = Object.entries(table.fields).map((value) => {
2398
- var _a3, _b2, _c2, _d2, _e, _f, _g;
2397
+ var _a2, _b2, _c2, _d2, _e, _f, _g;
2399
2398
  const [fieldName, field] = value;
2400
2399
  let def = `${fieldName} ${field.type.toUpperCase()}`;
2401
2400
  if (field.type === "varchar")
2402
- def += `(${(_b2 = (_a3 = field.constraints) == null ? void 0 : _a3.maxLength) != null ? _b2 : 255})`;
2401
+ def += `(${(_b2 = (_a2 = field.constraints) == null ? void 0 : _a2.maxLength) != null ? _b2 : 255})`;
2403
2402
  if (field.type === "decimal")
2404
2403
  def += `(${(_d2 = (_c2 = field.constraints) == null ? void 0 : _c2.precision) != null ? _d2 : 10},${(_f = (_e = field.constraints) == null ? void 0 : _e.scale) != null ? _f : 2})`;
2405
2404
  if (field.primary) def += " PRIMARY KEY";
@@ -2419,10 +2418,6 @@ var DatabaseController = class _DatabaseController {
2419
2418
  return def;
2420
2419
  }).join(", ");
2421
2420
  let sql = `CREATE TABLE IF NOT EXISTS ${tableName} (${fieldDefs})`;
2422
- if ((_a2 = table.meta) == null ? void 0 : _a2.appendOnly) {
2423
- sql += `;
2424
- CREATE TRIGGER prevent_modification BEFORE UPDATE OR DELETE ON ${tableName} FOR EACH STATEMENT EXECUTE FUNCTION prevent_context_modification();`;
2425
- }
2426
2421
  ddl.push(sql);
2427
2422
  return { ddl, table, tableName, schema, options };
2428
2423
  }).then(
@@ -2431,7 +2426,7 @@ CREATE TRIGGER prevent_modification BEFORE UPDATE OR DELETE ON ${tableName} FOR
2431
2426
  if (table.indexes) {
2432
2427
  table.indexes.forEach((fields) => {
2433
2428
  ddl.push(
2434
- `CREATE INDEX idx_${tableName}_${fields.join("_")} ON ${tableName} (${fields.join(", ")});`
2429
+ `CREATE INDEX IF NOT EXISTS idx_${tableName}_${fields.join("_")} ON ${tableName} (${fields.join(", ")});`
2435
2430
  );
2436
2431
  });
2437
2432
  }
@@ -2445,6 +2440,7 @@ CREATE TRIGGER prevent_modification BEFORE UPDATE OR DELETE ON ${tableName} FOR
2445
2440
  table.uniqueConstraints.forEach(
2446
2441
  (fields) => {
2447
2442
  ddl.push(
2443
+ `ALTER TABLE ${tableName} DROP CONSTRAINT IF EXISTS unique_${tableName}_${fields.join("_")};`,
2448
2444
  `ALTER TABLE ${tableName} ADD CONSTRAINT unique_${tableName}_${fields.join("_")} UNIQUE (${fields.join(", ")});`
2449
2445
  );
2450
2446
  }