import { MigrationInterface, QueryRunner } from "typeorm";

export class Migrations1732516475425 implements MigrationInterface {
    name = 'Migrations1732516475425'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE TYPE "public"."plans_interval_enum" AS ENUM('monthly', 'yearly')`);
        await queryRunner.query(`CREATE TABLE "plans" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "name" character varying(255) NOT NULL, "slug" character varying(255) NOT NULL, "description" text, "plan_type" character varying(50) NOT NULL, "product_id" character varying(255), "price_id" character varying(255), "product_response" jsonb, "price_response" jsonb, "currency" character varying(10) NOT NULL, "amount" numeric(10,2) NOT NULL DEFAULT '0', "interval" "public"."plans_interval_enum" NOT NULL DEFAULT 'monthly', "status" boolean NOT NULL DEFAULT true, "created_by" uuid, "updated_by" uuid, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_e7b71bb444e74ee067df057397e" UNIQUE ("slug"), CONSTRAINT "PK_3720521a81c7c24fe9b7202ba61" PRIMARY KEY ("id")); COMMENT ON COLUMN "plans"."plan_type" IS 'Free,Primium'`);
        await queryRunner.query(`CREATE TABLE "plan_permissions" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "plan_id" uuid NOT NULL, "feature_name" character varying(255) NOT NULL, "description" text, "type" character varying(255) NOT NULL, "limits" integer, "time_period" character varying(50), "comparison_operators" character varying(10), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_61b666b1e9c1e47013b3ea847fb" PRIMARY KEY ("id"))`);
        await queryRunner.query(`ALTER TABLE "plan_permissions" ADD CONSTRAINT "FK_36549acf496ef5f01d8422b60ed" FOREIGN KEY ("plan_id") REFERENCES "plans"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "plan_permissions" DROP CONSTRAINT "FK_36549acf496ef5f01d8422b60ed"`);
        await queryRunner.query(`DROP TABLE "plan_permissions"`);
        await queryRunner.query(`DROP TABLE "plans"`);
        await queryRunner.query(`DROP TYPE "public"."plans_interval_enum"`);
    }

}
