@ruiapp/rapid-core 0.8.7 → 0.8.8
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 +290 -266
- package/dist/plugins/metaManage/MetaManagePlugin.d.ts +6 -0
- package/dist/plugins/metaManage/services/MetaService.d.ts +7 -0
- package/package.json +1 -1
- package/src/plugins/metaManage/MetaManagePlugin.ts +28 -360
- package/src/plugins/metaManage/services/MetaService.ts +367 -0
|
@@ -3,14 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
IQueryBuilder,
|
|
7
6
|
QuoteTableOptions,
|
|
8
7
|
RpdApplicationConfig,
|
|
9
8
|
RpdDataDictionary,
|
|
10
9
|
RpdDataModel,
|
|
11
|
-
RpdDataModelIndex,
|
|
12
10
|
RpdDataModelProperty,
|
|
13
|
-
RpdDataPropertyTypes,
|
|
14
11
|
RpdEntityCreateEventPayload,
|
|
15
12
|
RpdEntityDeleteEventPayload,
|
|
16
13
|
RpdEntityUpdateEventPayload,
|
|
@@ -26,14 +23,29 @@ import {
|
|
|
26
23
|
import * as listMetaModels from "./actionHandlers/listMetaModels";
|
|
27
24
|
import * as listMetaRoutes from "./actionHandlers/listMetaRoutes";
|
|
28
25
|
import * as getMetaModelDetail from "./actionHandlers/getMetaModelDetail";
|
|
29
|
-
import {
|
|
30
|
-
import { getEntityPropertiesIncludingBase, getEntityPropertyByCode, isOneRelationProperty, isRelationProperty } from "~/helpers/metaHelper";
|
|
31
|
-
import { DataAccessPgColumnTypes } from "~/dataAccess/dataAccessTypes";
|
|
32
|
-
import { pgPropertyTypeColumnMap } from "~/dataAccess/columnTypeMapper";
|
|
33
|
-
import { convertModelIndexConditionsToRowFilterOptions } from "~/helpers/filterHelper";
|
|
26
|
+
import { getEntityPropertiesIncludingBase, isRelationProperty } from "~/helpers/metaHelper";
|
|
34
27
|
import { RouteContext } from "~/core/routeContext";
|
|
28
|
+
import MetaService from "./services/MetaService";
|
|
29
|
+
|
|
30
|
+
export type MetaManagerInitOptions = {
|
|
31
|
+
syncDatabaseSchemaOnLoaded?: boolean;
|
|
32
|
+
};
|
|
35
33
|
|
|
36
34
|
class MetaManager implements RapidPlugin {
|
|
35
|
+
#metaService: MetaService;
|
|
36
|
+
|
|
37
|
+
#syncDatabaseSchemaOnLoaded?: boolean;
|
|
38
|
+
|
|
39
|
+
constructor(options?: MetaManagerInitOptions) {
|
|
40
|
+
if (!options) {
|
|
41
|
+
options = {
|
|
42
|
+
syncDatabaseSchemaOnLoaded: true,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.#syncDatabaseSchemaOnLoaded = options.syncDatabaseSchemaOnLoaded;
|
|
47
|
+
}
|
|
48
|
+
|
|
37
49
|
get code(): string {
|
|
38
50
|
return "metaManager";
|
|
39
51
|
}
|
|
@@ -78,8 +90,15 @@ class MetaManager implements RapidPlugin {
|
|
|
78
90
|
}
|
|
79
91
|
}
|
|
80
92
|
|
|
93
|
+
async configureServices(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
94
|
+
this.#metaService = new MetaService(server);
|
|
95
|
+
server.registerService("metaService", this.#metaService);
|
|
96
|
+
}
|
|
97
|
+
|
|
81
98
|
async onApplicationLoaded(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
82
|
-
|
|
99
|
+
if (this.#syncDatabaseSchemaOnLoaded) {
|
|
100
|
+
await this.#metaService.syncDatabaseSchema(applicationConfig);
|
|
101
|
+
}
|
|
83
102
|
}
|
|
84
103
|
}
|
|
85
104
|
|
|
@@ -177,354 +196,3 @@ function listDataDictionaries(server: IRpdServer) {
|
|
|
177
196
|
properties: properties.map((item) => item.code),
|
|
178
197
|
});
|
|
179
198
|
}
|
|
180
|
-
|
|
181
|
-
type TableInformation = {
|
|
182
|
-
table_schema: string;
|
|
183
|
-
table_name: string;
|
|
184
|
-
table_description: string;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
type ColumnInformation = {
|
|
188
|
-
table_schema: string;
|
|
189
|
-
table_name: string;
|
|
190
|
-
column_name: string;
|
|
191
|
-
ordinal_position: number;
|
|
192
|
-
description?: string;
|
|
193
|
-
data_type: string;
|
|
194
|
-
udt_name: string;
|
|
195
|
-
is_nullable: "YES" | "NO";
|
|
196
|
-
column_default: string;
|
|
197
|
-
character_maximum_length: number;
|
|
198
|
-
numeric_precision: number;
|
|
199
|
-
numeric_scale: number;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
type ConstraintInformation = {
|
|
203
|
-
table_schema: string;
|
|
204
|
-
table_name: string;
|
|
205
|
-
constraint_type: string;
|
|
206
|
-
constraint_name: string;
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
async function syncDatabaseSchema(server: IRpdServer, applicationConfig: RpdApplicationConfig) {
|
|
210
|
-
const logger = server.getLogger();
|
|
211
|
-
logger.info("Synchronizing database schema...");
|
|
212
|
-
const sqlQueryTableInformations = `SELECT table_schema, table_name, obj_description((table_schema||'.'||quote_ident(table_name))::regclass) as table_description FROM information_schema.tables`;
|
|
213
|
-
const tablesInDb: TableInformation[] = await server.queryDatabaseObject(sqlQueryTableInformations);
|
|
214
|
-
const { queryBuilder } = server;
|
|
215
|
-
|
|
216
|
-
for (const model of applicationConfig.models) {
|
|
217
|
-
logger.debug(`Checking data table for '${model.namespace}.${model.singularCode}'...`);
|
|
218
|
-
|
|
219
|
-
const expectedTableSchema = model.schema || server.databaseConfig.dbDefaultSchema;
|
|
220
|
-
const expectedTableName = model.tableName;
|
|
221
|
-
const tableInDb = find(tablesInDb, { table_schema: expectedTableSchema, table_name: expectedTableName });
|
|
222
|
-
if (!tableInDb) {
|
|
223
|
-
await server.queryDatabaseObject(`CREATE TABLE IF NOT EXISTS ${queryBuilder.quoteTable(model)} ()`, []);
|
|
224
|
-
}
|
|
225
|
-
if (!tableInDb || tableInDb.table_description != model.name) {
|
|
226
|
-
await server.tryQueryDatabaseObject(`COMMENT ON TABLE ${queryBuilder.quoteTable(model)} IS ${queryBuilder.formatValueToSqlLiteral(model.name)};`, []);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const sqlQueryColumnInformations = `SELECT c.table_schema, c.table_name, c.column_name, c.ordinal_position, d.description, c.data_type, c.udt_name, c.is_nullable, c.column_default, c.character_maximum_length, c.numeric_precision, c.numeric_scale
|
|
231
|
-
FROM information_schema.columns c
|
|
232
|
-
INNER JOIN pg_catalog.pg_statio_all_tables st ON (st.schemaname = c.table_schema and st.relname = c.table_name)
|
|
233
|
-
LEFT JOIN pg_catalog.pg_description d ON (d.objoid = st.relid and d.objsubid = c.ordinal_position);`;
|
|
234
|
-
const columnsInDb: ColumnInformation[] = await server.queryDatabaseObject(sqlQueryColumnInformations, []);
|
|
235
|
-
|
|
236
|
-
for (const model of applicationConfig.models) {
|
|
237
|
-
logger.debug(`Checking data columns for '${model.namespace}.${model.singularCode}'...`);
|
|
238
|
-
|
|
239
|
-
for (const property of model.properties) {
|
|
240
|
-
let columnDDL = "";
|
|
241
|
-
if (isRelationProperty(property)) {
|
|
242
|
-
if (property.relation === "one") {
|
|
243
|
-
const targetModel = applicationConfig.models.find((item) => item.singularCode === property.targetSingularCode);
|
|
244
|
-
if (!targetModel) {
|
|
245
|
-
logger.warn(`Cannot find target model with singular code "${property.targetSingularCode}".`);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const columnInDb: ColumnInformation | undefined = find(columnsInDb, {
|
|
249
|
-
table_schema: model.schema || "public",
|
|
250
|
-
table_name: model.tableName,
|
|
251
|
-
column_name: property.targetIdColumnName!,
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
if (!columnInDb) {
|
|
255
|
-
columnDDL = generateCreateColumnDDL(queryBuilder, {
|
|
256
|
-
schema: model.schema,
|
|
257
|
-
tableName: model.tableName,
|
|
258
|
-
name: property.targetIdColumnName!,
|
|
259
|
-
type: "integer",
|
|
260
|
-
autoIncrement: false,
|
|
261
|
-
notNull: property.required,
|
|
262
|
-
});
|
|
263
|
-
await server.tryQueryDatabaseObject(columnDDL);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (!columnInDb || columnInDb.description != property.name) {
|
|
267
|
-
await server.tryQueryDatabaseObject(
|
|
268
|
-
`COMMENT ON COLUMN ${queryBuilder.quoteTable(model)}.${queryBuilder.quoteObject(
|
|
269
|
-
property.targetIdColumnName,
|
|
270
|
-
)} IS ${queryBuilder.formatValueToSqlLiteral(property.name)};`,
|
|
271
|
-
[],
|
|
272
|
-
);
|
|
273
|
-
}
|
|
274
|
-
} else if (property.relation === "many") {
|
|
275
|
-
if (property.linkTableName) {
|
|
276
|
-
const tableInDb = find(tablesInDb, {
|
|
277
|
-
table_schema: property.linkSchema || server.databaseConfig.dbDefaultSchema,
|
|
278
|
-
table_name: property.linkTableName,
|
|
279
|
-
});
|
|
280
|
-
if (!tableInDb) {
|
|
281
|
-
columnDDL = generateLinkTableDDL(queryBuilder, {
|
|
282
|
-
linkSchema: property.linkSchema,
|
|
283
|
-
linkTableName: property.linkTableName,
|
|
284
|
-
targetIdColumnName: property.targetIdColumnName!,
|
|
285
|
-
selfIdColumnName: property.selfIdColumnName!,
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const contraintName = `${property.linkTableName}_pk`;
|
|
290
|
-
columnDDL += `ALTER TABLE ${queryBuilder.quoteTable({
|
|
291
|
-
schema: property.linkSchema,
|
|
292
|
-
tableName: property.linkTableName,
|
|
293
|
-
})} ADD CONSTRAINT ${queryBuilder.quoteObject(contraintName)} PRIMARY KEY (id);`;
|
|
294
|
-
await server.tryQueryDatabaseObject(columnDDL);
|
|
295
|
-
} else {
|
|
296
|
-
const targetModel = applicationConfig.models.find((item) => item.singularCode === property.targetSingularCode);
|
|
297
|
-
if (!targetModel) {
|
|
298
|
-
logger.warn(`Cannot find target model with singular code "${property.targetSingularCode}".`);
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const columnInDb: ColumnInformation | undefined = find(columnsInDb, {
|
|
303
|
-
table_schema: targetModel.schema || "public",
|
|
304
|
-
table_name: targetModel.tableName,
|
|
305
|
-
column_name: property.selfIdColumnName!,
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
if (!columnInDb) {
|
|
309
|
-
columnDDL = generateCreateColumnDDL(queryBuilder, {
|
|
310
|
-
schema: targetModel.schema,
|
|
311
|
-
tableName: targetModel.tableName,
|
|
312
|
-
name: property.selfIdColumnName || "",
|
|
313
|
-
type: "integer",
|
|
314
|
-
autoIncrement: false,
|
|
315
|
-
notNull: property.required,
|
|
316
|
-
});
|
|
317
|
-
await server.tryQueryDatabaseObject(columnDDL);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
} else {
|
|
321
|
-
continue;
|
|
322
|
-
}
|
|
323
|
-
} else {
|
|
324
|
-
const columnName = property.columnName || property.code;
|
|
325
|
-
const columnInDb: ColumnInformation | undefined = find(columnsInDb, {
|
|
326
|
-
table_schema: model.schema || "public",
|
|
327
|
-
table_name: model.tableName,
|
|
328
|
-
column_name: columnName,
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
if (!columnInDb) {
|
|
332
|
-
// create column if not exists
|
|
333
|
-
columnDDL = generateCreateColumnDDL(queryBuilder, {
|
|
334
|
-
schema: model.schema,
|
|
335
|
-
tableName: model.tableName,
|
|
336
|
-
name: columnName,
|
|
337
|
-
type: property.type,
|
|
338
|
-
autoIncrement: property.autoIncrement,
|
|
339
|
-
notNull: property.required,
|
|
340
|
-
defaultValue: property.defaultValue,
|
|
341
|
-
});
|
|
342
|
-
await server.tryQueryDatabaseObject(columnDDL);
|
|
343
|
-
} else {
|
|
344
|
-
const expectedColumnType = pgPropertyTypeColumnMap[property.type];
|
|
345
|
-
if (columnInDb.udt_name !== expectedColumnType) {
|
|
346
|
-
const sqlAlterColumnType = `alter table ${queryBuilder.quoteTable(model)} alter column ${queryBuilder.quoteObject(
|
|
347
|
-
columnName,
|
|
348
|
-
)} type ${expectedColumnType}`;
|
|
349
|
-
await server.tryQueryDatabaseObject(sqlAlterColumnType);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
if (property.defaultValue) {
|
|
353
|
-
if (!columnInDb.column_default) {
|
|
354
|
-
const sqlSetColumnDefault = `alter table ${queryBuilder.quoteTable(model)} alter column ${queryBuilder.quoteObject(columnName)} set default ${
|
|
355
|
-
property.defaultValue
|
|
356
|
-
}`;
|
|
357
|
-
await server.tryQueryDatabaseObject(sqlSetColumnDefault);
|
|
358
|
-
}
|
|
359
|
-
} else {
|
|
360
|
-
if (columnInDb.column_default && !property.autoIncrement) {
|
|
361
|
-
const sqlDropColumnDefault = `alter table ${queryBuilder.quoteTable(model)} alter column ${queryBuilder.quoteObject(columnName)} drop default`;
|
|
362
|
-
await server.tryQueryDatabaseObject(sqlDropColumnDefault);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
if (property.required) {
|
|
367
|
-
if (columnInDb.is_nullable === "YES") {
|
|
368
|
-
const sqlSetColumnNotNull = `alter table ${queryBuilder.quoteTable(model)} alter column ${queryBuilder.quoteObject(columnName)} set not null`;
|
|
369
|
-
await server.tryQueryDatabaseObject(sqlSetColumnNotNull);
|
|
370
|
-
}
|
|
371
|
-
} else {
|
|
372
|
-
if (columnInDb.is_nullable === "NO") {
|
|
373
|
-
const sqlDropColumnNotNull = `alter table ${queryBuilder.quoteTable(model)} alter column ${queryBuilder.quoteObject(columnName)} drop not null`;
|
|
374
|
-
await server.tryQueryDatabaseObject(sqlDropColumnNotNull);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (!columnInDb || columnInDb.description != property.name) {
|
|
380
|
-
await server.tryQueryDatabaseObject(
|
|
381
|
-
`COMMENT ON COLUMN ${queryBuilder.quoteTable(model)}.${queryBuilder.quoteObject(
|
|
382
|
-
property.columnName || property.code,
|
|
383
|
-
)} IS ${queryBuilder.formatValueToSqlLiteral(property.name)};`,
|
|
384
|
-
[],
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
const sqlQueryConstraints = `SELECT table_schema, table_name, constraint_type, constraint_name FROM information_schema.table_constraints WHERE constraint_type = 'PRIMARY KEY';`;
|
|
392
|
-
const constraintsInDb: ConstraintInformation[] = await server.queryDatabaseObject(sqlQueryConstraints);
|
|
393
|
-
for (const model of applicationConfig.models) {
|
|
394
|
-
const expectedTableSchema = model.schema || server.databaseConfig.dbDefaultSchema;
|
|
395
|
-
const expectedTableName = model.tableName;
|
|
396
|
-
const expectedContraintName = `${expectedTableName}_pk`;
|
|
397
|
-
logger.debug(`Checking pk for '${expectedTableSchema}.${expectedTableName}'...`);
|
|
398
|
-
const constraintInDb = find(constraintsInDb, {
|
|
399
|
-
table_schema: expectedTableSchema,
|
|
400
|
-
table_name: expectedTableName,
|
|
401
|
-
constraint_type: "PRIMARY KEY",
|
|
402
|
-
constraint_name: expectedContraintName,
|
|
403
|
-
});
|
|
404
|
-
if (!constraintInDb) {
|
|
405
|
-
await server.queryDatabaseObject(
|
|
406
|
-
`ALTER TABLE ${queryBuilder.quoteTable(model)} ADD CONSTRAINT ${queryBuilder.quoteObject(expectedContraintName)} PRIMARY KEY (id);`,
|
|
407
|
-
[],
|
|
408
|
-
);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// generate indexes
|
|
413
|
-
for (const model of applicationConfig.models) {
|
|
414
|
-
if (!model.indexes || !model.indexes.length) {
|
|
415
|
-
continue;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
logger.debug(`Creating indexes of table ${queryBuilder.quoteTable(model)}`);
|
|
419
|
-
for (const index of model.indexes) {
|
|
420
|
-
const sqlCreateIndex = generateTableIndexDDL(queryBuilder, server, model, index);
|
|
421
|
-
await server.tryQueryDatabaseObject(sqlCreateIndex, []);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
function generateCreateColumnDDL(
|
|
427
|
-
queryBuilder: IQueryBuilder,
|
|
428
|
-
options: {
|
|
429
|
-
schema?: string;
|
|
430
|
-
tableName: string;
|
|
431
|
-
name: string;
|
|
432
|
-
type: RpdDataPropertyTypes;
|
|
433
|
-
autoIncrement?: boolean;
|
|
434
|
-
notNull?: boolean;
|
|
435
|
-
defaultValue?: string;
|
|
436
|
-
},
|
|
437
|
-
) {
|
|
438
|
-
let columnDDL = `ALTER TABLE ${queryBuilder.quoteTable(options)} ADD`;
|
|
439
|
-
columnDDL += ` ${queryBuilder.quoteObject(options.name)}`;
|
|
440
|
-
if (options.type === "integer" && options.autoIncrement) {
|
|
441
|
-
columnDDL += ` serial`;
|
|
442
|
-
} else {
|
|
443
|
-
const columnType = pgPropertyTypeColumnMap[options.type];
|
|
444
|
-
if (!columnType) {
|
|
445
|
-
throw new Error(`Property type "${options.type}" is not supported.`);
|
|
446
|
-
}
|
|
447
|
-
columnDDL += ` ${columnType}`;
|
|
448
|
-
}
|
|
449
|
-
if (options.notNull) {
|
|
450
|
-
columnDDL += " NOT NULL";
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
if (options.defaultValue) {
|
|
454
|
-
columnDDL += ` DEFAULT ${options.defaultValue}`;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
return columnDDL;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
function generateLinkTableDDL(
|
|
461
|
-
queryBuilder: IQueryBuilder,
|
|
462
|
-
options: {
|
|
463
|
-
linkSchema?: string;
|
|
464
|
-
linkTableName: string;
|
|
465
|
-
targetIdColumnName: string;
|
|
466
|
-
selfIdColumnName: string;
|
|
467
|
-
},
|
|
468
|
-
) {
|
|
469
|
-
let columnDDL = `CREATE TABLE ${queryBuilder.quoteTable({
|
|
470
|
-
schema: options.linkSchema,
|
|
471
|
-
tableName: options.linkTableName,
|
|
472
|
-
})} (`;
|
|
473
|
-
columnDDL += `id serial not null,`;
|
|
474
|
-
columnDDL += `${queryBuilder.quoteObject(options.selfIdColumnName)} integer not null,`;
|
|
475
|
-
columnDDL += `${queryBuilder.quoteObject(options.targetIdColumnName)} integer not null);`;
|
|
476
|
-
|
|
477
|
-
return columnDDL;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
function generateTableIndexDDL(queryBuilder: IQueryBuilder, server: IRpdServer, model: RpdDataModel, index: RpdDataModelIndex) {
|
|
481
|
-
let indexName = index.name;
|
|
482
|
-
if (!indexName) {
|
|
483
|
-
indexName = model.tableName;
|
|
484
|
-
for (const indexProp of index.properties) {
|
|
485
|
-
const propCode = isString(indexProp) ? indexProp : indexProp.code;
|
|
486
|
-
const property = getEntityPropertyByCode(server, model, propCode);
|
|
487
|
-
if (!isRelationProperty(property)) {
|
|
488
|
-
indexName += "_" + property.columnName;
|
|
489
|
-
} else if (isOneRelationProperty(property)) {
|
|
490
|
-
indexName += "_" + property.targetIdColumnName;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
indexName += index.unique ? "_uindex" : "_index";
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
const indexColumns = map(index.properties, (indexProp) => {
|
|
497
|
-
let columnName: string;
|
|
498
|
-
const propCode = isString(indexProp) ? indexProp : indexProp.code;
|
|
499
|
-
const property = getEntityPropertyByCode(server, model, propCode);
|
|
500
|
-
if (!isRelationProperty(property)) {
|
|
501
|
-
columnName = property.columnName;
|
|
502
|
-
} else if (isOneRelationProperty(property)) {
|
|
503
|
-
columnName = property.targetIdColumnName;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
if (isString(indexProp)) {
|
|
507
|
-
return columnName;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
if (indexProp.order === "desc") {
|
|
511
|
-
return `${columnName} desc`;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
return columnName;
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
let ddl = `CREATE ${index.unique ? "UNIQUE" : ""} INDEX ${indexName} `;
|
|
518
|
-
ddl += `ON ${queryBuilder.quoteTable({
|
|
519
|
-
schema: model.schema,
|
|
520
|
-
tableName: model.tableName,
|
|
521
|
-
})} (${indexColumns.join(", ")})`;
|
|
522
|
-
|
|
523
|
-
if (index.conditions) {
|
|
524
|
-
const logger = server.getLogger();
|
|
525
|
-
const rowFilterOptions = convertModelIndexConditionsToRowFilterOptions(logger, model, index.conditions);
|
|
526
|
-
ddl += ` WHERE ${queryBuilder.buildFiltersExpression(model, rowFilterOptions)}`;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
return ddl;
|
|
530
|
-
}
|