members-database/migrations/1723904760865-initial.ts
2024-08-17 16:30:11 +02:00

41 lines
5.2 KiB
TypeScript

import { MigrationInterface, QueryRunner } from "typeorm";
export class Initial1723904760865 implements MigrationInterface {
name = 'Initial1723904760865'
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_e3567ff6ba485f4e7a53f7f805\` (\`memberId\`), INDEX \`IDX_414e7d5fd60324d3a167a17c72\` (\`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_e3567ff6ba485f4e7a53f7f8053\` FOREIGN KEY (\`memberId\`) REFERENCES \`member\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`);
await queryRunner.query(`ALTER TABLE \`member__executive_position\` ADD CONSTRAINT \`FK_414e7d5fd60324d3a167a17c72c\` 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_414e7d5fd60324d3a167a17c72c\``);
await queryRunner.query(`ALTER TABLE \`member__executive_position\` DROP FOREIGN KEY \`FK_e3567ff6ba485f4e7a53f7f8053\``);
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_414e7d5fd60324d3a167a17c72\` ON \`member__executive_position\``);
await queryRunner.query(`DROP INDEX \`IDX_e3567ff6ba485f4e7a53f7f805\` 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\``);
}
}