@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 +50 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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(
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
def
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
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
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
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
|
-
|
|
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,
|