import { MigrationInterface, QueryRunner } from "typeorm"

export class AddCustomerLoginEntity1758521762493 implements MigrationInterface {
  name = "AddCustomerLoginEntity1758521762493"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "customer_access_tokens" ("id" SERIAL NOT NULL, "customer_id" integer NOT NULL, "device_id" character varying, "device_token" character varying, "device_type" character varying, "os_version" character varying, "access_token" character varying NOT NULL, "access_token_expire_at" TIMESTAMP NOT NULL, "refresh_token" character varying, "refresh_token_expire_at" TIMESTAMP, "fcm_token" character varying, "deleted_at" TIMESTAMP, "created_at" TIMESTAMP DEFAULT NOW(), "updated_at" TIMESTAMP DEFAULT NOW(), CONSTRAINT "PK_4541e9d3602c049417c7dce5915" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "customer_access_tokens" ADD CONSTRAINT "FK_9d16dc974c6abf82a9f3c7d9a29" FOREIGN KEY ("customer_id") REFERENCES "customers"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
  }

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