import { MigrationInterface, QueryRunner } from "typeorm"

export class AddStateDatabase1743501168349 implements MigrationInterface {
  name = "AddStateDatabase1743501168349"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "states" ("id" SERIAL NOT NULL, "name" character varying NOT NULL, "country_id" integer NOT NULL, CONSTRAINT "UQ_fe52f02449eaf27be2b2cb7acda" UNIQUE ("name"), CONSTRAINT "PK_09ab30ca0975c02656483265f4f" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "states" ADD CONSTRAINT "FK_f3bbd0bc19bb6d8a887add08461" FOREIGN KEY ("country_id") REFERENCES "countries"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
  }

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