//! SeaORM migration: add DND columns to room_member

use sea_orm_migration::prelude::*;

pub struct Migration;

impl MigrationName for Migration {
    fn name(&self) -> &str {
        "m20250628_000078_add_room_member_do_not_disturb"
    }
}

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        let sql = include_str!("sql/m20250628_000078_add_room_member_do_not_disturb.sql");
        super::execute_sql(manager, sql).await
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .get_connection()
            .execute_raw(sea_orm::Statement::from_string(
                sea_orm::DbBackend::Postgres,
                "ALTER TABLE room_member DROP COLUMN IF EXISTS do_not_disturb, \
                     DROP COLUMN IF EXISTS dnd_start_hour, DROP COLUMN IF EXISTS dnd_end_hour;",
            ))
            .await?;
        Ok(())
    }
}
