import { MigrationInterface, QueryRunner } from "typeorm";

export class Migrations1729495284243 implements MigrationInterface {
    name = 'Migrations1729495284243'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE TABLE "instagram_medias" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "caption" character varying NOT NULL DEFAULT '', "username" text NOT NULL DEFAULT '', "thumbnail_url" text NOT NULL DEFAULT '', "media_url" text NOT NULL DEFAULT '', "permalink" text NOT NULL DEFAULT '', "instagram_media_id" text NOT NULL DEFAULT '', "is_comment_enabled" text NOT NULL DEFAULT '', "media_product_type" text NOT NULL DEFAULT '', "media_type" text NOT NULL DEFAULT '', "shortcode" text NOT NULL DEFAULT '', "instagram_timestamp" text NOT NULL DEFAULT '', "comments_count" integer NOT NULL DEFAULT '0', "like_count" integer NOT NULL DEFAULT '0', "created_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP(0), "users" uuid, "socialMedia" uuid, "instagramProfiles" uuid, CONSTRAINT "PK_cacdda56b9a2b6d041aa833e739" PRIMARY KEY ("id"))`);
        await queryRunner.query(`CREATE TABLE "instagram_profiles" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "user_name" character varying NOT NULL DEFAULT '', "description" text NOT NULL DEFAULT '', "name" text NOT NULL DEFAULT '', "instagram_user_id" text NOT NULL DEFAULT '', "profile_picture_url" text NOT NULL DEFAULT '', "phone" text NOT NULL DEFAULT '', "follows_count" integer NOT NULL DEFAULT '0', "media_count" integer NOT NULL DEFAULT '0', "followers_count" integer NOT NULL DEFAULT '0', "created_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP(0), "users" uuid, "socialMedia" uuid, CONSTRAINT "PK_18f221e6b8351a57dbd617b93b3" PRIMARY KEY ("id"))`);
        await queryRunner.query(`ALTER TABLE "instagram_medias" ADD CONSTRAINT "FK_a1f9c3336233c535f11430e2438" FOREIGN KEY ("users") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "instagram_medias" ADD CONSTRAINT "FK_6fd439152977784c9d5c7470c3f" FOREIGN KEY ("socialMedia") REFERENCES "social_medias"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "instagram_medias" ADD CONSTRAINT "FK_4eeef393dc779f812d91f6021e6" FOREIGN KEY ("instagramProfiles") REFERENCES "instagram_profiles"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "instagram_profiles" ADD CONSTRAINT "FK_d20ad6c7e6ea647a1acff7df9ed" FOREIGN KEY ("users") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "instagram_profiles" ADD CONSTRAINT "FK_c8d4ac81d51e8cb7f07b7dccf67" FOREIGN KEY ("socialMedia") REFERENCES "social_medias"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "instagram_profiles" DROP CONSTRAINT "FK_c8d4ac81d51e8cb7f07b7dccf67"`);
        await queryRunner.query(`ALTER TABLE "instagram_profiles" DROP CONSTRAINT "FK_d20ad6c7e6ea647a1acff7df9ed"`);
        await queryRunner.query(`ALTER TABLE "instagram_medias" DROP CONSTRAINT "FK_4eeef393dc779f812d91f6021e6"`);
        await queryRunner.query(`ALTER TABLE "instagram_medias" DROP CONSTRAINT "FK_6fd439152977784c9d5c7470c3f"`);
        await queryRunner.query(`ALTER TABLE "instagram_medias" DROP CONSTRAINT "FK_a1f9c3336233c535f11430e2438"`);
        await queryRunner.query(`DROP TABLE "instagram_profiles"`);
        await queryRunner.query(`DROP TABLE "instagram_medias"`);
    }

}
