migrations relations cleanup and formatting

This commit is contained in:
Julian Krauser 2024-09-14 11:33:13 +02:00
parent 10db9a40f4
commit a0321905ce
12 changed files with 90 additions and 270 deletions

View file

@ -30,6 +30,8 @@ export class communication {
@ManyToOne(() => communicationType, (communicationType) => communicationType.communications, { @ManyToOne(() => communicationType, (communicationType) => communicationType.communications, {
nullable: false, nullable: false,
onDelete: "RESTRICT",
onUpdate: "RESTRICT",
}) })
type: communicationType; type: communicationType;

View file

@ -9,7 +9,7 @@ export class qualification {
@Column({ type: "varchar", length: 255 }) @Column({ type: "varchar", length: 255 })
qualification: string; qualification: string;
@Column({ type: "varchar", length: 255, nullable: true, default: null }) @Column({ type: "varchar", length: 255, nullable: true })
description?: string; description?: string;
@OneToMany(() => memberQualifications, (memberQualifications) => memberQualifications.qualification) @OneToMany(() => memberQualifications, (memberQualifications) => memberQualifications.qualification)

View file

@ -12,6 +12,10 @@ export class refresh {
@Column({ type: "datetime" }) @Column({ type: "datetime" })
expiry: Date; expiry: Date;
@ManyToOne(() => user) @ManyToOne(() => user, {
nullable: false,
onDelete: "CASCADE",
onUpdate: "RESTRICT",
})
user: user; user: user;
} }

View file

@ -10,7 +10,11 @@ export class role {
@Column({ type: "varchar", length: 255 }) @Column({ type: "varchar", length: 255 })
role: string; role: string;
@ManyToMany(() => user, (user) => user.roles) @ManyToMany(() => user, (user) => user.roles, {
nullable: false,
onDelete: "CASCADE",
onUpdate: "RESTRICT",
})
users: user[]; users: user[];
@OneToMany(() => rolePermission, (rolePermission) => rolePermission.role) @OneToMany(() => rolePermission, (rolePermission) => rolePermission.role)

View file

@ -10,6 +10,10 @@ export class rolePermission {
@PrimaryColumn({ type: "varchar", length: 255 }) @PrimaryColumn({ type: "varchar", length: 255 })
permission: PermissionString; permission: PermissionString;
@ManyToOne(() => role) @ManyToOne(() => role, {
nullable: false,
onDelete: "CASCADE",
onUpdate: "RESTRICT",
})
role: role; role: role;
} }

View file

@ -22,7 +22,11 @@ export class user {
@Column({ type: "varchar", length: 255 }) @Column({ type: "varchar", length: 255 })
secret: string; secret: string;
@ManyToMany(() => role, (role) => role.users) @ManyToMany(() => role, (role) => role.users, {
nullable: false,
onDelete: "CASCADE",
onUpdate: "RESTRICT",
})
@JoinTable({ @JoinTable({
name: "user_roles", name: "user_roles",
}) })

View file

@ -10,6 +10,10 @@ export class userPermission {
@PrimaryColumn({ type: "varchar", length: 255 }) @PrimaryColumn({ type: "varchar", length: 255 })
permission: PermissionString; permission: PermissionString;
@ManyToOne(() => user) @ManyToOne(() => user, {
nullable: false,
onDelete: "CASCADE",
onUpdate: "RESTRICT",
})
user: user; user: user;
} }

View file

@ -8,32 +8,10 @@ export class Initial1724317398939 implements MigrationInterface {
new Table({ new Table({
name: "user", name: "user",
columns: [ columns: [
{ { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
name: "id", { name: "mail", type: "varchar", length: "255", isNullable: false },
type: "int", { name: "username", type: "varchar", length: "255", isNullable: false },
isPrimary: true, { name: "secret", type: "varchar", length: "255", isNullable: false },
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,
},
], ],
}), }),
true true
@ -43,30 +21,10 @@ export class Initial1724317398939 implements MigrationInterface {
new Table({ new Table({
name: "refresh", name: "refresh",
columns: [ columns: [
{ { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
name: "id", { name: "token", type: "varchar", length: "255", isNullable: false },
type: "int", { name: "expiry", type: "datetime", isNullable: false },
isPrimary: true, { name: "userId", type: "int", isNullable: false },
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,
},
], ],
}), }),
true true
@ -79,6 +37,7 @@ export class Initial1724317398939 implements MigrationInterface {
referencedColumnNames: ["id"], referencedColumnNames: ["id"],
referencedTableName: "user", referencedTableName: "user",
onDelete: "CASCADE", onDelete: "CASCADE",
onUpdate: "RESTRICT",
}) })
); );
} }

View file

@ -8,43 +8,12 @@ export class Invite1724579024939 implements MigrationInterface {
new Table({ new Table({
name: "invite", name: "invite",
columns: [ columns: [
{ { name: "mail", type: "varchar", length: "255", isPrimary: true, isNullable: false },
name: "mail", { name: "token", type: "varchar", length: "255", isNullable: false },
type: "varchar", { name: "username", type: "varchar", length: "255", isNullable: false },
length: "255", { name: "firstname", type: "varchar", length: "255", isNullable: false },
isPrimary: true, { name: "lastname", type: "varchar", length: "255", isNullable: false },
isNullable: false, { name: "secret", type: "varchar", length: "255", 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 true

View file

@ -15,12 +15,7 @@ export class Permissions1724661484664 implements MigrationInterface {
isPrimary: true, isPrimary: true,
isNullable: false, isNullable: false,
}, },
{ { name: "userId", type: "int", isPrimary: true, isNullable: false },
name: "userId",
type: "int",
isPrimary: true,
isNullable: false,
},
], ],
}), }),
true true
@ -33,6 +28,7 @@ export class Permissions1724661484664 implements MigrationInterface {
referencedColumnNames: ["id"], referencedColumnNames: ["id"],
referencedTableName: "user", referencedTableName: "user",
onDelete: "CASCADE", onDelete: "CASCADE",
onUpdate: "RESTRICT",
}) })
); );
} }

View file

@ -1,4 +1,4 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm"; import { MigrationInterface, QueryRunner, Table, TableForeignKey, TableIndex } from "typeorm";
export class RolePermission1724771491085 implements MigrationInterface { export class RolePermission1724771491085 implements MigrationInterface {
name = "RolePermission1724771491085"; name = "RolePermission1724771491085";
@ -8,20 +8,8 @@ export class RolePermission1724771491085 implements MigrationInterface {
new Table({ new Table({
name: "role", name: "role",
columns: [ columns: [
{ { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
name: "id", { name: "role", type: "varchar", length: "255", isNullable: false },
type: "int",
isPrimary: true,
isNullable: false,
isGenerated: true,
generationStrategy: "increment",
},
{
name: "role",
type: "varchar",
length: "255",
isNullable: false,
},
], ],
}), }),
true true
@ -38,12 +26,7 @@ export class RolePermission1724771491085 implements MigrationInterface {
isPrimary: true, isPrimary: true,
isNullable: false, isNullable: false,
}, },
{ { name: "roleId", type: "int", isPrimary: true, isNullable: false },
name: "roleId",
type: "int",
isPrimary: true,
isNullable: false,
},
], ],
}), }),
true true
@ -55,18 +38,8 @@ export class RolePermission1724771491085 implements MigrationInterface {
new Table({ new Table({
name: "user_roles", name: "user_roles",
columns: [ columns: [
{ { name: "userId", type: "int", isPrimary: true, isNullable: false },
name: "userId", { name: "roleId", type: "int", isPrimary: true, isNullable: false },
type: "int",
isPrimary: true,
isNullable: false,
},
{
name: "roleId",
type: "int",
isPrimary: true,
isNullable: false,
},
], ],
}), }),
true true
@ -79,6 +52,7 @@ export class RolePermission1724771491085 implements MigrationInterface {
referencedColumnNames: ["id"], referencedColumnNames: ["id"],
referencedTableName: "role", referencedTableName: "role",
onDelete: "CASCADE", onDelete: "CASCADE",
onUpdate: "RESTRICT",
}) })
); );
@ -89,6 +63,7 @@ export class RolePermission1724771491085 implements MigrationInterface {
referencedColumnNames: ["id"], referencedColumnNames: ["id"],
referencedTableName: "user", referencedTableName: "user",
onDelete: "CASCADE", onDelete: "CASCADE",
onUpdate: "RESTRICT",
}) })
); );
@ -99,6 +74,21 @@ export class RolePermission1724771491085 implements MigrationInterface {
referencedColumnNames: ["id"], referencedColumnNames: ["id"],
referencedTableName: "role", referencedTableName: "role",
onDelete: "CASCADE", onDelete: "CASCADE",
onUpdate: "RESTRICT",
})
);
await queryRunner.createIndex(
"user_roles",
new TableIndex({
columnNames: ["userId"],
})
);
await queryRunner.createIndex(
"user_roles",
new TableIndex({
columnNames: ["roleId"],
}) })
); );
} }

View file

@ -8,20 +8,8 @@ export class MemberBaseData1725435669492 implements MigrationInterface {
new Table({ new Table({
name: "award", name: "award",
columns: [ columns: [
{ { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
name: "id", { name: "award", type: "varchar", length: "255", isNullable: false },
type: "int",
isPrimary: true,
isNullable: false,
isGenerated: true,
generationStrategy: "increment",
},
{
name: "award",
type: "varchar",
length: "255",
isNullable: false,
},
], ],
}), }),
true true
@ -31,27 +19,9 @@ export class MemberBaseData1725435669492 implements MigrationInterface {
new Table({ new Table({
name: "communication_type", name: "communication_type",
columns: [ columns: [
{ { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
name: "id", { name: "type", type: "varchar", length: "255", isNullable: false },
type: "int", { name: "useColumns", type: "varchar", length: "255", isNullable: false, default: "''" },
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: "''",
},
], ],
}), }),
true true
@ -61,60 +31,15 @@ export class MemberBaseData1725435669492 implements MigrationInterface {
new Table({ new Table({
name: "communication", name: "communication",
columns: [ columns: [
{ { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
name: "id", { name: "preffered", type: "tinyint", isNullable: false, default: 0 },
type: "int", { name: "mobile", type: "varchar", length: "255", isNullable: false },
isPrimary: true, { name: "email", type: "varchar", length: "255", isNullable: false },
isNullable: false, { name: "city", type: "varchar", length: "255", isNullable: false },
isGenerated: true, { name: "street", type: "varchar", length: "255", isNullable: false },
generationStrategy: "increment", { name: "streetNumber", type: "int", isNullable: false },
}, { name: "streetNumberAddition", type: "varchar", length: "255", isNullable: false },
{ { name: "typeId", type: "int", isNullable: false },
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 true
@ -124,20 +49,8 @@ export class MemberBaseData1725435669492 implements MigrationInterface {
new Table({ new Table({
name: "executive_position", name: "executive_position",
columns: [ columns: [
{ { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
name: "id", { name: "position", type: "varchar", length: "255", isNullable: false },
type: "int",
isPrimary: true,
isNullable: false,
isGenerated: true,
generationStrategy: "increment",
},
{
name: "position",
type: "varchar",
length: "255",
isNullable: false,
},
], ],
}), }),
true true
@ -147,20 +60,8 @@ export class MemberBaseData1725435669492 implements MigrationInterface {
new Table({ new Table({
name: "membership_status", name: "membership_status",
columns: [ columns: [
{ { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
name: "id", { name: "status", type: "varchar", length: "255", isNullable: false },
type: "int",
isPrimary: true,
isNullable: false,
isGenerated: true,
generationStrategy: "increment",
},
{
name: "status",
type: "varchar",
length: "255",
isNullable: false,
},
], ],
}), }),
true true
@ -170,27 +71,9 @@ export class MemberBaseData1725435669492 implements MigrationInterface {
new Table({ new Table({
name: "qualification", name: "qualification",
columns: [ columns: [
{ { name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
name: "id", { name: "qualification", type: "varchar", length: "255", isNullable: false },
type: "int", { name: "description", type: "varchar", length: "255", isNullable: true },
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,
},
], ],
}), }),
true true
@ -203,6 +86,7 @@ export class MemberBaseData1725435669492 implements MigrationInterface {
referencedColumnNames: ["id"], referencedColumnNames: ["id"],
referencedTableName: "communication_type", referencedTableName: "communication_type",
onDelete: "RESTRICT", onDelete: "RESTRICT",
onUpdate: "RESTRICT",
}) })
); );
} }