members-database/migrations/1724242210553-initial.ts

54 lines
7.4 KiB
TypeScript

import { MigrationInterface, QueryRunner } from "typeorm";
export class Initial1724242210553 implements MigrationInterface {
name = 'Initial1724242210553'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`membership_status\` (\`id\` int NOT NULL AUTO_INCREMENT, \`status\` varchar(255) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`membership\` (\`id\` int NOT NULL AUTO_INCREMENT, \`start\` date NOT NULL, \`end\` date NULL, \`termination_reason\` varchar(255) NULL, \`memberId\` int NULL, \`statusId\` int NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`qualification\` (\`id\` int NOT NULL AUTO_INCREMENT, \`qualification\` varchar(255) NOT NULL, \`description\` varchar(255) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`member_qualifications\` (\`id\` int NOT NULL AUTO_INCREMENT, \`given\` tinyint NOT NULL DEFAULT 1, \`note\` varchar(255) NULL, \`date\` date NOT NULL, \`memberId\` int NULL, \`qualificationId\` int NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`executive_position\` (\`id\` int NOT NULL AUTO_INCREMENT, \`postition\` varchar(255) NOT NULL, \`number_of_performers\` int NOT NULL DEFAULT '-1', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`member_executive_positions\` (\`id\` int NOT NULL AUTO_INCREMENT, \`given\` tinyint NOT NULL DEFAULT 1, \`note\` varchar(255) NULL, \`date\` date NOT NULL, \`memberId\` int NULL, \`executivePositionId\` int NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`communication\` (\`id\` int NOT NULL AUTO_INCREMENT, \`type\` enum ('phone', 'mobile', 'address', 'mail', 'internalMail') NOT NULL DEFAULT 'phone', \`preffered\` tinyint NOT NULL DEFAULT 0, \`mobile\` varchar(255) NOT NULL, \`email\` varchar(255) NOT NULL, \`city\` varchar(255) NOT NULL, \`street\` varchar(255) NOT NULL, \`streetnumber\` int NOT NULL, \`streetnumber_addition\` varchar(255) NOT NULL, \`memberId\` int NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`member\` (\`id\` int NOT NULL AUTO_INCREMENT, \`member_id\` varchar(255) NULL, \`salutation\` enum ('sir', 'madam', 'other', 'none') NOT NULL DEFAULT 'none', \`firstname\` varchar(255) NOT NULL, \`lastname\` varchar(255) NOT NULL, \`nameaffix\` varchar(255) NOT NULL, \`birthdate\` date NOT NULL, \`deathdate\` date NULL, \`sepa_mandat\` varchar(255) NULL, \`communicationsId\` int NULL, UNIQUE INDEX \`IDX_73e1828d94de0b2ddf89da0546\` (\`member_id\`), UNIQUE INDEX \`IDX_ab51d77cababfc4aa052344ec3\` (\`sepa_mandat\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`member_awards\` (\`id\` int NOT NULL AUTO_INCREMENT, \`given\` tinyint NOT NULL DEFAULT 1, \`note\` varchar(255) NULL, \`date\` date NOT NULL, \`memberId\` int NULL, \`awardId\` int NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`award\` (\`id\` int NOT NULL AUTO_INCREMENT, \`award\` varchar(255) NOT NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`ALTER TABLE \`membership\` ADD CONSTRAINT \`FK_3b4b41597707b13086e71727422\` FOREIGN KEY (\`memberId\`) REFERENCES \`member\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`membership\` ADD CONSTRAINT \`FK_e9fd4d37c4ac0fb08bd6eeeda3c\` FOREIGN KEY (\`statusId\`) REFERENCES \`membership_status\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`member_qualifications\` ADD CONSTRAINT \`FK_98b70e687c35709d2f01b3d7d74\` FOREIGN KEY (\`memberId\`) REFERENCES \`member\`(\`id\`) ON DELETE RESTRICT ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`member_qualifications\` ADD CONSTRAINT \`FK_dbebe53df1caa0b6715a220b0ea\` FOREIGN KEY (\`qualificationId\`) REFERENCES \`qualification\`(\`id\`) ON DELETE RESTRICT ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`member_executive_positions\` ADD CONSTRAINT \`FK_2912b056a5d0b7977360a986164\` FOREIGN KEY (\`memberId\`) REFERENCES \`member\`(\`id\`) ON DELETE RESTRICT ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`member_executive_positions\` ADD CONSTRAINT \`FK_1fd52c8f109123e5a2c67dc2c83\` FOREIGN KEY (\`executivePositionId\`) REFERENCES \`executive_position\`(\`id\`) ON DELETE RESTRICT ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`communication\` ADD CONSTRAINT \`FK_fc5f59e5c9aafdedd25ed8ed36e\` FOREIGN KEY (\`memberId\`) REFERENCES \`member\`(\`id\`) ON DELETE RESTRICT ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`member\` ADD CONSTRAINT \`FK_de8e6856d6b77e1b2815a8c0d4f\` FOREIGN KEY (\`communicationsId\`) REFERENCES \`communication\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`member_awards\` ADD CONSTRAINT \`FK_a47e04bfd3671d8a375d1896d25\` FOREIGN KEY (\`memberId\`) REFERENCES \`member\`(\`id\`) ON DELETE RESTRICT ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`member_awards\` ADD CONSTRAINT \`FK_ba47b44c2ddf34c1bcc75df6675\` FOREIGN KEY (\`awardId\`) REFERENCES \`award\`(\`id\`) ON DELETE RESTRICT ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`member_awards\` DROP FOREIGN KEY \`FK_ba47b44c2ddf34c1bcc75df6675\``);
await queryRunner.query(`ALTER TABLE \`member_awards\` DROP FOREIGN KEY \`FK_a47e04bfd3671d8a375d1896d25\``);
await queryRunner.query(`ALTER TABLE \`member\` DROP FOREIGN KEY \`FK_de8e6856d6b77e1b2815a8c0d4f\``);
await queryRunner.query(`ALTER TABLE \`communication\` DROP FOREIGN KEY \`FK_fc5f59e5c9aafdedd25ed8ed36e\``);
await queryRunner.query(`ALTER TABLE \`member_executive_positions\` DROP FOREIGN KEY \`FK_1fd52c8f109123e5a2c67dc2c83\``);
await queryRunner.query(`ALTER TABLE \`member_executive_positions\` DROP FOREIGN KEY \`FK_2912b056a5d0b7977360a986164\``);
await queryRunner.query(`ALTER TABLE \`member_qualifications\` DROP FOREIGN KEY \`FK_dbebe53df1caa0b6715a220b0ea\``);
await queryRunner.query(`ALTER TABLE \`member_qualifications\` DROP FOREIGN KEY \`FK_98b70e687c35709d2f01b3d7d74\``);
await queryRunner.query(`ALTER TABLE \`membership\` DROP FOREIGN KEY \`FK_e9fd4d37c4ac0fb08bd6eeeda3c\``);
await queryRunner.query(`ALTER TABLE \`membership\` DROP FOREIGN KEY \`FK_3b4b41597707b13086e71727422\``);
await queryRunner.query(`DROP TABLE \`award\``);
await queryRunner.query(`DROP TABLE \`member_awards\``);
await queryRunner.query(`DROP INDEX \`IDX_ab51d77cababfc4aa052344ec3\` ON \`member\``);
await queryRunner.query(`DROP INDEX \`IDX_73e1828d94de0b2ddf89da0546\` ON \`member\``);
await queryRunner.query(`DROP TABLE \`member\``);
await queryRunner.query(`DROP TABLE \`communication\``);
await queryRunner.query(`DROP TABLE \`member_executive_positions\``);
await queryRunner.query(`DROP TABLE \`executive_position\``);
await queryRunner.query(`DROP TABLE \`member_qualifications\``);
await queryRunner.query(`DROP TABLE \`qualification\``);
await queryRunner.query(`DROP TABLE \`membership\``);
await queryRunner.query(`DROP TABLE \`membership_status\``);
}
}