import Migration from "../db/Migration"; import {Connection} from "mysql"; import {query} from "../db/MysqlConnectionManager"; /** * Must be the first migration */ export default class CreateMigrationsTable extends Migration { public async shouldRun(currentVersion: number): Promise { try { await query('SELECT 1 FROM migrations LIMIT 1'); } catch (e) { if (e.code !== 'ER_NO_SUCH_TABLE') { return false; } } return await super.shouldRun(currentVersion); } public async install(connection: Connection): Promise { await this.query(`CREATE TABLE migrations ( id INT NOT NULL, name VARCHAR(64) NOT NULL, migration_date DATE, PRIMARY KEY (id) )`, connection); } public async rollback(connection: Connection): Promise { await this.query('DROP TABLE migrations', connection); } public registerModels(): void { } }