150 assignable roles should be its own table to prevent limitations on length #158

Merged
Vylpes merged 4 commits from 150-assignable-roles-should-be-its-own-table-to-prevent-limitations-on-length into develop 2022-05-14 14:59:33 +01:00
4 changed files with 43 additions and 2 deletions
Showing only changes of commit a44c6424e3 - Show all commits

View file

@ -7,7 +7,9 @@
"scripts": {
"build": "tsc",
"start": "node ./dist/vylbot",
"test": "jest"
"test": "jest",
"db:up": "typeorm migration:run",
"db:down": "typeorm migration:revert"
},
"repository": {
"type": "git",

18
src/entity/Role.ts Normal file
View file

@ -0,0 +1,18 @@
import { Column, Entity, ManyToOne } from "typeorm";
import BaseEntity from "../contracts/BaseEntity"
import Server from "./Server";
@Entity()
export default class Role extends BaseEntity {
constructor(roleId: string) {
super();
this.RoleId = roleId;
}
@Column()
RoleId: string;
@ManyToOne(() => Server, x => x.Roles)
Server: Server;
}

View file

@ -1,5 +1,6 @@
import { Column, Entity, getConnection, OneToMany } from "typeorm";
import { Entity, OneToMany } from "typeorm";
import BaseEntity from "../contracts/BaseEntity";
import Role from "./Role";
import Setting from "./Setting";
@Entity()
@ -13,7 +14,14 @@ export default class Server extends BaseEntity {
@OneToMany(() => Setting, x => x.Server)
Settings: Setting[];
@OneToMany(() => Role, x => x.Server)
Roles: Role[];
public AddSettingToServer(setting: Setting) {
this.Settings.push(setting);
}
public AddRoleToServer(role: Role) {
this.Roles.push(role);
}
}

View file

@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class migration1652375907691 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
queryRunner.query(`CREATE TABLE role (Id varchar(255), WhenCreated datetime, WhenUpdated datetime, RoleId varchar(255), serverId varchar(255), PRIMARY KEY (Id), FOREIGN KEY (serverId) REFERENCES server(Id))`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
queryRunner.query(`DROP TABLE role`);
}
}