penisularhr / src / database / migrations / 1709049095897-create-admin-config.ts
1709049095897-create-admin-config.ts
Raw
import { type MigrationInterface, type QueryRunner } from 'typeorm';

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

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      // eslint-disable-next-line max-len
      `CREATE TABLE "admin_config" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "rest_day_wages_required_days_in_week" numeric(5,3) NOT NULL DEFAULT '6', "advance_required_days" numeric(5,3) NOT NULL DEFAULT '15', "advance_required_wages" numeric(20,6) NOT NULL DEFAULT '750', "advance_amount" numeric(20,6) NOT NULL DEFAULT '500', "advance_last_execution_date" numeric(5,3) NOT NULL DEFAULT '21', CONSTRAINT "PK_c486270cca36cc6c0ee6cf65f74" PRIMARY KEY ("id"))`,
    );
    await queryRunner.query(
      // eslint-disable-next-line max-len
      `INSERT INTO "admin_config" ("id", "rest_day_wages_required_days_in_week", "advance_required_days", "advance_required_wages", "advance_amount", "advance_last_execution_date") VALUES ('c8cee0ed-b6e7-4e8a-b53a-e100f065d2fa', DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT)`,
    );

    await queryRunner.query(
      `ALTER TABLE "ot_settings" ALTER COLUMN "normal_rate_per" SET DEFAULT '1.5'`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "ot_settings" ALTER COLUMN "normal_rate_per" SET DEFAULT 1.5`,
    );
    await queryRunner.query(`DROP TABLE "admin_config"`);
  }
}