import { MigrationInterface, QueryRunner } from 'typeorm';

export class createNotificationAssetsTable1705300920652
  implements MigrationInterface
{
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE notifications ADD COLUMN auto_view BOOLEAN DEFAULT false`,
    );
    await queryRunner.query(
      `create table if not exists public.notification_assets (
        notification_id UUID not null
            constraint notification_fkey
                references public.notifications
                on update cascade on delete restrict,
        project_id BIGINT not null
            constraint notification_project_fkey
                references public.projects
                on update cascade on delete restrict,
        asset_id UUID not null,
        viewed_at timestamptz null,
        PRIMARY KEY(notification_id, project_id, asset_id)
       );`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`ALTER TABLE notifications DROP COLUMN auto_view`);
    await queryRunner.query(`DROP TABLE public.notification_assets`);
  }
}
