import { MigrationInterface, QueryRunner } from "typeorm"

export class CreateProjectsTable1762409903592 implements MigrationInterface {
  name = "CreateProjectsTable1762409903592"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "projects" ("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, "client_id" integer, "name" character varying(255) NOT NULL, "budget" numeric(12,2) NOT NULL, "remaining_budget" numeric(12,2) NOT NULL, "status" character varying(255) NOT NULL DEFAULT 'Planning', "address" text, "description" text, CONSTRAINT "PK_6271df0a7aed1d6c0691ce6ac50" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "projects" ADD CONSTRAINT "FK_c8708288b8e6a060ed7b9e1a226" FOREIGN KEY ("company_id") REFERENCES "companies"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "projects" ADD CONSTRAINT "FK_ca29f959102228649e714827478" FOREIGN KEY ("client_id") REFERENCES "clients"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "projects" DROP CONSTRAINT "FK_ca29f959102228649e714827478"`,
    )
    await queryRunner.query(
      `ALTER TABLE "projects" DROP CONSTRAINT "FK_c8708288b8e6a060ed7b9e1a226"`,
    )
    await queryRunner.query(`DROP TABLE "projects"`)
  }
}
