ily.li/src/migrations/CreateAuthTokensTable.ts

21 lines
783 B
TypeScript
Raw Normal View History

2020-06-14 13:01:52 +02:00
import {Connection} from "mysql";
import Migration from "wms-core/db/Migration";
export default class CreateAuthTokensTable extends Migration {
public async install(connection: Connection): Promise<void> {
await this.query('CREATE TABLE auth_tokens(' +
'id INT NOT NULL AUTO_INCREMENT,' +
'user_id INT NOT NULL,' +
'secret VARCHAR(64) UNIQUE NOT NULL,' +
'created_at DATETIME NOT NULL DEFAULT NOW(),' +
2020-06-14 21:23:57 +02:00
'used_at DATETIME NOT NULL DEFAULT NOW(),' +
'ttl INT UNSIGNED NOT NULL,' +
2020-06-14 13:01:52 +02:00
'PRIMARY KEY (id)' +
')', connection);
}
public async rollback(connection: Connection): Promise<void> {
await this.query('DROP TABLE IF EXISTS auth_tokens', connection);
}
}