migrate db
This commit is contained in:
parent
12b2a2f1fd
commit
9d8e14b393
7 changed files with 248 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ import {
|
|||
import { CommandType } from "./CommandType";
|
||||
import { CommandSalary } from "./CommandSalary";
|
||||
import { Assign } from "./Assign";
|
||||
import { Workflow } from "./Workflow";
|
||||
|
||||
@Entity("commandSys")
|
||||
export class CommandSys {
|
||||
|
|
@ -75,6 +76,9 @@ export class CommandSys {
|
|||
|
||||
@OneToMany(() => Assign, (assgin) => assgin.commandAssignSys)
|
||||
assgins: Assign[];
|
||||
|
||||
@OneToMany(() => Workflow, (workflow) => workflow.commandSys)
|
||||
workflows: Workflow[];
|
||||
}
|
||||
|
||||
export class CreateCommandSys {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { Position } from "./Position";
|
|||
import { PosDict } from "./PosDict";
|
||||
import { Profile } from "./Profile";
|
||||
import { profile } from "console";
|
||||
import { Workflow } from "./Workflow";
|
||||
|
||||
enum PosLevelAuthority {
|
||||
HEAD = "HEAD",
|
||||
|
|
@ -56,6 +57,9 @@ export class PosLevel extends EntityBase {
|
|||
|
||||
@OneToMany(() => Profile, (profile) => profile.posLevel)
|
||||
profiles: Profile[];
|
||||
|
||||
@OneToMany(() => Workflow, (workflow) => workflow.posLevel)
|
||||
workflows: Workflow[];
|
||||
}
|
||||
|
||||
export class CreatePosLevel {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { PosLevel } from "./PosLevel";
|
|||
import { Position } from "./Position";
|
||||
import { PosDict } from "./PosDict";
|
||||
import { Profile } from "./Profile";
|
||||
import { Workflow } from "./Workflow";
|
||||
|
||||
@Entity("posType")
|
||||
export class PosType extends EntityBase {
|
||||
|
|
@ -34,6 +35,9 @@ export class PosType extends EntityBase {
|
|||
|
||||
@OneToMany(() => Profile, (profile) => profile.posType)
|
||||
profiles: Profile[];
|
||||
|
||||
@OneToMany(() => Workflow, (workflow) => workflow.posType)
|
||||
workflows: Workflow[];
|
||||
}
|
||||
|
||||
export class CreatePosType {
|
||||
|
|
|
|||
46
src/entities/State.ts
Normal file
46
src/entities/State.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { StateOperator } from "./StateOperator";
|
||||
import { Workflow } from "./Workflow";
|
||||
|
||||
@Entity("state")
|
||||
export class State extends EntityBase {
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ชื่อประเภทขั้นตอน",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
name: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ประเภทขั้นตอน",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
type: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ลำดับ",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
order: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 40,
|
||||
comment: "คีย์นอก(FK)ของตาราง workflow",
|
||||
default: null,
|
||||
})
|
||||
workflowId: string;
|
||||
|
||||
@ManyToOne(() => Workflow, (workflow) => workflow.states)
|
||||
@JoinColumn({ name: "workflowId" })
|
||||
workflow: Workflow;
|
||||
|
||||
@OneToMany(() => StateOperator, (stateOperator) => stateOperator.state)
|
||||
stateOperators: StateOperator[];
|
||||
}
|
||||
74
src/entities/StateOperator.ts
Normal file
74
src/entities/StateOperator.ts
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { State } from "./State";
|
||||
|
||||
@Entity("stateOperator")
|
||||
export class StateOperator extends EntityBase {
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ผู้ดำเนินการ",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
operator: string;
|
||||
|
||||
@Column({
|
||||
comment: "ดูเอกสาร",
|
||||
default: false,
|
||||
})
|
||||
canView: boolean;
|
||||
|
||||
@Column({
|
||||
comment: "แก้ไขเอกสาร",
|
||||
default: false,
|
||||
})
|
||||
canUpdate: boolean;
|
||||
|
||||
@Column({
|
||||
comment: "ลบเอกสาร",
|
||||
default: false,
|
||||
})
|
||||
canDelete: boolean;
|
||||
|
||||
@Column({
|
||||
comment: "ยกเลิกเอกสาร",
|
||||
default: false,
|
||||
})
|
||||
canCancel: boolean;
|
||||
|
||||
@Column({
|
||||
comment: "ดำเนินการเอกสาร",
|
||||
default: false,
|
||||
})
|
||||
canOperate: boolean;
|
||||
|
||||
@Column({
|
||||
comment: "เปลี่ยนสถานะเอกสาร",
|
||||
default: false,
|
||||
})
|
||||
canChangeState: boolean;
|
||||
|
||||
@Column({
|
||||
comment: "แสดงความเห็นเอกสาร",
|
||||
default: false,
|
||||
})
|
||||
canComment: boolean;
|
||||
|
||||
@Column({
|
||||
comment: "ลงนามอนุมัติ",
|
||||
default: false,
|
||||
})
|
||||
canSign: boolean;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 40,
|
||||
comment: "คีย์นอก(FK)ของตาราง state",
|
||||
default: null,
|
||||
})
|
||||
stateId: string;
|
||||
|
||||
@ManyToOne(() => State, (state) => state.stateOperators)
|
||||
@JoinColumn({ name: "stateId" })
|
||||
state: State;
|
||||
}
|
||||
88
src/entities/Workflow.ts
Normal file
88
src/entities/Workflow.ts
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
import { Entity, Column, OneToMany, ManyToOne, JoinColumn } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { State } from "./State";
|
||||
import { CommandSys } from "./CommandSys";
|
||||
import { PosLevel } from "./PosLevel";
|
||||
import { PosType } from "./PosType";
|
||||
|
||||
@Entity("workflow")
|
||||
export class Workflow extends EntityBase {
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ชื่อ flow",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
name: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ระบบ",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
category: string;
|
||||
|
||||
// @Column({
|
||||
// nullable: true,
|
||||
// comment: "กรุ๊ปเลือด",
|
||||
// length: 255,
|
||||
// default: null,
|
||||
// })
|
||||
// rank: string;
|
||||
|
||||
// @Column({
|
||||
// nullable: true,
|
||||
// comment: "กรุ๊ปเลือด",
|
||||
// length: 255,
|
||||
// default: null,
|
||||
// })
|
||||
// executive: string;
|
||||
|
||||
// @Column({
|
||||
// nullable: true,
|
||||
// comment: "หมวดหมู่ระบบ",
|
||||
// length: 255,
|
||||
// default: null,
|
||||
// })
|
||||
// system: string;
|
||||
|
||||
@OneToMany(() => State, (state) => state.workflow)
|
||||
states: State[];
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 40,
|
||||
comment: "คีย์นอก(FK)ของตาราง commandSys",
|
||||
default: null,
|
||||
})
|
||||
commandSysId: string;
|
||||
|
||||
@ManyToOne(() => CommandSys, (commandSys) => commandSys.workflows)
|
||||
@JoinColumn({ name: "commandSysId" })
|
||||
commandSys: CommandSys;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 40,
|
||||
comment: "คีย์นอก(FK)ของตาราง posLevel",
|
||||
default: null,
|
||||
})
|
||||
posLevelId: string;
|
||||
|
||||
@ManyToOne(() => PosLevel, (posLevel) => posLevel.workflows)
|
||||
@JoinColumn({ name: "posLevelId" })
|
||||
posLevel: PosLevel;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 40,
|
||||
comment: "คีย์นอก(FK)ของตาราง posType",
|
||||
default: null,
|
||||
})
|
||||
posTypeId: string;
|
||||
|
||||
@ManyToOne(() => PosType, (posType) => posType.workflows)
|
||||
@JoinColumn({ name: "posTypeId" })
|
||||
posType: PosType;
|
||||
}
|
||||
28
src/migration/1728399911271-add_table_workflow.ts
Normal file
28
src/migration/1728399911271-add_table_workflow.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AddTableWorkflow1728399911271 implements MigrationInterface {
|
||||
name = 'AddTableWorkflow1728399911271'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`CREATE TABLE \`stateOperator\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`operator\` varchar(255) NULL COMMENT 'ผู้ดำเนินการ', \`canView\` tinyint NOT NULL COMMENT 'ดูเอกสาร' DEFAULT 0, \`canUpdate\` tinyint NOT NULL COMMENT 'แก้ไขเอกสาร' DEFAULT 0, \`canDelete\` tinyint NOT NULL COMMENT 'ลบเอกสาร' DEFAULT 0, \`canCancel\` tinyint NOT NULL COMMENT 'ยกเลิกเอกสาร' DEFAULT 0, \`canOperate\` tinyint NOT NULL COMMENT 'ดำเนินการเอกสาร' DEFAULT 0, \`canChangeState\` tinyint NOT NULL COMMENT 'เปลี่ยนสถานะเอกสาร' DEFAULT 0, \`canComment\` tinyint NOT NULL COMMENT 'แสดงความเห็นเอกสาร' DEFAULT 0, \`canSign\` tinyint NOT NULL COMMENT 'ลงนามอนุมัติ' DEFAULT 0, \`stateId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง state', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`CREATE TABLE \`state\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`name\` varchar(255) NULL COMMENT 'ชื่อประเภทขั้นตอน', \`type\` varchar(255) NULL COMMENT 'ประเภทขั้นตอน', \`order\` varchar(255) NULL COMMENT 'ลำดับ', \`workflowId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง workflow', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`CREATE TABLE \`workflow\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`name\` varchar(255) NULL COMMENT 'ชื่อ flow', \`category\` varchar(255) NULL COMMENT 'ระบบ', \`commandSysId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง commandSys', \`posLevelId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง posLevel', \`posTypeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง posType', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`ALTER TABLE \`stateOperator\` ADD CONSTRAINT \`FK_72292e09e5c83c34016a4b17ce4\` FOREIGN KEY (\`stateId\`) REFERENCES \`state\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE \`state\` ADD CONSTRAINT \`FK_fad8656b57142ed4a41584057a7\` FOREIGN KEY (\`workflowId\`) REFERENCES \`workflow\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE \`workflow\` ADD CONSTRAINT \`FK_248dca7108cc3ba484d7eac2bc2\` FOREIGN KEY (\`commandSysId\`) REFERENCES \`commandSys\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE \`workflow\` ADD CONSTRAINT \`FK_0eadcb967c5bdb18867395b8bf9\` FOREIGN KEY (\`posLevelId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE \`workflow\` ADD CONSTRAINT \`FK_77889a7cde943b64fc28dd06025\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`workflow\` DROP FOREIGN KEY \`FK_77889a7cde943b64fc28dd06025\``);
|
||||
await queryRunner.query(`ALTER TABLE \`workflow\` DROP FOREIGN KEY \`FK_0eadcb967c5bdb18867395b8bf9\``);
|
||||
await queryRunner.query(`ALTER TABLE \`workflow\` DROP FOREIGN KEY \`FK_248dca7108cc3ba484d7eac2bc2\``);
|
||||
await queryRunner.query(`ALTER TABLE \`state\` DROP FOREIGN KEY \`FK_fad8656b57142ed4a41584057a7\``);
|
||||
await queryRunner.query(`ALTER TABLE \`stateOperator\` DROP FOREIGN KEY \`FK_72292e09e5c83c34016a4b17ce4\``);
|
||||
await queryRunner.query(`DROP TABLE \`workflow\``);
|
||||
await queryRunner.query(`DROP TABLE \`state\``);
|
||||
await queryRunner.query(`DROP TABLE \`stateOperator\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue