mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-22 07:10:53 +00:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import DataMigrationBase from "./DataMigrationBase";
|
|
import AnalyticsTableColumn from "Common/Types/AnalyticsDatabase/TableColumn";
|
|
import SpanService from "Common/Server/Services/SpanService";
|
|
import Span from "Common/Models/AnalyticsModels/Span";
|
|
|
|
export default class AddDurationColumnToSpanTable extends DataMigrationBase {
|
|
public constructor() {
|
|
super("AddDurationColumnToSpanTable");
|
|
}
|
|
|
|
public override async migrate(): Promise<void> {
|
|
const hasDurationColumn: boolean =
|
|
await SpanService.doesColumnExistInDatabase("durationUnixNano");
|
|
|
|
const durationColumn: AnalyticsTableColumn = new Span().tableColumns.find(
|
|
(column: AnalyticsTableColumn) => {
|
|
return column.key === "durationUnixNano";
|
|
},
|
|
)!;
|
|
|
|
if (!hasDurationColumn && durationColumn) {
|
|
await SpanService.addColumnInDatabase(durationColumn);
|
|
}
|
|
}
|
|
|
|
public override async rollback(): Promise<void> {
|
|
const hasDurationColumn: boolean =
|
|
await SpanService.doesColumnExistInDatabase("durationUnixNano");
|
|
|
|
if (hasDurationColumn) {
|
|
await SpanService.dropColumnInDatabase("durationUnixNano");
|
|
}
|
|
}
|
|
}
|