import { MigrationInterface, QueryRunner } from "typeorm";

export class Migrations1729860453765 implements MigrationInterface {
    name = 'Migrations1729860453765'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE TYPE "public"."social_media_posts_social_type_enum" AS ENUM('youtube', 'facebook', 'instagram', 'tiktok')`);
        await queryRunner.query(`CREATE TABLE "social_media_posts" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "social_type" "public"."social_media_posts_social_type_enum" NOT NULL DEFAULT 'youtube', "title" text NOT NULL DEFAULT '', "description" text NOT NULL DEFAULT '', "image_url" text NOT NULL DEFAULT '', "post_id" text NOT NULL DEFAULT '', "like_count" character varying NOT NULL DEFAULT '0', "comment_count" character varying 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_42e86de89a8229e933617cbe1f8" PRIMARY KEY ("id"))`);
        await queryRunner.query(`ALTER TABLE "social_medias" ADD "follower_count" integer NOT NULL DEFAULT '0'`);
        await queryRunner.query(`ALTER TABLE "social_medias" ADD "following_count" integer NOT NULL DEFAULT '0'`);
        await queryRunner.query(`ALTER TABLE "social_medias" ADD "post_count" integer NOT NULL DEFAULT '0'`);
        await queryRunner.query(`ALTER TABLE "social_media_posts" ADD CONSTRAINT "FK_a71882f851d8deea920cf7d839f" FOREIGN KEY ("users") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "social_media_posts" ADD CONSTRAINT "FK_820fcf26e5ebcddfed69d83c85f" 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 "social_media_posts" DROP CONSTRAINT "FK_820fcf26e5ebcddfed69d83c85f"`);
        await queryRunner.query(`ALTER TABLE "social_media_posts" DROP CONSTRAINT "FK_a71882f851d8deea920cf7d839f"`);
        await queryRunner.query(`ALTER TABLE "social_medias" DROP COLUMN "post_count"`);
        await queryRunner.query(`ALTER TABLE "social_medias" DROP COLUMN "following_count"`);
        await queryRunner.query(`ALTER TABLE "social_medias" DROP COLUMN "follower_count"`);
        await queryRunner.query(`DROP TABLE "social_media_posts"`);
        await queryRunner.query(`DROP TYPE "public"."social_media_posts_social_type_enum"`);
    }

}
