@cadenza.io/service 1.17.0 → 1.17.1

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
@@ -2295,54 +2295,58 @@ var DatabaseController = class _DatabaseController {
2295
2295
  this.splitTables.bind(this),
2296
2296
  "Generates DDL for database schema"
2297
2297
  ).then(
2298
- CadenzaService.createMetaTask("Generate DDL from table", (ctx) => {
2299
- const {
2300
- ddl,
2301
- table,
2302
- tableName,
2303
- schema,
2304
- options,
2305
- sortedTables
2306
- } = ctx;
2307
- const fieldDefs = Object.entries(table.fields).map((value) => {
2308
- const [fieldName, field] = value;
2309
- let def = `${fieldName} ${field.type.toUpperCase()}`;
2310
- if (field.type === "varchar")
2311
- def += `(${field.constraints?.maxLength ?? 255})`;
2312
- if (field.type === "decimal")
2313
- def += `(${field.constraints?.precision ?? 10},${field.constraints?.scale ?? 2})`;
2314
- if (field.primary) def += " PRIMARY KEY";
2315
- if (field.unique) def += " UNIQUE";
2316
- if (field.default !== void 0)
2317
- def += ` DEFAULT ${field.default === "" ? "''" : String(field.default)}`;
2318
- if (field.required && !field.nullable) def += " NOT NULL";
2319
- if (field.nullable) def += " NULL";
2320
- if (field.generated)
2321
- def += ` GENERATED ALWAYS AS ${field.generated.toUpperCase()} STORED`;
2322
- if (field.references)
2323
- def += ` REFERENCES ${field.references} ON DELETE ${field.onDelete || "DO NOTHING"}`;
2324
- if (field.encrypted) def += " ENCRYPTED";
2325
- if (field.constraints?.check) {
2326
- def += ` CHECK (${field.constraints.check})`;
2298
+ CadenzaService.createMetaTask(
2299
+ "Generate DDL from table",
2300
+ async (ctx) => {
2301
+ const {
2302
+ ddl,
2303
+ table,
2304
+ tableName,
2305
+ schema,
2306
+ options,
2307
+ sortedTables
2308
+ } = ctx;
2309
+ const fieldDefs = Object.entries(table.fields).map((value) => {
2310
+ const [fieldName, field] = value;
2311
+ let def = `${fieldName} ${field.type.toUpperCase()}`;
2312
+ if (field.type === "varchar")
2313
+ def += `(${field.constraints?.maxLength ?? 255})`;
2314
+ if (field.type === "decimal")
2315
+ def += `(${field.constraints?.precision ?? 10},${field.constraints?.scale ?? 2})`;
2316
+ if (field.primary) def += " PRIMARY KEY";
2317
+ if (field.unique) def += " UNIQUE";
2318
+ if (field.default !== void 0)
2319
+ def += ` DEFAULT ${field.default === "" ? "''" : String(field.default)}`;
2320
+ if (field.required && !field.nullable)
2321
+ def += " NOT NULL";
2322
+ if (field.nullable) def += " NULL";
2323
+ if (field.generated)
2324
+ def += ` GENERATED ALWAYS AS ${field.generated.toUpperCase()} STORED`;
2325
+ if (field.references)
2326
+ def += ` REFERENCES ${field.references} ON DELETE ${field.onDelete || "DO NOTHING"}`;
2327
+ if (field.encrypted) def += " ENCRYPTED";
2328
+ if (field.constraints?.check) {
2329
+ def += ` CHECK (${field.constraints.check})`;
2330
+ }
2331
+ return def;
2332
+ }).join(", ");
2333
+ if (schema.meta?.dropExisting) {
2334
+ await this.dbClient.query(
2335
+ `DROP TABLE IF EXISTS ${tableName} CASCADE;`
2336
+ );
2327
2337
  }
2328
- return def;
2329
- }).join(", ");
2330
- if (schema.meta?.dropExisting) {
2331
- this.dbClient.query(
2332
- `DROP TABLE IF EXISTS ${tableName} CASCADE;`
2333
- );
2338
+ const sql = `CREATE TABLE IF NOT EXISTS ${tableName} (${fieldDefs})`;
2339
+ ddl.push(sql);
2340
+ return {
2341
+ ddl,
2342
+ table,
2343
+ tableName,
2344
+ schema,
2345
+ options,
2346
+ sortedTables
2347
+ };
2334
2348
  }
2335
- const sql = `CREATE TABLE IF NOT EXISTS ${tableName} (${fieldDefs})`;
2336
- ddl.push(sql);
2337
- return {
2338
- ddl,
2339
- table,
2340
- tableName,
2341
- schema,
2342
- options,
2343
- sortedTables
2344
- };
2345
- }).then(
2349
+ ).then(
2346
2350
  CadenzaService.createMetaTask("Generate index DDL", (ctx) => {
2347
2351
  const {
2348
2352
  ddl,