Add entity
This commit is contained in:
parent
6522bee37b
commit
a44c6424e3
4 changed files with 43 additions and 2 deletions
|
@ -7,7 +7,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"start": "node ./dist/vylbot",
|
"start": "node ./dist/vylbot",
|
||||||
"test": "jest"
|
"test": "jest",
|
||||||
|
"db:up": "typeorm migration:run",
|
||||||
|
"db:down": "typeorm migration:revert"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
18
src/entity/Role.ts
Normal file
18
src/entity/Role.ts
Normal 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;
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
import { Column, Entity, getConnection, OneToMany } from "typeorm";
|
import { Entity, OneToMany } from "typeorm";
|
||||||
import BaseEntity from "../contracts/BaseEntity";
|
import BaseEntity from "../contracts/BaseEntity";
|
||||||
|
import Role from "./Role";
|
||||||
import Setting from "./Setting";
|
import Setting from "./Setting";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
|
@ -13,7 +14,14 @@ export default class Server extends BaseEntity {
|
||||||
@OneToMany(() => Setting, x => x.Server)
|
@OneToMany(() => Setting, x => x.Server)
|
||||||
Settings: Setting[];
|
Settings: Setting[];
|
||||||
|
|
||||||
|
@OneToMany(() => Role, x => x.Server)
|
||||||
|
Roles: Role[];
|
||||||
|
|
||||||
public AddSettingToServer(setting: Setting) {
|
public AddSettingToServer(setting: Setting) {
|
||||||
this.Settings.push(setting);
|
this.Settings.push(setting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AddRoleToServer(role: Role) {
|
||||||
|
this.Roles.push(role);
|
||||||
|
}
|
||||||
}
|
}
|
13
src/migration/1652375907691-CreateRole.ts
Normal file
13
src/migration/1652375907691-CreateRole.ts
Normal 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`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue