@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.mjs CHANGED
@@ -2345,14 +2345,13 @@ var DatabaseController = class _DatabaseController {
2345
2345
  "Generates auto-tasks for database schema"
2346
2346
  ),
2347
2347
  CadenzaService.createMetaTask("Generate DDL from table", (ctx) => {
2348
- var _a2;
2349
2348
  const { ddl, table, tableName, schema, options } = ctx;
2350
2349
  const fieldDefs = Object.entries(table.fields).map((value) => {
2351
- var _a3, _b2, _c2, _d2, _e, _f, _g;
2350
+ var _a2, _b2, _c2, _d2, _e, _f, _g;
2352
2351
  const [fieldName, field] = value;
2353
2352
  let def = `${fieldName} ${field.type.toUpperCase()}`;
2354
2353
  if (field.type === "varchar")
2355
- def += `(${(_b2 = (_a3 = field.constraints) == null ? void 0 : _a3.maxLength) != null ? _b2 : 255})`;
2354
+ def += `(${(_b2 = (_a2 = field.constraints) == null ? void 0 : _a2.maxLength) != null ? _b2 : 255})`;
2356
2355
  if (field.type === "decimal")
2357
2356
  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})`;
2358
2357
  if (field.primary) def += " PRIMARY KEY";
@@ -2372,10 +2371,6 @@ var DatabaseController = class _DatabaseController {
2372
2371
  return def;
2373
2372
  }).join(", ");
2374
2373
  let sql = `CREATE TABLE IF NOT EXISTS ${tableName} (${fieldDefs})`;
2375
- if ((_a2 = table.meta) == null ? void 0 : _a2.appendOnly) {
2376
- sql += `;
2377
- CREATE TRIGGER prevent_modification BEFORE UPDATE OR DELETE ON ${tableName} FOR EACH STATEMENT EXECUTE FUNCTION prevent_context_modification();`;
2378
- }
2379
2374
  ddl.push(sql);
2380
2375
  return { ddl, table, tableName, schema, options };
2381
2376
  }).then(
@@ -2384,7 +2379,7 @@ CREATE TRIGGER prevent_modification BEFORE UPDATE OR DELETE ON ${tableName} FOR
2384
2379
  if (table.indexes) {
2385
2380
  table.indexes.forEach((fields) => {
2386
2381
  ddl.push(
2387
- `CREATE INDEX idx_${tableName}_${fields.join("_")} ON ${tableName} (${fields.join(", ")});`
2382
+ `CREATE INDEX IF NOT EXISTS idx_${tableName}_${fields.join("_")} ON ${tableName} (${fields.join(", ")});`
2388
2383
  );
2389
2384
  });
2390
2385
  }
@@ -2398,6 +2393,7 @@ CREATE TRIGGER prevent_modification BEFORE UPDATE OR DELETE ON ${tableName} FOR
2398
2393
  table.uniqueConstraints.forEach(
2399
2394
  (fields) => {
2400
2395
  ddl.push(
2396
+ `ALTER TABLE ${tableName} DROP CONSTRAINT IF EXISTS unique_${tableName}_${fields.join("_")};`,
2401
2397
  `ALTER TABLE ${tableName} ADD CONSTRAINT unique_${tableName}_${fields.join("_")} UNIQUE (${fields.join(", ")});`
2402
2398
  );
2403
2399
  }