import { MigrationInterface, QueryRunner } from "typeorm"

export class AddCurrencyTable1743595037301 implements MigrationInterface {
  name = "AddCurrencyTable1743595037301"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "currencies" ("id" SERIAL NOT NULL, "code" character varying NOT NULL, "country_id" integer NOT NULL, "deleted_at" TIMESTAMP, "created_at" TIMESTAMP NOT NULL DEFAULT NOW(), "updated_at" TIMESTAMP NOT NULL DEFAULT NOW(), CONSTRAINT "UQ_9f8d0972aeeb5a2277e40332d29" UNIQUE ("code"), CONSTRAINT "PK_d528c54860c4182db13548e08c4" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "currencies" ADD CONSTRAINT "FK_8ee6ff98e79c5bc234fba43d617" 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 "currencies" DROP CONSTRAINT "FK_8ee6ff98e79c5bc234fba43d617"`,
    )
    await queryRunner.query(`DROP TABLE "currencies"`)
  }
}
