use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        // 添加 data_scope 列 — 行级数据权限范围
        // 可选值: all, self, department, department_tree
        manager
            .alter_table(
                Table::alter()
                    .table(Alias::new("role_permissions"))
                    .add_column(
                        ColumnDef::new(Alias::new("data_scope"))
                            .string()
                            .not_null()
                            .default("all"),
                    )
                    .to_owned(),
            )
            .await?;
        Ok(())
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .alter_table(
                Table::alter()
                    .table(Alias::new("role_permissions"))
                    .drop_column(Alias::new("data_scope"))
                    .to_owned(),
            )
            .await
    }
}
