Deprecate legacy migrations

Fix CreateUsersAndUserEmailsTableMigration


sq
This commit is contained in:
Alice Gaudon 2020-11-11 19:29:04 +01:00
parent 03d9826f93
commit 79c2f33000
4 changed files with 9 additions and 7 deletions

View File

@ -8,7 +8,7 @@ export default class CreateUsersAndUserEmailsTable extends Migration {
await this.query(`CREATE TABLE users
(
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(64),
main_email_id INT,
is_admin BOOLEAN NOT NULL DEFAULT false,
created_at DATETIME NOT NULL DEFAULT NOW(),
updated_at DATETIME NOT NULL DEFAULT NOW(),
@ -19,11 +19,12 @@ export default class CreateUsersAndUserEmailsTable extends Migration {
id INT NOT NULL AUTO_INCREMENT,
user_id INT NOT NULL,
email VARCHAR(254) UNIQUE NOT NULL,
main BOOLEAN NOT NULL,
created_at DATETIME NOT NULL DEFAULT NOW(),
PRIMARY KEY (id),
FOREIGN KEY user_fk (user_id) REFERENCES users (id) ON DELETE CASCADE
)`);
await this.query(`ALTER TABLE users
ADD FOREIGN KEY main_user_email_fk (main_email_id) REFERENCES user_emails (id) ON DELETE SET NULL`);
}
public async rollback(): Promise<void> {

View File

@ -1,5 +1,8 @@
import Migration from "../../db/Migration";
/**
* @deprecated - TODO may be remove at next major version >= 0.24, replace with DummyMigration.
*/
export default class DropNameFromUsers extends Migration {
public async install(): Promise<void> {
await this.query('ALTER TABLE users DROP COLUMN name');
@ -8,5 +11,4 @@ export default class DropNameFromUsers extends Migration {
public async rollback(): Promise<void> {
await this.query('ALTER TABLE users ADD COLUMN name VARCHAR(64)');
}
}

View File

@ -1,5 +1,8 @@
import Migration from "../../db/Migration";
/**
* @deprecated - TODO may be remove at next major version >= 0.24, replace with DummyMigration.
*/
export default class FixUserMainEmailRelation extends Migration {
public async install(): Promise<void> {
await this.query(`ALTER TABLE users

View File

@ -1,13 +1,9 @@
import CreateMigrationsTable from "../src/migrations/CreateMigrationsTable";
import CreateUsersAndUserEmailsTable from "../src/auth/migrations/CreateUsersAndUserEmailsTable";
import FixUserMainEmailRelation from "../src/auth/migrations/FixUserMainEmailRelation";
import DropNameFromUsers from "../src/auth/migrations/DropNameFromUsers";
import CreateMagicLinksTable from "../src/auth/migrations/CreateMagicLinksTable";
export const MIGRATIONS = [
CreateMigrationsTable,
CreateUsersAndUserEmailsTable,
FixUserMainEmailRelation,
DropNameFromUsers,
CreateMagicLinksTable,
];