dev-manager-tauri/src-tauri/src/commands/spaces.rs
lanrtop 412ab8491f
All checks were successful
Push & PR Check / check (push) Successful in 1m23s
Push & PR Check / check (pull_request) Successful in 58s
feat(feature-pruning): 撤销零数据/死代码功能(留撤盘点批次 1)
按「管家准入与退出」撤销实测无使用的功能,台账见 docs/tasks/2026-10-04-feature-pruning.md:
- 项目级工具(project_tools 0 行):删除项目级 command;保留全局快启,
  project_tools.rs/ProjectToolsModal 改名 global_tools.rs/GlobalToolsModal
- 部署命令(deploy_commands 0 行):删除 4 个 command、DeployModal 与「部署配置」按钮;
  删除未编译的 deploy_info.rs 与空壳 DeployInfoPanel
- 宿主机应用(0 行)、项目个人备忘(1 条,表与数据保留)、活动日志与 relations(0 行)
- GitHub 残留:git_accounts 建表与 github_client_* 设置种子;publish.rs 改名 local_git.rs
- 空壳 NetworkPage

数据原则:不 DROP 表、不删已有行,只移除建表语句、两段 FK 迁移与读写代码。
核查后撤回 server_network_config:镜像选择功能在用(ServerSoftwareBlock 调用)。

Rules-Applied: R01,R05
Feature-Confirmed: true

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 20:34:32 +09:00

84 lines
2.7 KiB
Rust

use crate::db;
use crate::models::Space;
use uuid::Uuid;
// ── 空间管理 ────────────────────────────────────────────────
#[tauri::command]
pub fn get_spaces() -> Result<Vec<Space>, String> {
let conn = db::pool().get().map_err(|e| e.to_string())?;
let mut stmt = conn
.prepare("SELECT id, name, is_current, created_at FROM spaces ORDER BY created_at ASC")
.map_err(|e| e.to_string())?;
let rows = stmt
.query_map([], Space::from_row)
.map_err(|e| e.to_string())?;
rows.map(|r| r.map_err(|e| e.to_string())).collect()
}
#[tauri::command]
pub fn create_space(name: String) -> Result<Space, String> {
let conn = db::pool().get().map_err(|e| e.to_string())?;
let id = Uuid::new_v4().to_string();
conn.execute_batch("BEGIN").map_err(|e| e.to_string())?;
let result = (|| -> Result<(), String> {
conn.execute("UPDATE spaces SET is_current = 0", [])
.map_err(|e| e.to_string())?;
// local_root 保留列但填空字符串(历史 NOT NULL 约束)
conn.execute(
"INSERT INTO spaces (id, name, local_root, is_current) VALUES (?1, ?2, '', 1)",
rusqlite::params![id, name],
)
.map_err(|e| e.to_string())?;
Ok(())
})();
if let Err(e) = result {
let _ = conn.execute_batch("ROLLBACK");
return Err(e);
}
conn.execute_batch("COMMIT").map_err(|e| e.to_string())?;
let space = conn
.query_row(
"SELECT id, name, is_current, created_at FROM spaces WHERE id = ?1",
rusqlite::params![id],
Space::from_row,
)
.map_err(|e| e.to_string())?;
Ok(space)
}
#[tauri::command]
pub fn update_space(id: String, name: String) -> Result<(), String> {
let conn = db::pool().get().map_err(|e| e.to_string())?;
conn.execute(
"UPDATE spaces SET name = ?1 WHERE id = ?2",
rusqlite::params![name, id],
)
.map_err(|e| e.to_string())?;
Ok(())
}
#[tauri::command]
pub fn delete_space(id: String) -> Result<(), String> {
let conn = db::pool().get().map_err(|e| e.to_string())?;
conn.execute("DELETE FROM spaces WHERE id = ?1", rusqlite::params![id])
.map_err(|e| e.to_string())?;
Ok(())
}
#[tauri::command]
pub fn set_current_space(id: String) -> Result<(), String> {
let conn = db::pool().get().map_err(|e| e.to_string())?;
conn.execute("UPDATE spaces SET is_current = 0", [])
.map_err(|e| e.to_string())?;
conn.execute(
"UPDATE spaces SET is_current = 1 WHERE id = ?1",
rusqlite::params![id],
)
.map_err(|e| e.to_string())?;
Ok(())
}