2021-05-03 19:29:22 +02:00
|
|
|
import Migration from "../db/Migration.js";
|
|
|
|
import {query} from "../db/MysqlConnectionManager.js";
|
2020-04-22 15:52:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Must be the first migration
|
|
|
|
*/
|
|
|
|
export default class CreateMigrationsTable extends Migration {
|
2020-07-24 12:13:28 +02:00
|
|
|
public async shouldRun(currentVersion: number): Promise<boolean> {
|
2020-04-22 15:52:17 +02:00
|
|
|
try {
|
|
|
|
await query('SELECT 1 FROM migrations LIMIT 1');
|
2021-11-08 00:52:33 +01:00
|
|
|
} catch (e: any) {
|
2020-04-22 15:52:17 +02:00
|
|
|
if (e.code !== 'ER_NO_SUCH_TABLE') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return await super.shouldRun(currentVersion);
|
|
|
|
}
|
|
|
|
|
2020-11-08 15:48:34 +01:00
|
|
|
public async install(): Promise<void> {
|
2020-07-24 12:13:28 +02:00
|
|
|
await this.query(`CREATE TABLE migrations
|
|
|
|
(
|
|
|
|
id INT NOT NULL,
|
|
|
|
name VARCHAR(64) NOT NULL,
|
|
|
|
migration_date DATE,
|
|
|
|
PRIMARY KEY (id)
|
2020-11-08 15:48:34 +01:00
|
|
|
)`);
|
2020-04-22 15:52:17 +02:00
|
|
|
}
|
|
|
|
|
2020-11-08 15:48:34 +01:00
|
|
|
public async rollback(): Promise<void> {
|
|
|
|
await this.query('DROP TABLE migrations');
|
2020-04-22 15:52:17 +02:00
|
|
|
}
|
2020-09-25 23:42:15 +02:00
|
|
|
}
|