mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-19 19:04:23 +08:00
修复 OOBE 建表异常并提升遮罩层内错误提示层级
This commit is contained in:
@@ -4,6 +4,8 @@ use std::sync::Arc;
|
||||
use tauri::State;
|
||||
|
||||
use crate::db::connection::{create_postgres_connection, create_sqlite_connection};
|
||||
use crate::db::connection::DatabaseType;
|
||||
use crate::db::migration::run_migration;
|
||||
use crate::services::permission::PermissionLevel;
|
||||
use crate::state::AppState;
|
||||
|
||||
@@ -119,6 +121,9 @@ pub async fn db_switch_connection(
|
||||
let conn = create_postgres_connection(&connection_string)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
run_migration(&conn, DatabaseType::PostgreSQL)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
let state_guard = state.read();
|
||||
let mut db_guard = state_guard.db.write();
|
||||
@@ -138,6 +143,9 @@ pub async fn db_switch_connection(
|
||||
let conn = create_sqlite_connection(&path)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
run_migration(&conn, DatabaseType::SQLite)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
let state_guard = state.read();
|
||||
let mut db_guard = state_guard.db.write();
|
||||
@@ -189,7 +197,24 @@ pub async fn db_sync(
|
||||
let state_guard = state.read();
|
||||
let db_guard = state_guard.db.read();
|
||||
if let Some(conn) = db_guard.as_ref() {
|
||||
match conn.ping().await {
|
||||
let settings = state_guard.settings.read();
|
||||
let status_json = settings.get_value(crate::services::settings::SettingsKey::PgConnectionStatus);
|
||||
let db_type = match status_json {
|
||||
crate::services::settings::SettingsValue::Json(json) => json
|
||||
.get("type")
|
||||
.and_then(|t| t.as_str())
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_else(|| "sqlite".to_string()),
|
||||
_ => "sqlite".to_string(),
|
||||
};
|
||||
|
||||
let migration_result = if db_type == "postgresql" {
|
||||
run_migration(conn, DatabaseType::PostgreSQL).await
|
||||
} else {
|
||||
run_migration(conn, DatabaseType::SQLite).await
|
||||
};
|
||||
|
||||
match migration_result {
|
||||
Ok(_) => Ok(IpcResponse::success(SyncResult {
|
||||
success: true,
|
||||
message: Some("Database synchronized successfully".to_string()),
|
||||
|
||||
@@ -6,6 +6,8 @@ pub mod state;
|
||||
pub mod utils;
|
||||
|
||||
use crate::db::connection::create_sqlite_connection;
|
||||
use crate::db::connection::DatabaseType;
|
||||
use crate::db::migration::run_migration;
|
||||
use tauri::{
|
||||
image::Image,
|
||||
menu::{Menu, MenuItem},
|
||||
@@ -51,6 +53,10 @@ fn setup_database(app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
|
||||
tauri::async_runtime::spawn(async move {
|
||||
match create_sqlite_connection(&db_path_str).await {
|
||||
Ok(conn) => {
|
||||
if let Err(e) = run_migration(&conn, DatabaseType::SQLite).await {
|
||||
eprintln!("Failed to run sqlite migration: {}", e);
|
||||
return;
|
||||
}
|
||||
let state = handle.state::<crate::state::SafeAppState>();
|
||||
let state_guard = state.write();
|
||||
let mut db_guard = state_guard.db.write();
|
||||
|
||||
Reference in New Issue
Block a user