import { MigrationInterface, QueryRunner } from 'typeorm';

export class projectSubscribers1697694465989 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
        create table project_subscribers
        (
            id uuid PRIMARY KEY,
            project_id    bigint  not null
                    references projects
                    on update cascade on delete cascade,
            user_id       integer                                not null
                    references users
                    on update cascade on delete cascade,
            created_at timestamptz NOT NULL DEFAULT(NOW()),
            deleted_At timestamptz
        );
    `);
    await queryRunner.query(`
        CREATE INDEX project_subscribers_users_idx ON project_subscribers(project_id, user_id);
    `);
  }

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