members-database/migrations/1723905344553-initial.ts

42 lines
5.1 KiB
TypeScript
Raw Permalink Normal View History

2024-08-17 14:38:08 +00:00
import { MigrationInterface, QueryRunner } from "typeorm";
export class Initial1723905344553 implements MigrationInterface {
name = 'Initial1723905344553'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`executive_position\` (\`id\` varchar(36) NOT NULL, \`postition\` varchar(255) NOT NULL, \`number_of_performers\` int NOT NULL DEFAULT '1', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`qualification\` (\`id\` varchar(36) NOT NULL, \`qualification\` varchar(255) NOT NULL, \`number_of_performers\` int NOT NULL DEFAULT '1', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`member\` (\`id\` varchar(36) NOT NULL, \`member_id\` varchar(255) NULL, \`firstname\` varchar(255) NOT NULL, \`lastname\` varchar(255) NOT NULL, \`phone\` varchar(255) NOT NULL, \`mobile\` varchar(255) NOT NULL, \`email\` varchar(255) NOT NULL, \`postal_code\` varchar(255) NOT NULL, \`place\` varchar(255) NOT NULL, \`street\` varchar(255) NOT NULL, \`birthdate\` date NOT NULL, \`accession_date\` date NOT NULL, \`leaving_data\` date NULL, \`active\` tinyint NOT NULL DEFAULT 1, \`push_alert\` tinyint NOT NULL DEFAULT 0, UNIQUE INDEX \`IDX_73e1828d94de0b2ddf89da0546\` (\`member_id\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`authentication\` (\`username\` varchar(36) NOT NULL, \`secret\` varchar(255) NOT NULL, PRIMARY KEY (\`username\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`session\` (\`accessToken\` varchar(36) NOT NULL, \`expiration\` datetime NOT NULL, \`memberId\` varchar(36) NULL, PRIMARY KEY (\`accessToken\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`member_executive_position\` (\`memberId\` varchar(36) NOT NULL, \`executivePositionId\` varchar(36) NOT NULL, INDEX \`IDX_d624e879b218a815ba6280ee03\` (\`memberId\`), INDEX \`IDX_871ad125ada81704d0ff5f77fd\` (\`executivePositionId\`), PRIMARY KEY (\`memberId\`, \`executivePositionId\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`member_qualification\` (\`memberId\` varchar(36) NOT NULL, \`qualificationId\` varchar(36) NOT NULL, INDEX \`IDX_6e044da7d52bc06dbe86451acd\` (\`memberId\`), INDEX \`IDX_0cd599d7a2617a381266258693\` (\`qualificationId\`), PRIMARY KEY (\`memberId\`, \`qualificationId\`)) ENGINE=InnoDB`);
await queryRunner.query(`ALTER TABLE \`session\` ADD CONSTRAINT \`FK_1f8d57f74fb4486a743d89d4820\` FOREIGN KEY (\`memberId\`) REFERENCES \`member\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`member_executive_position\` ADD CONSTRAINT \`FK_d624e879b218a815ba6280ee035\` FOREIGN KEY (\`memberId\`) REFERENCES \`member\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`);
await queryRunner.query(`ALTER TABLE \`member_executive_position\` ADD CONSTRAINT \`FK_871ad125ada81704d0ff5f77fda\` FOREIGN KEY (\`executivePositionId\`) REFERENCES \`executive_position\`(\`id\`) ON DELETE RESTRICT ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`member_qualification\` ADD CONSTRAINT \`FK_6e044da7d52bc06dbe86451acdc\` FOREIGN KEY (\`memberId\`) REFERENCES \`member\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`);
await queryRunner.query(`ALTER TABLE \`member_qualification\` ADD CONSTRAINT \`FK_0cd599d7a2617a3812662586930\` FOREIGN KEY (\`qualificationId\`) REFERENCES \`qualification\`(\`id\`) ON DELETE RESTRICT ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`member_qualification\` DROP FOREIGN KEY \`FK_0cd599d7a2617a3812662586930\``);
await queryRunner.query(`ALTER TABLE \`member_qualification\` DROP FOREIGN KEY \`FK_6e044da7d52bc06dbe86451acdc\``);
await queryRunner.query(`ALTER TABLE \`member_executive_position\` DROP FOREIGN KEY \`FK_871ad125ada81704d0ff5f77fda\``);
await queryRunner.query(`ALTER TABLE \`member_executive_position\` DROP FOREIGN KEY \`FK_d624e879b218a815ba6280ee035\``);
await queryRunner.query(`ALTER TABLE \`session\` DROP FOREIGN KEY \`FK_1f8d57f74fb4486a743d89d4820\``);
await queryRunner.query(`DROP INDEX \`IDX_0cd599d7a2617a381266258693\` ON \`member_qualification\``);
await queryRunner.query(`DROP INDEX \`IDX_6e044da7d52bc06dbe86451acd\` ON \`member_qualification\``);
await queryRunner.query(`DROP TABLE \`member_qualification\``);
await queryRunner.query(`DROP INDEX \`IDX_871ad125ada81704d0ff5f77fd\` ON \`member_executive_position\``);
await queryRunner.query(`DROP INDEX \`IDX_d624e879b218a815ba6280ee03\` ON \`member_executive_position\``);
await queryRunner.query(`DROP TABLE \`member_executive_position\``);
await queryRunner.query(`DROP TABLE \`session\``);
await queryRunner.query(`DROP TABLE \`authentication\``);
await queryRunner.query(`DROP INDEX \`IDX_73e1828d94de0b2ddf89da0546\` ON \`member\``);
await queryRunner.query(`DROP TABLE \`member\``);
await queryRunner.query(`DROP TABLE \`qualification\``);
await queryRunner.query(`DROP TABLE \`executive_position\``);
}
}