import { MigrationInterface, QueryRunner } from 'typeorm';

export class fixNotificationAssetsTable1705311485274
  implements MigrationInterface
{
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`DROP TABLE public.notification_assets`);
    await queryRunner.query(
      `create table 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,
              user_id int not null,
              viewed_at timestamptz null,
              PRIMARY KEY(user_id, project_id, asset_id, notification_id)
             );`,
    );
  }

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