diff --git a/src/entity/communication.ts b/src/entity/communication.ts index fc9aa79..527b685 100644 --- a/src/entity/communication.ts +++ b/src/entity/communication.ts @@ -30,6 +30,8 @@ export class communication { @ManyToOne(() => communicationType, (communicationType) => communicationType.communications, { nullable: false, + onDelete: "RESTRICT", + onUpdate: "RESTRICT", }) type: communicationType; diff --git a/src/entity/qualification.ts b/src/entity/qualification.ts index 59a657c..513a31f 100644 --- a/src/entity/qualification.ts +++ b/src/entity/qualification.ts @@ -9,7 +9,7 @@ export class qualification { @Column({ type: "varchar", length: 255 }) qualification: string; - @Column({ type: "varchar", length: 255, nullable: true, default: null }) + @Column({ type: "varchar", length: 255, nullable: true }) description?: string; @OneToMany(() => memberQualifications, (memberQualifications) => memberQualifications.qualification) diff --git a/src/entity/refresh.ts b/src/entity/refresh.ts index a781197..bf99f21 100644 --- a/src/entity/refresh.ts +++ b/src/entity/refresh.ts @@ -12,6 +12,10 @@ export class refresh { @Column({ type: "datetime" }) expiry: Date; - @ManyToOne(() => user) + @ManyToOne(() => user, { + nullable: false, + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) user: user; } diff --git a/src/entity/role.ts b/src/entity/role.ts index 6a4bac9..87f0049 100644 --- a/src/entity/role.ts +++ b/src/entity/role.ts @@ -10,7 +10,11 @@ export class role { @Column({ type: "varchar", length: 255 }) role: string; - @ManyToMany(() => user, (user) => user.roles) + @ManyToMany(() => user, (user) => user.roles, { + nullable: false, + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) users: user[]; @OneToMany(() => rolePermission, (rolePermission) => rolePermission.role) diff --git a/src/entity/role_permission.ts b/src/entity/role_permission.ts index a723ccc..c1d7d4d 100644 --- a/src/entity/role_permission.ts +++ b/src/entity/role_permission.ts @@ -10,6 +10,10 @@ export class rolePermission { @PrimaryColumn({ type: "varchar", length: 255 }) permission: PermissionString; - @ManyToOne(() => role) + @ManyToOne(() => role, { + nullable: false, + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) role: role; } diff --git a/src/entity/user.ts b/src/entity/user.ts index fd41008..fcb31c6 100644 --- a/src/entity/user.ts +++ b/src/entity/user.ts @@ -22,7 +22,11 @@ export class user { @Column({ type: "varchar", length: 255 }) secret: string; - @ManyToMany(() => role, (role) => role.users) + @ManyToMany(() => role, (role) => role.users, { + nullable: false, + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) @JoinTable({ name: "user_roles", }) diff --git a/src/entity/user_permission.ts b/src/entity/user_permission.ts index 01cb8a6..34e6cf5 100644 --- a/src/entity/user_permission.ts +++ b/src/entity/user_permission.ts @@ -10,6 +10,10 @@ export class userPermission { @PrimaryColumn({ type: "varchar", length: 255 }) permission: PermissionString; - @ManyToOne(() => user) + @ManyToOne(() => user, { + nullable: false, + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) user: user; } diff --git a/src/migrations/1724317398939-initial.ts b/src/migrations/1724317398939-initial.ts index d26bf43..437d5b3 100644 --- a/src/migrations/1724317398939-initial.ts +++ b/src/migrations/1724317398939-initial.ts @@ -8,32 +8,10 @@ export class Initial1724317398939 implements MigrationInterface { new Table({ name: "user", columns: [ - { - name: "id", - type: "int", - isPrimary: true, - isNullable: false, - isGenerated: true, - generationStrategy: "increment", - }, - { - name: "mail", - type: "varchar", - length: "255", - isNullable: false, - }, - { - name: "username", - type: "varchar", - length: "255", - isNullable: false, - }, - { - name: "secret", - type: "varchar", - length: "255", - isNullable: false, - }, + { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "mail", type: "varchar", length: "255", isNullable: false }, + { name: "username", type: "varchar", length: "255", isNullable: false }, + { name: "secret", type: "varchar", length: "255", isNullable: false }, ], }), true @@ -43,30 +21,10 @@ export class Initial1724317398939 implements MigrationInterface { new Table({ name: "refresh", columns: [ - { - name: "id", - type: "int", - isPrimary: true, - isNullable: false, - isGenerated: true, - generationStrategy: "increment", - }, - { - name: "token", - type: "varchar", - length: "255", - isNullable: false, - }, - { - name: "expiry", - type: "datetime", - isNullable: false, - }, - { - name: "userId", - type: "int", - isNullable: true, - }, + { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "token", type: "varchar", length: "255", isNullable: false }, + { name: "expiry", type: "datetime", isNullable: false }, + { name: "userId", type: "int", isNullable: false }, ], }), true @@ -79,6 +37,7 @@ export class Initial1724317398939 implements MigrationInterface { referencedColumnNames: ["id"], referencedTableName: "user", onDelete: "CASCADE", + onUpdate: "RESTRICT", }) ); } diff --git a/src/migrations/1724579024939-invite.ts b/src/migrations/1724579024939-invite.ts index b8f9a9c..03309ac 100644 --- a/src/migrations/1724579024939-invite.ts +++ b/src/migrations/1724579024939-invite.ts @@ -8,43 +8,12 @@ export class Invite1724579024939 implements MigrationInterface { new Table({ name: "invite", columns: [ - { - name: "mail", - type: "varchar", - length: "255", - isPrimary: true, - isNullable: false, - }, - { - name: "token", - type: "varchar", - length: "255", - isNullable: false, - }, - { - name: "username", - type: "varchar", - length: "255", - isNullable: false, - }, - { - name: "firstname", - type: "varchar", - length: "255", - isNullable: false, - }, - { - name: "lastname", - type: "varchar", - length: "255", - isNullable: false, - }, - { - name: "secret", - type: "varchar", - length: "255", - isNullable: false, - }, + { name: "mail", type: "varchar", length: "255", isPrimary: true, isNullable: false }, + { name: "token", type: "varchar", length: "255", isNullable: false }, + { name: "username", type: "varchar", length: "255", isNullable: false }, + { name: "firstname", type: "varchar", length: "255", isNullable: false }, + { name: "lastname", type: "varchar", length: "255", isNullable: false }, + { name: "secret", type: "varchar", length: "255", isNullable: false }, ], }), true diff --git a/src/migrations/1724661484664-permissions.ts b/src/migrations/1724661484664-permissions.ts index fe90b9f..22cc1e8 100644 --- a/src/migrations/1724661484664-permissions.ts +++ b/src/migrations/1724661484664-permissions.ts @@ -15,12 +15,7 @@ export class Permissions1724661484664 implements MigrationInterface { isPrimary: true, isNullable: false, }, - { - name: "userId", - type: "int", - isPrimary: true, - isNullable: false, - }, + { name: "userId", type: "int", isPrimary: true, isNullable: false }, ], }), true @@ -33,6 +28,7 @@ export class Permissions1724661484664 implements MigrationInterface { referencedColumnNames: ["id"], referencedTableName: "user", onDelete: "CASCADE", + onUpdate: "RESTRICT", }) ); } diff --git a/src/migrations/1724771491085-role_permission.ts b/src/migrations/1724771491085-role_permission.ts index d40b148..4d3915f 100644 --- a/src/migrations/1724771491085-role_permission.ts +++ b/src/migrations/1724771491085-role_permission.ts @@ -1,4 +1,4 @@ -import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm"; +import { MigrationInterface, QueryRunner, Table, TableForeignKey, TableIndex } from "typeorm"; export class RolePermission1724771491085 implements MigrationInterface { name = "RolePermission1724771491085"; @@ -8,20 +8,8 @@ export class RolePermission1724771491085 implements MigrationInterface { new Table({ name: "role", columns: [ - { - name: "id", - type: "int", - isPrimary: true, - isNullable: false, - isGenerated: true, - generationStrategy: "increment", - }, - { - name: "role", - type: "varchar", - length: "255", - isNullable: false, - }, + { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "role", type: "varchar", length: "255", isNullable: false }, ], }), true @@ -38,12 +26,7 @@ export class RolePermission1724771491085 implements MigrationInterface { isPrimary: true, isNullable: false, }, - { - name: "roleId", - type: "int", - isPrimary: true, - isNullable: false, - }, + { name: "roleId", type: "int", isPrimary: true, isNullable: false }, ], }), true @@ -55,18 +38,8 @@ export class RolePermission1724771491085 implements MigrationInterface { new Table({ name: "user_roles", columns: [ - { - name: "userId", - type: "int", - isPrimary: true, - isNullable: false, - }, - { - name: "roleId", - type: "int", - isPrimary: true, - isNullable: false, - }, + { name: "userId", type: "int", isPrimary: true, isNullable: false }, + { name: "roleId", type: "int", isPrimary: true, isNullable: false }, ], }), true @@ -79,6 +52,7 @@ export class RolePermission1724771491085 implements MigrationInterface { referencedColumnNames: ["id"], referencedTableName: "role", onDelete: "CASCADE", + onUpdate: "RESTRICT", }) ); @@ -89,6 +63,7 @@ export class RolePermission1724771491085 implements MigrationInterface { referencedColumnNames: ["id"], referencedTableName: "user", onDelete: "CASCADE", + onUpdate: "RESTRICT", }) ); @@ -99,6 +74,21 @@ export class RolePermission1724771491085 implements MigrationInterface { referencedColumnNames: ["id"], referencedTableName: "role", onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) + ); + + await queryRunner.createIndex( + "user_roles", + new TableIndex({ + columnNames: ["userId"], + }) + ); + + await queryRunner.createIndex( + "user_roles", + new TableIndex({ + columnNames: ["roleId"], }) ); } diff --git a/src/migrations/1725435669492-member_base_data.ts b/src/migrations/1725435669492-member_base_data.ts index cc85791..054d85a 100644 --- a/src/migrations/1725435669492-member_base_data.ts +++ b/src/migrations/1725435669492-member_base_data.ts @@ -8,20 +8,8 @@ export class MemberBaseData1725435669492 implements MigrationInterface { new Table({ name: "award", columns: [ - { - name: "id", - type: "int", - isPrimary: true, - isNullable: false, - isGenerated: true, - generationStrategy: "increment", - }, - { - name: "award", - type: "varchar", - length: "255", - isNullable: false, - }, + { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "award", type: "varchar", length: "255", isNullable: false }, ], }), true @@ -31,27 +19,9 @@ export class MemberBaseData1725435669492 implements MigrationInterface { new Table({ name: "communication_type", columns: [ - { - name: "id", - type: "int", - isPrimary: true, - isNullable: false, - isGenerated: true, - generationStrategy: "increment", - }, - { - name: "type", - type: "varchar", - length: "255", - isNullable: false, - }, - { - name: "useColumns", - type: "varchar", - length: "255", - isNullable: false, - default: "''", - }, + { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "type", type: "varchar", length: "255", isNullable: false }, + { name: "useColumns", type: "varchar", length: "255", isNullable: false, default: "''" }, ], }), true @@ -61,60 +31,15 @@ export class MemberBaseData1725435669492 implements MigrationInterface { new Table({ name: "communication", columns: [ - { - name: "id", - type: "int", - isPrimary: true, - isNullable: false, - isGenerated: true, - generationStrategy: "increment", - }, - { - name: "preffered", - type: "tinyint", - isNullable: false, - default: 0, - }, - { - name: "mobile", - type: "varchar", - length: "255", - isNullable: false, - }, - { - name: "email", - type: "varchar", - length: "255", - isNullable: false, - }, - { - name: "city", - type: "varchar", - length: "255", - isNullable: false, - }, - { - name: "street", - type: "varchar", - length: "255", - isNullable: false, - }, - { - name: "streetNumber", - type: "int", - isNullable: false, - }, - { - name: "streetNumberAddition", - type: "varchar", - length: "255", - isNullable: false, - }, - { - name: "typeId", - type: "int", - isNullable: false, - }, + { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "preffered", type: "tinyint", isNullable: false, default: 0 }, + { name: "mobile", type: "varchar", length: "255", isNullable: false }, + { name: "email", type: "varchar", length: "255", isNullable: false }, + { name: "city", type: "varchar", length: "255", isNullable: false }, + { name: "street", type: "varchar", length: "255", isNullable: false }, + { name: "streetNumber", type: "int", isNullable: false }, + { name: "streetNumberAddition", type: "varchar", length: "255", isNullable: false }, + { name: "typeId", type: "int", isNullable: false }, ], }), true @@ -124,20 +49,8 @@ export class MemberBaseData1725435669492 implements MigrationInterface { new Table({ name: "executive_position", columns: [ - { - name: "id", - type: "int", - isPrimary: true, - isNullable: false, - isGenerated: true, - generationStrategy: "increment", - }, - { - name: "position", - type: "varchar", - length: "255", - isNullable: false, - }, + { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "position", type: "varchar", length: "255", isNullable: false }, ], }), true @@ -147,20 +60,8 @@ export class MemberBaseData1725435669492 implements MigrationInterface { new Table({ name: "membership_status", columns: [ - { - name: "id", - type: "int", - isPrimary: true, - isNullable: false, - isGenerated: true, - generationStrategy: "increment", - }, - { - name: "status", - type: "varchar", - length: "255", - isNullable: false, - }, + { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "status", type: "varchar", length: "255", isNullable: false }, ], }), true @@ -170,27 +71,9 @@ export class MemberBaseData1725435669492 implements MigrationInterface { new Table({ name: "qualification", columns: [ - { - name: "id", - type: "int", - isPrimary: true, - isNullable: false, - isGenerated: true, - generationStrategy: "increment", - }, - { - name: "qualification", - type: "varchar", - length: "255", - isNullable: false, - }, - { - name: "description", - type: "varchar", - length: "255", - isNullable: true, - default: null, - }, + { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "qualification", type: "varchar", length: "255", isNullable: false }, + { name: "description", type: "varchar", length: "255", isNullable: true }, ], }), true @@ -203,6 +86,7 @@ export class MemberBaseData1725435669492 implements MigrationInterface { referencedColumnNames: ["id"], referencedTableName: "communication_type", onDelete: "RESTRICT", + onUpdate: "RESTRICT", }) ); }