import { MigrationInterface, QueryRunner } from "typeorm"

export class CretaeNotificationsTable1768208209336 implements MigrationInterface {
  name = "CretaeNotificationsTable1768208209336"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "notifications" ("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, "title" character varying(255) NOT NULL, "description" text NOT NULL, "is_read" smallint NOT NULL DEFAULT '0', "company_id" integer NOT NULL, "employee_id" integer NOT NULL, CONSTRAINT "PK_6a72c3c0f683f6462415e653c3a" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `CREATE TABLE "fcm_tokens" ("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, "fcm_token" text NOT NULL, "company_id" integer NOT NULL, "user_id" integer, "employee_id" integer, CONSTRAINT "PK_0802a779d616597e9330bb9a7cc" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "notifications" ADD CONSTRAINT "FK_c642fb845de2edcae46635863ab" FOREIGN KEY ("company_id") REFERENCES "companies"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "notifications" ADD CONSTRAINT "FK_d59afae1b9c6b8d9a17548e014f" FOREIGN KEY ("employee_id") REFERENCES "employees"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "fcm_tokens" ADD CONSTRAINT "FK_751cffce548738212f7e0518636" FOREIGN KEY ("company_id") REFERENCES "companies"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "fcm_tokens" ADD CONSTRAINT "FK_9fd867cabc75028a5625ce7b24c" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "fcm_tokens" ADD CONSTRAINT "FK_d09319f0103485cea9f616f6de7" FOREIGN KEY ("employee_id") REFERENCES "employees"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "fcm_tokens" DROP CONSTRAINT "FK_d09319f0103485cea9f616f6de7"`,
    )
    await queryRunner.query(
      `ALTER TABLE "fcm_tokens" DROP CONSTRAINT "FK_9fd867cabc75028a5625ce7b24c"`,
    )
    await queryRunner.query(
      `ALTER TABLE "fcm_tokens" DROP CONSTRAINT "FK_751cffce548738212f7e0518636"`,
    )
    await queryRunner.query(
      `ALTER TABLE "notifications" DROP CONSTRAINT "FK_d59afae1b9c6b8d9a17548e014f"`,
    )
    await queryRunner.query(
      `ALTER TABLE "notifications" DROP CONSTRAINT "FK_c642fb845de2edcae46635863ab"`,
    )
    await queryRunner.query(`DROP TABLE "fcm_tokens"`)
    await queryRunner.query(`DROP TABLE "notifications"`)
  }
}
