From 466e5933c038050be52a1be68b149e043ff41846 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Mon, 19 Aug 2024 12:47:10 +0200 Subject: [PATCH] split member --- data-source.ts | 21 ++++++- entities/award.ts | 16 +++++ entities/city.ts | 25 ++++++++ entities/city_district.ts | 21 +++++++ entities/executive_position.ts | 2 +- entities/member.ts | 56 ++++++++++++----- entities/member_awards.ts | 32 ++++++++++ entities/membership.ts | 25 ++++++++ entities/qualification.ts | 4 +- enums/membership_type.ts | 4 ++ enums/newsletter_type.ts | 5 ++ enums/salutation.ts | 6 ++ index.ts | 9 +++ migrations/1724064152696-split_member.ts | 79 ++++++++++++++++++++++++ 14 files changed, 286 insertions(+), 19 deletions(-) create mode 100644 entities/award.ts create mode 100644 entities/city.ts create mode 100644 entities/city_district.ts create mode 100644 entities/member_awards.ts create mode 100644 entities/membership.ts create mode 100644 enums/membership_type.ts create mode 100644 enums/newsletter_type.ts create mode 100644 enums/salutation.ts create mode 100644 migrations/1724064152696-split_member.ts diff --git a/data-source.ts b/data-source.ts index 21b159e..add9016 100644 --- a/data-source.ts +++ b/data-source.ts @@ -4,9 +4,15 @@ import { DataSource } from "typeorm"; import { member } from "./entities/member"; import { executive_position } from "./entities/executive_position"; import { qualification } from "./entities/qualification"; +import { member_awards } from "./entities/member_awards"; +import { award } from "./entities/award"; +import { city } from "./entities/city"; +import { city_district } from "./entities/city_district"; +import { membership } from "./entities/membership"; import { authentication } from "./entities/authentication"; import { session } from "./entities/session"; import { Initial1723905344553 } from "./migrations/1723905344553-initial"; +import { SplitMember1724064152696 } from "./migrations/1724064152696-split_member"; const dataSource = new DataSource({ type: "mysql", @@ -18,8 +24,19 @@ const dataSource = new DataSource({ synchronize: false, logging: process.env.NODE_ENV ? true : ["schema", "error", "warn", "log", "migration"], bigNumberStrings: false, - entities: [member, executive_position, qualification, authentication, session], - migrations: [Initial1723905344553], + entities: [ + member, + executive_position, + qualification, + member_awards, + award, + city, + city_district, + membership, + authentication, + session, + ], + migrations: [Initial1723905344553, SplitMember1724064152696], migrationsRun: true, migrationsTransactionMode: "each", subscribers: [], diff --git a/entities/award.ts b/entities/award.ts new file mode 100644 index 0000000..3f45392 --- /dev/null +++ b/entities/award.ts @@ -0,0 +1,16 @@ +import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm"; +import { member_awards } from "./member_awards"; + +@Entity() +export class award { + @PrimaryColumn({ generated: "uuid", type: "varchar", length: 36 }) + id: string; + + @Column({ type: "varchar", length: 255 }) + award: string; + + @OneToMany(() => member_awards, (member) => member.award, { + onDelete: "RESTRICT", + }) + members: member_awards[]; +} diff --git a/entities/city.ts b/entities/city.ts new file mode 100644 index 0000000..caf4f8b --- /dev/null +++ b/entities/city.ts @@ -0,0 +1,25 @@ +import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm"; +import { member } from "./member"; +import { city_district } from "./city_district"; + +@Entity() +export class city { + @PrimaryColumn({ generated: "uuid", type: "varchar", length: 36 }) + id: string; + + @Column({ type: "varchar", length: 255, unique: true }) + postal_code: string; + + @Column({ type: "varchar", length: 255 }) + city: string; + + @OneToMany(() => city_district, (district) => district.city, { + onDelete: "RESTRICT", + }) + districts: city_district[]; + + @OneToMany(() => member, (member) => member.city_district, { + onDelete: "RESTRICT", + }) + members: member[]; +} diff --git a/entities/city_district.ts b/entities/city_district.ts new file mode 100644 index 0000000..7d287f7 --- /dev/null +++ b/entities/city_district.ts @@ -0,0 +1,21 @@ +import { Column, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryColumn } from "typeorm"; +import { member } from "./member"; +import { city } from "./city"; + +@Entity() +export class city_district { + @PrimaryColumn({ generated: "uuid", type: "varchar", length: 36 }) + id: string; + + @Column({ type: "varchar", length: 255, unique: true, nullable: true }) + district?: string; + + @ManyToOne(() => city, (city) => city.districts) + @JoinColumn() + city: city; + + @OneToMany(() => member, (member) => member.city_district, { + onDelete: "RESTRICT", + }) + members: member[]; +} diff --git a/entities/executive_position.ts b/entities/executive_position.ts index 445dbc1..b95a51c 100644 --- a/entities/executive_position.ts +++ b/entities/executive_position.ts @@ -9,7 +9,7 @@ export class executive_position { @Column({ type: "varchar", length: 255 }) postition: string; - @Column({ type: "int", default: 1 }) + @Column({ type: "int", default: -1 }) number_of_performers: string; @ManyToMany(() => member, (member) => member.positions, { diff --git a/entities/member.ts b/entities/member.ts index 334dc7a..38aab93 100644 --- a/entities/member.ts +++ b/entities/member.ts @@ -1,14 +1,26 @@ -import { Column, Entity, JoinTable, ManyToMany, PrimaryColumn, Unique } from "typeorm"; +import { Column, Entity, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany, PrimaryColumn } from "typeorm"; import { executive_position } from "./executive_position"; import { qualification } from "./qualification"; +import { city_district } from "./city_district"; +import { Salutation } from "../enums/salutation"; +import { city } from "./city"; +import { membership } from "./membership"; +import { NewsletterType } from "../enums/newsletter_type"; +import { member_awards } from "./member_awards"; @Entity() export class member { @PrimaryColumn({ generated: "uuid", type: "varchar", length: 36 }) id: string; + @Column({ type: "enum", enum: Salutation, default: Salutation.none }) + salutation: Salutation; + @Column({ type: "varchar", length: 255, unique: true, nullable: true }) - member_id: string; + member_id?: string; + + @Column({ type: "varchar", length: 255, unique: true, nullable: true }) + sepa_mandat?: string; @Column({ type: "varchar", length: 255 }) firstname: string; @@ -25,11 +37,8 @@ export class member { @Column({ type: "varchar", length: 255 }) email: string; - @Column({ type: "varchar", length: 255 }) - postal_code: string; - - @Column({ type: "varchar", length: 255 }) - place: string; + @Column({ type: "varchar", length: 255, nullable: true, default: null }) + official_email?: string; @Column({ type: "varchar", length: 255 }) street: string; @@ -37,18 +46,32 @@ export class member { @Column({ type: "date" }) birthdate: Date; - @Column({ type: "date" }) - accession_date: Date; - @Column({ type: "date", nullable: true, default: null }) - leaving_data: Date; - - @Column({ type: "boolean", default: true }) - active: boolean; + deathdate?: Date; @Column({ type: "boolean", default: false }) push_alert: boolean; + @Column({ type: "enum", enum: NewsletterType, default: NewsletterType.Online }) + newsletter: NewsletterType; + + @OneToMany(() => membership, (membership) => membership.member) + memberships: membership[]; + + @ManyToOne(() => city, (city) => city.members) + @JoinColumn({ + name: "city", + }) + city: city; + + @ManyToOne(() => city_district, (city_district) => city_district.members, { + nullable: true, + }) + @JoinColumn({ + name: "district", + }) + city_district: city_district; + @ManyToMany(() => executive_position, (executive_position) => executive_position.members, { onDelete: "CASCADE", }) @@ -60,4 +83,9 @@ export class member { }) @JoinTable({ name: "member_qualification" }) qualifications: qualification[]; + + @OneToMany(() => member_awards, (awards) => awards.member, { + onDelete: "CASCADE", + }) + awards: member_awards[]; } diff --git a/entities/member_awards.ts b/entities/member_awards.ts new file mode 100644 index 0000000..8a328ff --- /dev/null +++ b/entities/member_awards.ts @@ -0,0 +1,32 @@ +import { Column, Entity, ManyToOne, PrimaryColumn, Unique } from "typeorm"; +import { member } from "./member"; +import { award } from "./award"; + +@Entity() +@Unique(["memberId", "awardId"]) +export class member_awards { + @PrimaryColumn({ type: "varchar", length: 36 }) + memberId: string; + + @PrimaryColumn({ type: "varchar", length: 36 }) + awardId: string; + + @Column({ type: "boolean", default: true }) + given: boolean; + + @Column({ type: "varchar", length: 255, nullable: true, default: null }) + reason?: string; + + @Column({ type: "date" }) + date: Date; + + @ManyToOne(() => member, (member) => member.awards, { + onDelete: "RESTRICT", + }) + member: member; + + @ManyToOne(() => award, (award) => award.members, { + onDelete: "RESTRICT", + }) + award: award; +} diff --git a/entities/membership.ts b/entities/membership.ts new file mode 100644 index 0000000..7722908 --- /dev/null +++ b/entities/membership.ts @@ -0,0 +1,25 @@ +import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm"; +import { member } from "./member"; +import { MembershipType } from "../enums/membership_type"; + +@Entity() +export class membership { + @PrimaryColumn({ generated: "uuid", type: "varchar", length: 36 }) + id: string; + + @Column({ type: "date" }) + start: Date; + + @Column({ type: "date", nullable: true, default: null }) + end?: Date; + + @Column({ type: "enum", enum: MembershipType, default: MembershipType.Active }) + type: MembershipType; + + @Column({ type: "varchar", length: 255, nullable: true }) + reason?: string; + + @ManyToOne(() => member, (member) => member.memberships) + @JoinColumn() + member: member; +} diff --git a/entities/qualification.ts b/entities/qualification.ts index 2c42c70..683a5d7 100644 --- a/entities/qualification.ts +++ b/entities/qualification.ts @@ -9,8 +9,8 @@ export class qualification { @Column({ type: "varchar", length: 255 }) qualification: string; - @Column({ type: "int", default: 1 }) - number_of_performers: string; + @Column({ type: "varchar", length: 255, nullable: true, default: null }) + description?: string; @ManyToMany(() => member, (member) => member.positions, { onDelete: "RESTRICT", diff --git a/enums/membership_type.ts b/enums/membership_type.ts new file mode 100644 index 0000000..d068819 --- /dev/null +++ b/enums/membership_type.ts @@ -0,0 +1,4 @@ +export enum MembershipType { + Active = "active", + Passive = "passive", +} diff --git a/enums/newsletter_type.ts b/enums/newsletter_type.ts new file mode 100644 index 0000000..13ea0a8 --- /dev/null +++ b/enums/newsletter_type.ts @@ -0,0 +1,5 @@ +export enum NewsletterType { + Online = "online", + Offline = "offline", + None = "none", +} diff --git a/enums/salutation.ts b/enums/salutation.ts new file mode 100644 index 0000000..214bb85 --- /dev/null +++ b/enums/salutation.ts @@ -0,0 +1,6 @@ +export enum Salutation { + Sir = "sir", + Madam = "madam", + other = "other", + none = "none", +} diff --git a/index.ts b/index.ts index cc19b4b..2134664 100644 --- a/index.ts +++ b/index.ts @@ -5,5 +5,14 @@ export { dataSource } from "./data-source"; export { member } from "./entities/member"; export { qualification } from "./entities/qualification"; export { executive_position } from "./entities/executive_position"; +export { member_awards } from "./entities/member_awards"; +export { award } from "./entities/award"; +export { city } from "./entities/city"; +export { city_district } from "./entities/city_district"; +export { membership } from "./entities/membership"; export { authentication } from "./entities/authentication"; export { session } from "./entities/session"; + +export { MembershipType } from "./enums/membership_type"; +export { NewsletterType } from "./enums/newsletter_type"; +export { Salutation } from "./enums/salutation"; diff --git a/migrations/1724064152696-split_member.ts b/migrations/1724064152696-split_member.ts new file mode 100644 index 0000000..f62b646 --- /dev/null +++ b/migrations/1724064152696-split_member.ts @@ -0,0 +1,79 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class SplitMember1724064152696 implements MigrationInterface { + name = 'SplitMember1724064152696' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`qualification\` CHANGE \`number_of_performers\` \`description\` int NOT NULL DEFAULT '1'`); + await queryRunner.query(`CREATE TABLE \`city\` (\`id\` varchar(36) NOT NULL, \`postal_code\` varchar(255) NOT NULL, \`city\` varchar(255) NOT NULL, UNIQUE INDEX \`IDX_cc45d5049db48b8d7c0f9cf2b3\` (\`postal_code\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`city_district\` (\`id\` varchar(36) NOT NULL, \`district\` varchar(255) NULL, \`cityId\` varchar(36) NULL, UNIQUE INDEX \`IDX_9c5511a4d64dda3dc96472db53\` (\`district\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`membership\` (\`id\` varchar(36) NOT NULL, \`start\` date NOT NULL, \`end\` date NULL, \`type\` enum ('active', 'passive') NOT NULL DEFAULT 'active', \`reason\` varchar(255) NULL, \`memberId\` varchar(36) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`award\` (\`id\` varchar(36) NOT NULL, \`award\` varchar(255) NOT NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`member_awards\` (\`memberId\` varchar(36) NOT NULL, \`awardId\` varchar(36) NOT NULL, \`given\` tinyint NOT NULL DEFAULT 1, \`reason\` varchar(255) NULL, \`date\` date NOT NULL, UNIQUE INDEX \`IDX_abbbec2c01332355aab3b811c0\` (\`memberId\`, \`awardId\`), PRIMARY KEY (\`memberId\`, \`awardId\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`member\` DROP COLUMN \`postal_code\``); + await queryRunner.query(`ALTER TABLE \`member\` DROP COLUMN \`place\``); + await queryRunner.query(`ALTER TABLE \`member\` DROP COLUMN \`accession_date\``); + await queryRunner.query(`ALTER TABLE \`member\` DROP COLUMN \`leaving_data\``); + await queryRunner.query(`ALTER TABLE \`member\` DROP COLUMN \`active\``); + await queryRunner.query(`ALTER TABLE \`member\` ADD \`salutation\` enum ('sir', 'madam', 'other', 'none') NOT NULL DEFAULT 'none'`); + await queryRunner.query(`ALTER TABLE \`member\` ADD \`sepa_mandat\` varchar(255) NULL`); + await queryRunner.query(`ALTER TABLE \`member\` ADD UNIQUE INDEX \`IDX_ab51d77cababfc4aa052344ec3\` (\`sepa_mandat\`)`); + await queryRunner.query(`ALTER TABLE \`member\` ADD \`official_email\` varchar(255) NULL`); + await queryRunner.query(`ALTER TABLE \`member\` ADD \`deathdate\` date NULL`); + await queryRunner.query(`ALTER TABLE \`member\` ADD \`newsletter\` enum ('online', 'offline', 'none') NOT NULL DEFAULT 'online'`); + await queryRunner.query(`ALTER TABLE \`member\` ADD \`city\` varchar(36) NULL`); + await queryRunner.query(`ALTER TABLE \`member\` ADD \`district\` varchar(36) NULL`); + await queryRunner.query(`ALTER TABLE \`executive_position\` CHANGE \`number_of_performers\` \`number_of_performers\` int NOT NULL DEFAULT '-1'`); + await queryRunner.query(`ALTER TABLE \`qualification\` DROP COLUMN \`description\``); + await queryRunner.query(`ALTER TABLE \`qualification\` ADD \`description\` varchar(255) NULL`); + await queryRunner.query(`ALTER TABLE \`member\` CHANGE \`member_id\` \`member_id\` varchar(255) NULL`); + await queryRunner.query(`ALTER TABLE \`session\` DROP FOREIGN KEY \`FK_1f8d57f74fb4486a743d89d4820\``); + await queryRunner.query(`ALTER TABLE \`session\` CHANGE \`memberId\` \`memberId\` varchar(36) NULL`); + await queryRunner.query(`ALTER TABLE \`city_district\` ADD CONSTRAINT \`FK_7193b3158b46421daeae4a62f95\` FOREIGN KEY (\`cityId\`) REFERENCES \`city\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + 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 \`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`); + await queryRunner.query(`ALTER TABLE \`member\` ADD CONSTRAINT \`FK_cf71c62f17604b8c0e9c15c9556\` FOREIGN KEY (\`city\`) REFERENCES \`city\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`member\` ADD CONSTRAINT \`FK_e74f4be05ffd453b5dfb51d6f79\` FOREIGN KEY (\`district\`) REFERENCES \`city_district\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`session\` ADD CONSTRAINT \`FK_1f8d57f74fb4486a743d89d4820\` FOREIGN KEY (\`memberId\`) REFERENCES \`member\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`session\` DROP FOREIGN KEY \`FK_1f8d57f74fb4486a743d89d4820\``); + await queryRunner.query(`ALTER TABLE \`member\` DROP FOREIGN KEY \`FK_e74f4be05ffd453b5dfb51d6f79\``); + await queryRunner.query(`ALTER TABLE \`member\` DROP FOREIGN KEY \`FK_cf71c62f17604b8c0e9c15c9556\``); + 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 \`membership\` DROP FOREIGN KEY \`FK_3b4b41597707b13086e71727422\``); + await queryRunner.query(`ALTER TABLE \`city_district\` DROP FOREIGN KEY \`FK_7193b3158b46421daeae4a62f95\``); + await queryRunner.query(`ALTER TABLE \`session\` CHANGE \`memberId\` \`memberId\` varchar(36) NULL DEFAULT 'NULL'`); + 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\` CHANGE \`member_id\` \`member_id\` varchar(255) NULL DEFAULT 'NULL'`); + await queryRunner.query(`ALTER TABLE \`qualification\` DROP COLUMN \`description\``); + await queryRunner.query(`ALTER TABLE \`qualification\` ADD \`description\` int NOT NULL DEFAULT '1'`); + await queryRunner.query(`ALTER TABLE \`executive_position\` CHANGE \`number_of_performers\` \`number_of_performers\` int NOT NULL DEFAULT '1'`); + await queryRunner.query(`ALTER TABLE \`member\` DROP COLUMN \`district\``); + await queryRunner.query(`ALTER TABLE \`member\` DROP COLUMN \`city\``); + await queryRunner.query(`ALTER TABLE \`member\` DROP COLUMN \`newsletter\``); + await queryRunner.query(`ALTER TABLE \`member\` DROP COLUMN \`deathdate\``); + await queryRunner.query(`ALTER TABLE \`member\` DROP COLUMN \`official_email\``); + await queryRunner.query(`ALTER TABLE \`member\` DROP INDEX \`IDX_ab51d77cababfc4aa052344ec3\``); + await queryRunner.query(`ALTER TABLE \`member\` DROP COLUMN \`sepa_mandat\``); + await queryRunner.query(`ALTER TABLE \`member\` DROP COLUMN \`salutation\``); + await queryRunner.query(`ALTER TABLE \`member\` ADD \`active\` tinyint NOT NULL DEFAULT '1'`); + await queryRunner.query(`ALTER TABLE \`member\` ADD \`leaving_data\` date NULL DEFAULT 'NULL'`); + await queryRunner.query(`ALTER TABLE \`member\` ADD \`accession_date\` date NOT NULL`); + await queryRunner.query(`ALTER TABLE \`member\` ADD \`place\` varchar(255) NOT NULL`); + await queryRunner.query(`ALTER TABLE \`member\` ADD \`postal_code\` varchar(255) NOT NULL`); + await queryRunner.query(`DROP INDEX \`IDX_abbbec2c01332355aab3b811c0\` ON \`member_awards\``); + await queryRunner.query(`DROP TABLE \`member_awards\``); + await queryRunner.query(`DROP TABLE \`award\``); + await queryRunner.query(`DROP TABLE \`membership\``); + await queryRunner.query(`DROP INDEX \`IDX_9c5511a4d64dda3dc96472db53\` ON \`city_district\``); + await queryRunner.query(`DROP TABLE \`city_district\``); + await queryRunner.query(`DROP INDEX \`IDX_cc45d5049db48b8d7c0f9cf2b3\` ON \`city\``); + await queryRunner.query(`DROP TABLE \`city\``); + await queryRunner.query(`ALTER TABLE \`qualification\` CHANGE \`description\` \`number_of_performers\` int NOT NULL DEFAULT '1'`); + } + +}