import {Connection} from "mysql"; import {Type} from "../Utils.js"; import MysqlConnectionManager from "./MysqlConnectionManager.js"; export default abstract class Migration { public readonly version: number; private currentConnection?: Connection; public constructor(version: number) { this.version = version; } public async shouldRun(currentVersion: number): Promise { return this.version > currentVersion; } public abstract install(): Promise; public abstract rollback(): Promise; public registerModels?(): void; protected async query(queryString: string): Promise { await MysqlConnectionManager.query(queryString, undefined, this.getCurrentConnection()); } protected getCurrentConnection(): Connection { if (!this.currentConnection) throw new Error('No current connection set.'); return this.currentConnection; } public setCurrentConnection(connection: Connection | null): void { this.currentConnection = connection || undefined; } } export interface MigrationType extends Type { new(version: number): M; }