import { MigrationInterface, QueryRunner } from "typeorm";

export class Migrations1771490007536 implements MigrationInterface {
    name = 'Migrations1771490007536'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE TYPE "public"."user_notification_preferences_channel_enum" AS ENUM('whatsapp_notification', 'email_notification', 'notification')`);
        await queryRunner.query(`CREATE TABLE "user_notification_preferences" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "channel" "public"."user_notification_preferences_channel_enum" NOT NULL, "is_enabled" boolean NOT NULL DEFAULT true, "enabled_types" jsonb NOT NULL DEFAULT '[]', "created_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "updated_at" TIMESTAMP(0) NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP(0), "user_id" uuid, CONSTRAINT "PK_2b30dfc697b16f75a55be54d464" PRIMARY KEY ("id"))`);
        await queryRunner.query(`ALTER TABLE "user_notification_preferences" ADD CONSTRAINT "FK_816517663cdb51e17cd20947556" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "user_notification_preferences" DROP CONSTRAINT "FK_816517663cdb51e17cd20947556"`);
        await queryRunner.query(`DROP TABLE "user_notification_preferences"`);
        await queryRunner.query(`DROP TYPE "public"."user_notification_preferences_channel_enum"`);
    }

}
