import { MigrationInterface, QueryRunner } from "typeorm";

export class Migrations1741255116174 implements MigrationInterface {
    name = 'Migrations1741255116174'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE TABLE "campaign_categories" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "created_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP(0), "campaign_id" uuid, "category_id" uuid, CONSTRAINT "PK_13c2b95eec882cbd57e2238ff30" PRIMARY KEY ("id"))`);
        await queryRunner.query(`ALTER TABLE "campaigns" ADD "platforms" jsonb`);
        await queryRunner.query(`ALTER TABLE "campaign_categories" ADD CONSTRAINT "FK_6e111ff0890a3ef4aaf0f62c8a8" FOREIGN KEY ("campaign_id") REFERENCES "campaigns"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "campaign_categories" ADD CONSTRAINT "FK_22ac2409f1855281c3b813beee8" FOREIGN KEY ("category_id") REFERENCES "categories"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "campaign_categories" DROP CONSTRAINT "FK_22ac2409f1855281c3b813beee8"`);
        await queryRunner.query(`ALTER TABLE "campaign_categories" DROP CONSTRAINT "FK_6e111ff0890a3ef4aaf0f62c8a8"`);
        await queryRunner.query(`ALTER TABLE "campaigns" DROP COLUMN "platforms"`);
        await queryRunner.query(`DROP TABLE "campaign_categories"`);
    }

}
