import { MigrationInterface, QueryRunner } from "typeorm"

export class CreateTimeTrackingTable1762950575404 implements MigrationInterface {
  name = "CreateTimeTrackingTable1762950575404"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "time_tracking" ("created_by" integer, "updated_by" integer, "deleted_by" integer, "created_at" TIMESTAMP NOT NULL DEFAULT NOW(), "updated_at" TIMESTAMP NOT NULL DEFAULT NOW(), "deleted_at" TIMESTAMP, "id" SERIAL NOT NULL, "company_id" integer NOT NULL, "employee_id" integer NOT NULL, "project_id" integer NOT NULL, "activity_type_id" integer NOT NULL, "description" text, "start_time" TIMESTAMP NOT NULL, "end_time" TIMESTAMP, "total_minutes" integer, "cost" numeric(10,2), CONSTRAINT "PK_47d84cfac233244d3924cfdac37" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "time_tracking" ADD CONSTRAINT "FK_c0a361c2f733e214261d2cb180e" FOREIGN KEY ("company_id") REFERENCES "companies"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "time_tracking" ADD CONSTRAINT "FK_bb85c97fa2e5b0cc309dabae8ba" FOREIGN KEY ("employee_id") REFERENCES "employees"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "time_tracking" ADD CONSTRAINT "FK_2bd7c5e2edb13ec587111d844ab" FOREIGN KEY ("project_id") REFERENCES "projects"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "time_tracking" ADD CONSTRAINT "FK_0f9723b7bd46fbf0e9b3ea3d534" FOREIGN KEY ("activity_type_id") REFERENCES "activity_types"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "time_tracking" DROP CONSTRAINT "FK_0f9723b7bd46fbf0e9b3ea3d534"`,
    )
    await queryRunner.query(
      `ALTER TABLE "time_tracking" DROP CONSTRAINT "FK_2bd7c5e2edb13ec587111d844ab"`,
    )
    await queryRunner.query(
      `ALTER TABLE "time_tracking" DROP CONSTRAINT "FK_bb85c97fa2e5b0cc309dabae8ba"`,
    )
    await queryRunner.query(
      `ALTER TABLE "time_tracking" DROP CONSTRAINT "FK_c0a361c2f733e214261d2cb180e"`,
    )
    await queryRunner.query(`DROP TABLE "time_tracking"`)
  }
}
