refactor: Add unit column to metrics table and improve code readability in StatementGenerator.ts

This commit is contained in:
Simon Larsen 2024-06-07 17:36:09 +01:00
parent e762778fc6
commit d954b4a5df
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA
2 changed files with 12 additions and 4 deletions

View File

@ -58,7 +58,7 @@ const DataMigrations: Array<DataMigrationBase> = [
new GenerateNewCertsForStatusPage(),
new AddEndDateToMonitorStatusTimelineWhereEndDateIsMissing(),
new RemoveCanFromPermissions(),
new AddUnitColumnToMetricsTable()
new AddUnitColumnToMetricsTable(),
];
export default DataMigrations;

View File

@ -597,8 +597,14 @@ export default class StatementGenerator<TBaseModel extends AnalyticsBaseModel> {
columns
.append(keyStatement)
.append(SQL` `)
.append(column.required ? this.toColumnType(column.type): (SQL`Nullable(`.append(this.toColumnType(column.type)).append(SQL`)`)));
.append(
column.required
? this.toColumnType(column.type)
: SQL`Nullable(`
.append(this.toColumnType(column.type))
.append(SQL`)`)
);
if (nestedModelColumns) {
columns.append(SQL` `).append(nestedModelColumns);
}
@ -659,7 +665,9 @@ export default class StatementGenerator<TBaseModel extends AnalyticsBaseModel> {
const statement: Statement = SQL`
ALTER TABLE ${this.database.getDatasourceOptions().database!}.${
this.model.tableName
} ADD COLUMN IF NOT EXISTS `.append(this.toColumnsCreateStatement([column], false));
} ADD COLUMN IF NOT EXISTS `.append(
this.toColumnsCreateStatement([column], false)
);
logger.debug(`${this.model.tableName} Add Column Statement`);
logger.debug(statement);