penisularhr / src / database / migrations / 1697712982580-create-user-and-employee.ts
1697712982580-create-user-and-employee.ts
Raw
import { MigrationInterface, QueryRunner } from 'typeorm';

export class CreateUserAndEmployee1697712982580 implements MigrationInterface {
  name = 'CreateUserAndEmployee1697712982580';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TYPE "public"."users_role_enum" AS ENUM('USER', 'ADMIN')`,
    );
    await queryRunner.query(
      `CREATE TABLE "users" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), "name" character varying NOT NULL, "role" "public"."users_role_enum" NOT NULL DEFAULT 'USER', "username" character varying NOT NULL, "password" character varying NOT NULL, CONSTRAINT "UQ_fe0bb3f6520ee0469504521e710" UNIQUE ("username"), CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433" PRIMARY KEY ("id"))`,
    );
    await queryRunner.query(
      `CREATE TABLE "employees" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), "name" character varying NOT NULL, "origin" character varying, "date_join" TIMESTAMP NOT NULL, "date_resign" TIMESTAMP, "basic_salary" numeric(20,6) NOT NULL, "daily_rate" numeric(20,6) NOT NULL, "monthly_allowance" numeric(20,6) NOT NULL DEFAULT '0', "epf_rate" integer NOT NULL DEFAULT '0', "should_deduct_socso" boolean NOT NULL DEFAULT false, CONSTRAINT "UQ_ede58bf474d1eaea7ce27383005" UNIQUE ("name"), CONSTRAINT "PK_b9535a98350d5b26e7eb0c26af4" PRIMARY KEY ("id"))`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`DROP TABLE "employees"`);
    await queryRunner.query(`DROP TABLE "users"`);
    await queryRunner.query(`DROP TYPE "public"."users_role_enum"`);
  }
}