import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Store WHO made a contract edit as a name, not just an id. Denormalised on
 * purpose: an audit trail must still read correctly after the user is renamed,
 * deactivated or deleted, and `iam.users` lives outside this module's schema.
 */
export class AddRevisionActorName2920000000000 implements MigrationInterface {
  name = 'AddRevisionActorName2920000000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE freight.contract_document_revisions ADD COLUMN IF NOT EXISTS actor_name varchar(200);`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE freight.contract_document_revisions DROP COLUMN IF EXISTS actor_name;`,
    );
  }
}
