/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-empty-function */
import type { MigrationInterface, QueryRunner } from 'typeorm';

export class ChatUserExternal1709805560320 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      create table chat_user_external (
        id integer generated by default as identity,
        account_id integer not null,
        external_id character varying not null,
        first_name character varying,
        last_name character varying,
        avatar_url character varying,
        phone character varying,
        email character varying,
        link character varying,
        primary key (id),
        foreign key (account_id) references account(id) on delete cascade
      );

      delete from chat_user where external_id is not null;

      alter table chat_user
        drop column external_id,
        drop column external_first_name,
        drop column external_last_name,
        drop column external_avatar_url;

      alter table chat_user
        add column external_user_id integer,
        add foreign key (external_user_id) references chat_user_external(id) on delete cascade;
    `);
  }

  public async down(_queryRunner: QueryRunner): Promise<void> {}
}
