split member

This commit is contained in:
Julian Krauser 2024-08-19 12:47:10 +02:00
parent c54f046e86
commit 466e5933c0
14 changed files with 286 additions and 19 deletions

View file

@ -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: [],

16
entities/award.ts Normal file
View file

@ -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[];
}

25
entities/city.ts Normal file
View file

@ -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[];
}

21
entities/city_district.ts Normal file
View file

@ -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[];
}

View file

@ -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, {

View file

@ -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[];
}

32
entities/member_awards.ts Normal file
View file

@ -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;
}

25
entities/membership.ts Normal file
View file

@ -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;
}

View file

@ -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",

4
enums/membership_type.ts Normal file
View file

@ -0,0 +1,4 @@
export enum MembershipType {
Active = "active",
Passive = "passive",
}

5
enums/newsletter_type.ts Normal file
View file

@ -0,0 +1,5 @@
export enum NewsletterType {
Online = "online",
Offline = "offline",
None = "none",
}

6
enums/salutation.ts Normal file
View file

@ -0,0 +1,6 @@
export enum Salutation {
Sir = "sir",
Madam = "madam",
other = "other",
none = "none",
}

View file

@ -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";

View file

@ -0,0 +1,79 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class SplitMember1724064152696 implements MigrationInterface {
name = 'SplitMember1724064152696'
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
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'`);
}
}