mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-22 15:24:55 +00:00
Fix data migration issues and improve code readability
This commit is contained in:
parent
625a2c410c
commit
73a6b2d1fa
@ -9,7 +9,6 @@ export default class AddDurationColumnToSpanTable extends DataMigrationBase {
|
||||
}
|
||||
|
||||
public override async migrate(): Promise<void> {
|
||||
|
||||
const hasDurationColumn: boolean =
|
||||
await SpanService.doesColumnExistInDatabase('durationUnixNano');
|
||||
|
||||
|
@ -11,8 +11,6 @@ export default class ChangeLogSeverityColumnTypeFromTextToNumber extends DataMig
|
||||
|
||||
public override async migrate(): Promise<void> {
|
||||
|
||||
debugger;
|
||||
|
||||
const logSeverityNumberColumn: AnalyticsTableColumn | undefined =
|
||||
new Log().tableColumns.find((column: AnalyticsTableColumn) => {
|
||||
return column.key === 'severityNumber';
|
||||
|
@ -42,7 +42,7 @@ const DataMigrations: Array<DataMigrationBase> = [
|
||||
new AddStartDateToMonitorStatusTimeline(),
|
||||
new AddStartDateToScheduledEventsStateTimeline(),
|
||||
new AddDurationColumnToSpanTable(),
|
||||
new ChangeLogSeverityColumnTypeFromTextToNumber()
|
||||
new ChangeLogSeverityColumnTypeFromTextToNumber(),
|
||||
];
|
||||
|
||||
export default DataMigrations;
|
||||
|
@ -108,7 +108,8 @@ export default class AnalyticsDatabaseService<
|
||||
return null;
|
||||
}
|
||||
|
||||
const statement: string = this.statementGenerator.getColumnTypesStatement(columnName);
|
||||
const statement: string =
|
||||
this.statementGenerator.getColumnTypesStatement(columnName);
|
||||
|
||||
const dbResult: ExecResult<Stream> = await this.execute(statement);
|
||||
|
||||
@ -116,7 +117,11 @@ export default class AnalyticsDatabaseService<
|
||||
dbResult.stream
|
||||
);
|
||||
|
||||
return this.statementGenerator.toTableColumnType(strResult.trim()) as TableColumnType || null;
|
||||
return (
|
||||
(this.statementGenerator.toTableColumnType(
|
||||
strResult.trim()
|
||||
) as TableColumnType) || null
|
||||
);
|
||||
}
|
||||
|
||||
public async countBy(
|
||||
|
@ -451,9 +451,12 @@ export default class StatementGenerator<TBaseModel extends AnalyticsBaseModel> {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public getColumnTypesStatement(columnName: string): string {
|
||||
return `SELECT type FROM system.columns WHERE table = '${this.model.tableName}' AND database = '${this.database.getDatasourceOptions().database}' AND name = '${columnName}'`
|
||||
return `SELECT type FROM system.columns WHERE table = '${
|
||||
this.model.tableName
|
||||
}' AND database = '${
|
||||
this.database.getDatasourceOptions().database
|
||||
}' AND name = '${columnName}'`;
|
||||
}
|
||||
|
||||
public async toRenameColumnStatement(
|
||||
@ -520,20 +523,22 @@ export default class StatementGenerator<TBaseModel extends AnalyticsBaseModel> {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public toTableColumnType(clickhouseType: string): TableColumnType | undefined {
|
||||
public toTableColumnType(
|
||||
clickhouseType: string
|
||||
): TableColumnType | undefined {
|
||||
return {
|
||||
'String': TableColumnType.Text,
|
||||
'Int32': TableColumnType.Number,
|
||||
'Int64': TableColumnType.LongNumber,
|
||||
'Int128': TableColumnType.LongNumber,
|
||||
'Float32': TableColumnType.Decimal,
|
||||
'Float64': TableColumnType.Decimal,
|
||||
'DateTime': TableColumnType.Date,
|
||||
String: TableColumnType.Text,
|
||||
Int32: TableColumnType.Number,
|
||||
Int64: TableColumnType.LongNumber,
|
||||
Int128: TableColumnType.LongNumber,
|
||||
Float32: TableColumnType.Decimal,
|
||||
Float64: TableColumnType.Decimal,
|
||||
DateTime: TableColumnType.Date,
|
||||
'Array(String)': TableColumnType.ArrayText,
|
||||
'Array(Int32)': TableColumnType.ArrayNumber,
|
||||
'JSON': TableColumnType.JSON,
|
||||
'Nested': TableColumnType.NestedModel,
|
||||
'Bool': TableColumnType.Boolean,
|
||||
JSON: TableColumnType.JSON,
|
||||
Nested: TableColumnType.NestedModel,
|
||||
Bool: TableColumnType.Boolean,
|
||||
}[clickhouseType];
|
||||
}
|
||||
|
||||
@ -576,8 +581,6 @@ export default class StatementGenerator<TBaseModel extends AnalyticsBaseModel> {
|
||||
logger.info(`${this.model.tableName} Add Column Statement`);
|
||||
logger.info(statement);
|
||||
|
||||
debugger;
|
||||
|
||||
return statement;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user