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

export class ChatMessageReactionIdIdentity1725024956416 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      ALTER TABLE chat_message_reaction ALTER COLUMN id DROP DEFAULT;
      DROP SEQUENCE IF EXISTS chat_message_reaction_id_seq;
      DO $$ 
      DECLARE
          max_id integer;
      BEGIN
          SELECT COALESCE(MAX(id), 0) + 1 INTO max_id FROM chat_message_reaction;
          EXECUTE 'ALTER TABLE chat_message_reaction ALTER COLUMN id SET NOT NULL, ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (START WITH ' || max_id || ')';
      END $$;
    `);
  }

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