#[cfg(test)]
mod tests {
    use dbnexus::{DbPool, migration::executor::MigrationExecutor};
    use dbnexus::migration::sql_reverser::SqlReverser;

    #[tokio::test]
    async fn test_rollback_with_generated_sql() {
        let pool = DbPool::new("sqlite::memory:").await.unwrap();
        let mut executor = MigrationExecutor::new(pool.connection().clone(), dbnexus::config::DatabaseType::Sqlite).await.unwrap();

        // 创建测试表
        executor.execute_raw("CREATE TABLE test_rollback (id INTEGER PRIMARY KEY, name TEXT);").await.unwrap();

        // 验证表存在
        let result = executor.execute_raw("SELECT COUNT(*) FROM test_rollback;").await.unwrap();
        assert!(result.rows_affected() > 0);

        // 执行迁移（添加到历史记录）
        use dbnexus::migration::schema::MigrationRecord;
        executor.history.applied_migrations.push(MigrationRecord {
            version: 1,
            description: "test migration".to_string(),
            file_path: None,
            applied_at: chrono::Utc::now(),
            up_sql: "CREATE TABLE test_rollback (id INTEGER PRIMARY KEY, name TEXT);".to_string(),
            down_sql: None,
        });

        // 回滚（应该执行实际的 DROP TABLE）
        let reverser = SqlReverser::new();
        let down_sql = reverser.reverse("CREATE TABLE test_rollback (id INTEGER PRIMARY KEY, name TEXT);").unwrap();
        println!("Generated down SQL: {}", down_sql);
        
        // 验证生成的 SQL 包含 DROP TABLE
        assert!(down_sql.contains("DROP TABLE"));

        // 执行回滚
        executor.rollback_migration(1).await.unwrap();

        // 验证表已删除
        let result = executor.execute_raw("SELECT COUNT(*) FROM test_rollback;").await;
        assert!(result.is_err(), "Table should not exist after rollback");
    }
}