ily.li/src/migrations/CreateUrlRedirectsTable.ts

27 lines
1009 B
TypeScript

import Migration from "swaf/db/Migration";
import ModelFactory from "swaf/db/ModelFactory";
import URLRedirect from "../models/URLRedirect.js";
export default class CreateUrlRedirectsTable extends Migration {
public async install(): Promise<void> {
await this.query(`CREATE TABLE url_redirects
(
id INT NOT NULL AUTO_INCREMENT,
user_id INT NOT NULL,
slug VARCHAR(259) UNIQUE NOT NULL,
target_url VARCHAR(1745) NOT NULL,
created_at DATETIME NOT NULL DEFAULT NOW(),
PRIMARY KEY (id)
)`);
}
public async rollback(): Promise<void> {
await this.query(`DROP TABLE IF EXISTS url_redirects`);
}
public registerModels(): void {
ModelFactory.register(URLRedirect);
}
}