ily.li/oldsrc/src/migrations/CreateAuthTokensTable.ts

29 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-11-22 13:49:08 +01:00
import Migration from "swaf/db/Migration";
import ModelFactory from "swaf/db/ModelFactory";
2022-02-19 09:30:51 +01:00
import AuthToken from "../models/AuthToken.js";
2020-06-14 13:01:52 +02:00
export default class CreateAuthTokensTable extends Migration {
2021-01-25 17:43:26 +01:00
public async install(): Promise<void> {
2020-08-11 17:54:15 +02:00
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(),
used_at DATETIME NOT NULL DEFAULT NOW(),
ttl INT UNSIGNED NOT NULL,
PRIMARY KEY (id)
2021-01-25 17:43:26 +01:00
)`);
2020-06-14 13:01:52 +02:00
}
2021-01-25 17:43:26 +01:00
public async rollback(): Promise<void> {
await this.query(`DROP TABLE IF EXISTS auth_tokens`);
2020-08-11 17:54:15 +02:00
}
public registerModels(): void {
ModelFactory.register(AuthToken);
2020-06-14 13:01:52 +02:00
}
2020-11-22 13:49:08 +01:00
}