2024-06-14 11:09:53 +00:00
|
|
|
import DataMigrationBase from "./DataMigrationBase";
|
|
|
|
import AnalyticsTableColumn from "Common/Types/AnalyticsDatabase/TableColumn";
|
|
|
|
import TableColumnType from "Common/Types/AnalyticsDatabase/TableColumnType";
|
2024-08-07 21:50:32 +00:00
|
|
|
import MetricService from "Common/Server/Services/MetricService";
|
2024-08-05 19:05:53 +00:00
|
|
|
import Metric from "Common/Models/AnalyticsModels/Metric";
|
2024-06-10 11:49:29 +00:00
|
|
|
|
|
|
|
export default class AddIsMonotonicToMetric extends DataMigrationBase {
|
2024-06-14 11:09:53 +00:00
|
|
|
public constructor() {
|
|
|
|
super("AddIsMonotonicToMetric");
|
|
|
|
}
|
2024-06-10 11:49:29 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
public override async migrate(): Promise<void> {
|
|
|
|
const column: AnalyticsTableColumn | undefined =
|
|
|
|
new Metric().tableColumns.find((column: AnalyticsTableColumn) => {
|
|
|
|
return column.key === "isMonotonic";
|
|
|
|
});
|
2024-06-10 11:49:29 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
if (!column) {
|
|
|
|
return;
|
|
|
|
}
|
2024-06-10 11:49:29 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
const columnType: TableColumnType | null =
|
|
|
|
await MetricService.getColumnTypeInDatabase(column);
|
2024-06-10 11:49:29 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
if (!columnType) {
|
|
|
|
await MetricService.dropColumnInDatabase("isMonotonic");
|
|
|
|
await MetricService.addColumnInDatabase(column);
|
2024-06-10 11:49:29 +00:00
|
|
|
}
|
2024-06-14 11:09:53 +00:00
|
|
|
}
|
2024-06-10 11:49:29 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
public override async rollback(): Promise<void> {
|
|
|
|
return;
|
|
|
|
}
|
2024-06-10 11:49:29 +00:00
|
|
|
}
|