communication update (breaking schema - clear database before use)

This commit is contained in:
Julian Krauser 2024-08-21 14:13:39 +02:00
parent 837b67e648
commit cc3975978a
21 changed files with 248 additions and 307 deletions

View file

@ -1,18 +1,17 @@
import "dotenv/config";
import "reflect-metadata";
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 { communication } from "./entities/communication";
import { executive_position } from "./entities/executive_position";
import { member_awards } from "./entities/member_awards";
import { member_executive_positions } from "./entities/member_executive_positions";
import { member_qualifications } from "./entities/member_qualifications";
import { member } from "./entities/member";
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";
import { membership_status } from "./entities/membership_status";
import { qualification } from "./entities/qualification";
import { Initial1724242210553 } from "./migrations/1724242210553-initial";
const dataSource = new DataSource({
type: "mysql",
@ -25,18 +24,18 @@ const dataSource = new DataSource({
logging: process.env.NODE_ENV ? true : ["schema", "error", "warn", "log", "migration"],
bigNumberStrings: false,
entities: [
member,
executive_position,
qualification,
member_awards,
award,
city,
city_district,
communication,
executive_position,
member_awards,
member_executive_positions,
member_qualifications,
member,
membership,
authentication,
session,
membership_status,
qualification,
],
migrations: [Initial1723905344553, SplitMember1724064152696],
migrations: [Initial1724242210553],
migrationsRun: true,
migrationsTransactionMode: "each",
subscribers: [],

View file

@ -1,10 +0,0 @@
import { Column, Entity, PrimaryColumn } from "typeorm";
@Entity()
export class authentication {
@PrimaryColumn({ type: "varchar", length: 36 })
username: string;
@Column({ type: "varchar", length: 255 })
secret: string;
}

View file

@ -3,8 +3,8 @@ import { member_awards } from "./member_awards";
@Entity()
export class award {
@PrimaryColumn({ generated: "uuid", type: "varchar", length: 36 })
id: string;
@PrimaryColumn({ generated: "increment", type: "int" })
id: number;
@Column({ type: "varchar", length: 255 })
award: string;

View file

@ -1,25 +0,0 @@
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[];
}

View file

@ -1,21 +0,0 @@
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[];
}

38
entities/communication.ts Normal file
View file

@ -0,0 +1,38 @@
import { Column, Entity, ManyToOne, PrimaryColumn } from "typeorm";
import { member } from "./member";
import { CommunicationType } from "../enums/membership_type";
@Entity()
export class communication {
@PrimaryColumn({ generated: "increment", type: "int" })
id: number;
@Column({ type: "enum", enum: CommunicationType, default: CommunicationType.Phone })
type: CommunicationType;
@Column({ type: "boolean", default: false })
preffered: boolean;
@Column({ type: "varchar", length: 255 })
mobile: string;
@Column({ type: "varchar", length: 255 })
email: string;
@Column({ type: "varchar", length: 255 })
city: string;
@Column({ type: "varchar", length: 255 })
street: string;
@Column({ type: "integer" })
streetnumber: number;
@Column({ type: "varchar", length: 255 })
streetnumber_addition: string;
@ManyToOne(() => member, (member) => member.awards, {
onDelete: "RESTRICT",
})
member: member;
}

View file

@ -1,10 +1,10 @@
import { Column, Entity, ManyToMany, PrimaryColumn } from "typeorm";
import { member } from "./member";
import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm";
import { member_executive_positions } from "./member_executive_positions";
@Entity()
export class executive_position {
@PrimaryColumn({ generated: "uuid", type: "varchar", length: 36 })
id: string;
@PrimaryColumn({ generated: "increment", type: "int" })
id: number;
@Column({ type: "varchar", length: 255 })
postition: string;
@ -12,8 +12,12 @@ export class executive_position {
@Column({ type: "int", default: -1 })
number_of_performers: string;
@ManyToMany(() => member, (member) => member.positions, {
onDelete: "RESTRICT",
})
members: member[];
@OneToMany(
() => member_executive_positions,
(member_executive_positions) => member_executive_positions.executive_position,
{
onDelete: "RESTRICT",
}
)
members: member_executive_positions[];
}

View file

@ -1,26 +1,21 @@
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 { Column, Entity, ManyToOne, OneToMany, OneToOne, PrimaryColumn } from "typeorm";
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";
import { member_qualifications } from "./member_qualifications";
import { member_executive_positions } from "./member_executive_positions";
import { communication } from "./communication";
@Entity()
export class member {
@PrimaryColumn({ generated: "uuid", type: "varchar", length: 36 })
id: string;
@Column({ type: "enum", enum: Salutation, default: Salutation.none })
salutation: Salutation;
@PrimaryColumn({ generated: "increment", type: "int" })
id: number;
@Column({ type: "varchar", length: 255, unique: true, nullable: true })
member_id?: string;
@Column({ type: "varchar", length: 255, unique: true, nullable: true })
sepa_mandat?: string;
@Column({ type: "enum", enum: Salutation, default: Salutation.none })
salutation: Salutation;
@Column({ type: "varchar", length: 255 })
firstname: string;
@ -29,19 +24,7 @@ export class member {
lastname: string;
@Column({ type: "varchar", length: 255 })
phone: string;
@Column({ type: "varchar", length: 255 })
mobile: string;
@Column({ type: "varchar", length: 255 })
email: string;
@Column({ type: "varchar", length: 255, nullable: true, default: null })
official_email?: string;
@Column({ type: "varchar", length: 255 })
street: string;
nameaffix: string;
@Column({ type: "date" })
birthdate: Date;
@ -49,40 +32,29 @@ export class member {
@Column({ type: "date", nullable: true, default: null })
deathdate?: Date;
@Column({ type: "boolean", default: false })
push_alert: boolean;
@Column({ type: "varchar", length: 255, unique: true, nullable: true })
sepa_mandat?: string;
@Column({ type: "enum", enum: NewsletterType, default: NewsletterType.Online })
newsletter: NewsletterType;
@ManyToOne(() => communication, (member_communications) => member_communications.member)
communications: communication;
@OneToOne(() => communication, {
nullable: true,
})
sendNewsletter: communication;
@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, {
@OneToMany(() => member_executive_positions, (member_executive_positions) => member_executive_positions.member, {
onDelete: "CASCADE",
})
@JoinTable({ name: "member_executive_position" })
positions: executive_position[];
positions: member_executive_positions[];
@ManyToMany(() => qualification, (qualification) => qualification.members, {
@OneToMany(() => member_qualifications, (qualification) => qualification.member, {
onDelete: "CASCADE",
})
@JoinTable({ name: "member_qualification" })
qualifications: qualification[];
qualifications: member_qualifications[];
@OneToMany(() => member_awards, (awards) => awards.member, {
onDelete: "CASCADE",

View file

@ -1,21 +1,17 @@
import { Column, Entity, ManyToOne, PrimaryColumn, Unique } from "typeorm";
import { Column, Entity, ManyToOne, PrimaryColumn } 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;
@PrimaryColumn({ generated: "increment", type: "int" })
id: number;
@Column({ type: "boolean", default: true })
given: boolean;
@Column({ type: "varchar", length: 255, nullable: true, default: null })
reason?: string;
note?: string;
@Column({ type: "date" })
date: Date;

View file

@ -0,0 +1,28 @@
import { Column, Entity, ManyToOne, PrimaryColumn } from "typeorm";
import { member } from "./member";
import { executive_position } from "./executive_position";
@Entity()
export class member_executive_positions {
@PrimaryColumn({ generated: "increment", type: "int" })
id: number;
@Column({ type: "boolean", default: true })
given: boolean;
@Column({ type: "varchar", length: 255, nullable: true, default: null })
note?: string;
@Column({ type: "date" })
date: Date;
@ManyToOne(() => member, (member) => member.awards, {
onDelete: "RESTRICT",
})
member: member;
@ManyToOne(() => executive_position, (executive_position) => executive_position.members, {
onDelete: "RESTRICT",
})
executive_position: executive_position;
}

View file

@ -0,0 +1,28 @@
import { Column, Entity, ManyToOne, PrimaryColumn } from "typeorm";
import { member } from "./member";
import { qualification } from "./qualification";
@Entity()
export class member_qualifications {
@PrimaryColumn({ generated: "increment", type: "int" })
id: number;
@Column({ type: "boolean", default: true })
given: boolean;
@Column({ type: "varchar", length: 255, nullable: true, default: null })
note?: string;
@Column({ type: "date" })
date: Date;
@ManyToOne(() => member, (member) => member.awards, {
onDelete: "RESTRICT",
})
member: member;
@ManyToOne(() => qualification, (qualification) => qualification.members, {
onDelete: "RESTRICT",
})
qualification: qualification;
}

View file

@ -1,11 +1,11 @@
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm";
import { member } from "./member";
import { MembershipType } from "../enums/membership_type";
import { membership_status } from "./membership_status";
@Entity()
export class membership {
@PrimaryColumn({ generated: "uuid", type: "varchar", length: 36 })
id: string;
@PrimaryColumn({ generated: "increment", type: "int" })
id: number;
@Column({ type: "date" })
start: Date;
@ -13,13 +13,14 @@ export class membership {
@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;
termination_reason?: string;
@ManyToOne(() => member, (member) => member.memberships)
@JoinColumn()
member: member;
@ManyToOne(() => membership_status, (membership_status) => membership_status.memberships)
@JoinColumn()
status: membership_status;
}

View file

@ -0,0 +1,14 @@
import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm";
import { membership } from "./membership";
@Entity()
export class membership_status {
@PrimaryColumn({ generated: "increment", type: "int" })
id: number;
@Column({ type: "varchar", length: 255, nullable: true })
status: string;
@OneToMany(() => membership, (membership) => membership.status)
memberships: membership[];
}

View file

@ -1,10 +1,10 @@
import { Column, Entity, ManyToMany, PrimaryColumn } from "typeorm";
import { member } from "./member";
import { Column, Entity, OneToMany, PrimaryColumn } from "typeorm";
import { member_qualifications } from "./member_qualifications";
@Entity()
export class qualification {
@PrimaryColumn({ generated: "uuid", type: "varchar", length: 36 })
id: string;
@PrimaryColumn({ generated: "increment", type: "int" })
id: number;
@Column({ type: "varchar", length: 255 })
qualification: string;
@ -12,8 +12,8 @@ export class qualification {
@Column({ type: "varchar", length: 255, nullable: true, default: null })
description?: string;
@ManyToMany(() => member, (member) => member.positions, {
@OneToMany(() => member_qualifications, (member_qualifications) => member_qualifications.qualification, {
onDelete: "RESTRICT",
})
members: member[];
members: member_qualifications[];
}

View file

@ -1,14 +0,0 @@
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm";
import { member } from "./member";
@Entity()
export class session {
@PrimaryColumn({ type: "varchar", length: 36 })
accessToken: string;
@Column({ type: "datetime" })
expiration: Date;
@ManyToOne(() => member)
member: member;
}

View file

@ -1,4 +1,7 @@
export enum MembershipType {
Active = "active",
Passive = "passive",
export enum CommunicationType {
Phone = "phone",
Mobile = "mobile",
Address = "address",
Mail = "mail",
InternalMail = "internalMail",
}

View file

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

View file

@ -2,17 +2,16 @@ import "dotenv/config";
import "reflect-metadata";
export { dataSource } from "./data-source";
export { member } from "./entities/member";
export { qualification } from "./entities/qualification";
export { award } from "./entities/award";
export { communication } from "./entities/communication";
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 { member_executive_positions } from "./entities/member_executive_positions";
export { member_qualifications } from "./entities/member_qualifications";
export { member } from "./entities/member";
export { membership } from "./entities/membership";
export { authentication } from "./entities/authentication";
export { session } from "./entities/session";
export { membership_status } from "./entities/membership_status";
export { qualification } from "./entities/qualification";
export { MembershipType } from "./enums/membership_type";
export { NewsletterType } from "./enums/newsletter_type";
export { CommunicationType } from "./enums/membership_type";
export { Salutation } from "./enums/salutation";

View file

@ -1,41 +0,0 @@
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\``);
}
}

View file

@ -1,79 +0,0 @@
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'`);
}
}

View file

@ -0,0 +1,54 @@
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\``);
}
}