import { MigrationInterface, QueryRunner } from "typeorm"

export class CreateCompaniesTable1761734879533 implements MigrationInterface {
  name = "CreateCompaniesTable1761734879533"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      'CREATE TABLE "companies" ("id" SERIAL NOT NULL, "name" character varying NOT NULL, "address_id" integer, "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, CONSTRAINT "PK_d4bc3e82a314fa9e29f652c2c22" PRIMARY KEY ("id"))',
    )
    await queryRunner.query(
      'ALTER TABLE "companies" ADD CONSTRAINT "FK_ca4df9b8772f1c1a02f3a560555" FOREIGN KEY ("created_by") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION',
    )
    await queryRunner.query(
      'ALTER TABLE "companies" ADD CONSTRAINT "FK_9991d25b571eb593c19f4208fae" FOREIGN KEY ("updated_by") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION',
    )
    await queryRunner.query(
      'ALTER TABLE "companies" ADD CONSTRAINT "FK_c3c4235d8af94bc206635fe7cbb" FOREIGN KEY ("deleted_by") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION',
    )
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      'ALTER TABLE "companies" DROP CONSTRAINT "FK_c3c4235d8af94bc206635fe7cbb"',
    )
    await queryRunner.query(
      'ALTER TABLE "companies" DROP CONSTRAINT "FK_9991d25b571eb593c19f4208fae"',
    )
    await queryRunner.query(
      'ALTER TABLE "companies" DROP CONSTRAINT "FK_ca4df9b8772f1c1a02f3a560555"',
    )
    await queryRunner.query('DROP TABLE "companies"')
  }
}
