import { MigrationInterface, QueryRunner } from 'typeorm';

export class addProjectActionsTable1702962802869 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
        create type action_type as enum (
            'task_change'
        );
    `);
    await queryRunner.query(`
        create table project_actions
        (
            id uuid PRIMARY KEY,
            project_id bigint not null,
            asset_id uuid not null,
            initiator_user_id integer not null
                references users
                on update cascade on delete cascade,
            action_type action_type,
            content JSONB,
            created_at timestamptz NOT NULL DEFAULT(NOW()),
            notified_at timestamptz,
            foreign key (project_id, asset_id) references assets(project_id, id) ON UPDATE CASCADE ON DELETE CASCADE
        );
    `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
        delete type action_type;
    `);
    await queryRunner.dropTable(`
        DROP TABLE project_actions;
    `);
  }
}
