import { MigrationInterface, QueryRunner } from "typeorm";

export class Migrations1738241890546 implements MigrationInterface {
    name = 'Migrations1738241890546'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE TYPE "public"."posts_status_enum" AS ENUM('approved', 'pending', 'rejected')`);
        await queryRunner.query(`CREATE TABLE "posts" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "status" "public"."posts_status_enum" NOT NULL DEFAULT 'pending', "post_link" text, "image_link" text, "created_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP(0), "campaign_id" uuid, "influencerId" uuid, "campaign_influencer_id" uuid, CONSTRAINT "PK_2829ac61eff60fcec60d7274b9e" PRIMARY KEY ("id"))`);
        await queryRunner.query(`ALTER TABLE "posts" ADD CONSTRAINT "FK_bbe21c78558308e29350da0479d" FOREIGN KEY ("campaign_id") REFERENCES "campaigns"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "posts" ADD CONSTRAINT "FK_15d5a0362b3a2dfb44c317b037b" FOREIGN KEY ("influencerId") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "posts" ADD CONSTRAINT "FK_41109ce866117d7a414b174b723" FOREIGN KEY ("campaign_influencer_id") REFERENCES "campaign_influencers"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "posts" DROP CONSTRAINT "FK_41109ce866117d7a414b174b723"`);
        await queryRunner.query(`ALTER TABLE "posts" DROP CONSTRAINT "FK_15d5a0362b3a2dfb44c317b037b"`);
        await queryRunner.query(`ALTER TABLE "posts" DROP CONSTRAINT "FK_bbe21c78558308e29350da0479d"`);
        await queryRunner.query(`DROP TABLE "posts"`);
        await queryRunner.query(`DROP TYPE "public"."posts_status_enum"`);
    }

}
