29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import Migration from "swaf/db/Migration";
|
|
import ModelFactory from "swaf/db/ModelFactory";
|
|
|
|
import AuthToken from "../models/AuthToken.js";
|
|
|
|
export default class CreateAuthTokensTable extends Migration {
|
|
public async install(): 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(),
|
|
used_at DATETIME NOT NULL DEFAULT NOW(),
|
|
ttl INT UNSIGNED NOT NULL,
|
|
PRIMARY KEY (id)
|
|
)`);
|
|
}
|
|
|
|
public async rollback(): Promise<void> {
|
|
await this.query(`DROP TABLE IF EXISTS auth_tokens`);
|
|
}
|
|
|
|
public registerModels(): void {
|
|
ModelFactory.register(AuthToken);
|
|
}
|
|
|
|
}
|