import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddRoomMembers1000000000001 implements MigrationInterface {
  name = 'AddRoomMembers1000000000001';

  public async up(queryRunner: QueryRunner): Promise<void> {
    const columns = await queryRunner.query(`PRAGMA table_info("rooms")`) as Array<{ name?: string }>;
    const hasMembersColumn = Array.isArray(columns)
      && columns.some((column) => column.name === 'members');

    if (!hasMembersColumn) {
      await queryRunner.query(`ALTER TABLE "rooms" ADD COLUMN "members" TEXT`);
    }
  }

  public async down(_queryRunner: QueryRunner): Promise<void> {
    // Forward-only migration: SQLite column removal is intentionally omitted.
  }
}
