2024-06-14 11:09:53 +00:00
|
|
|
import DataMigrationBase from "./DataMigrationBase";
|
|
|
|
import AnalyticsTableColumn from "Common/Types/AnalyticsDatabase/TableColumn";
|
2024-08-07 21:50:32 +00:00
|
|
|
import SpanService from "Common/Server/Services/SpanService";
|
2024-08-05 19:05:53 +00:00
|
|
|
import Span from "Common/Models/AnalyticsModels/Span";
|
2024-02-25 12:19:57 +00:00
|
|
|
|
|
|
|
export default class AddDurationColumnToSpanTable extends DataMigrationBase {
|
2024-06-14 11:09:53 +00:00
|
|
|
public constructor() {
|
|
|
|
super("AddDurationColumnToSpanTable");
|
|
|
|
}
|
2024-02-25 12:19:57 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
public override async migrate(): Promise<void> {
|
|
|
|
const hasDurationColumn: boolean =
|
|
|
|
await SpanService.doesColumnExistInDatabase("durationUnixNano");
|
2024-02-25 12:19:57 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
const durationColumn: AnalyticsTableColumn = new Span().tableColumns.find(
|
|
|
|
(column: AnalyticsTableColumn) => {
|
|
|
|
return column.key === "durationUnixNano";
|
|
|
|
},
|
|
|
|
)!;
|
2024-02-25 12:19:57 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
if (!hasDurationColumn && durationColumn) {
|
|
|
|
await SpanService.addColumnInDatabase(durationColumn);
|
2024-02-25 12:19:57 +00:00
|
|
|
}
|
2024-06-14 11:09:53 +00:00
|
|
|
}
|
2024-02-25 12:19:57 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
public override async rollback(): Promise<void> {
|
|
|
|
const hasDurationColumn: boolean =
|
|
|
|
await SpanService.doesColumnExistInDatabase("durationUnixNano");
|
2024-02-25 12:19:57 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
if (hasDurationColumn) {
|
|
|
|
await SpanService.dropColumnInDatabase("durationUnixNano");
|
2024-02-25 12:19:57 +00:00
|
|
|
}
|
2024-06-14 11:09:53 +00:00
|
|
|
}
|
2024-02-25 12:19:57 +00:00
|
|
|
}
|