swaf/src/migrations/CreateLogsTable.ts

33 lines
1.2 KiB
TypeScript

import Migration from "../db/Migration";
import {Connection} from "mysql";
import ModelFactory from "../db/ModelFactory";
import Log from "../models/Log";
/**
* Must be the first migration
*/
export default class CreateLogsTable extends Migration {
public async install(connection: Connection): Promise<void> {
await this.query(`CREATE TABLE logs
(
id INT NOT NULL AUTO_INCREMENT,
level TINYINT UNSIGNED NOT NULL,
message TEXT NOT NULL,
log_id BINARY(16),
error_name VARCHAR(128),
error_message VARCHAR(512),
error_stack TEXT,
created_at DATETIME NOT NULL DEFAULT NOW(),
PRIMARY KEY (id)
)`, connection);
}
public async rollback(connection: Connection): Promise<void> {
await this.query('DROP TABLE logs', connection);
}
public registerModels(): void {
ModelFactory.register(Log);
}
}