/* eslint-disable max-len */ // eslint-disable-next-line @typescript-eslint/consistent-type-imports import { MigrationInterface, QueryRunner } from 'typeorm'; export class MonthlyRecordCron1698857362506 implements MigrationInterface { name = 'MonthlyRecordCron1698857362506'; public async up(queryRunner: QueryRunner): Promise<void> { await queryRunner.query( `ALTER TABLE "incentive_records" DROP CONSTRAINT "incentive_record_employee"`, ); await queryRunner.query( `ALTER TABLE "incentive_records" DROP CONSTRAINT "incentiveSetting"`, ); await queryRunner.query( `CREATE TABLE "monthly_records" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), "rest_day_wages" numeric(20,6) NOT NULL DEFAULT '0', "advance" numeric(20,6) NOT NULL DEFAULT '0', "unpaid_leave" numeric(20,6) NOT NULL DEFAULT '0', "cleaning_fee" numeric(20,6) NOT NULL DEFAULT '0', "deduct" numeric(20,6) NOT NULL DEFAULT '0', "addition" numeric(20,6) NOT NULL DEFAULT '0', "date" TIMESTAMP NOT NULL, "employee_id" uuid, CONSTRAINT "PK_dd50aef519934a7f265f91f8eee" PRIMARY KEY ("id"))`, ); await queryRunner.query( `ALTER TABLE "ot_settings" ALTER COLUMN "extra_rate_per" SET DEFAULT '1.5'`, ); await queryRunner.query( `ALTER TABLE "incentive_records" ADD CONSTRAINT "incentive_record_employee" FOREIGN KEY ("employee_id") REFERENCES "employees"("id") ON DELETE NO ACTION ON UPDATE CASCADE`, ); await queryRunner.query( `ALTER TABLE "incentive_records" ADD CONSTRAINT "incentiveSetting" FOREIGN KEY ("incentive_setting_id") REFERENCES "incentive_settings"("id") ON DELETE NO ACTION ON UPDATE CASCADE`, ); await queryRunner.query( `ALTER TABLE "monthly_records" ADD CONSTRAINT "incentive_record_employee" FOREIGN KEY ("employee_id") REFERENCES "employees"("id") ON DELETE NO ACTION ON UPDATE CASCADE`, ); } public async down(queryRunner: QueryRunner): Promise<void> { await queryRunner.query( `ALTER TABLE "monthly_records" DROP CONSTRAINT "incentive_record_employee"`, ); await queryRunner.query( `ALTER TABLE "incentive_records" DROP CONSTRAINT "incentiveSetting"`, ); await queryRunner.query( `ALTER TABLE "incentive_records" DROP CONSTRAINT "incentive_record_employee"`, ); await queryRunner.query( `ALTER TABLE "ot_settings" ALTER COLUMN "extra_rate_per" SET DEFAULT 1.5`, ); await queryRunner.query(`DROP TABLE "monthly_records"`); await queryRunner.query( `ALTER TABLE "incentive_records" ADD CONSTRAINT "incentiveSetting" FOREIGN KEY ("incentive_setting_id") REFERENCES "incentive_settings"("id") ON DELETE CASCADE ON UPDATE CASCADE`, ); await queryRunner.query( `ALTER TABLE "incentive_records" ADD CONSTRAINT "incentive_record_employee" FOREIGN KEY ("employee_id") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE`, ); } }