Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ Constants are in `constants/mod.rs`. Errors are `AppError` (`error.rs`), which r
changing or dropping a column drops its default first.
- Backup and the Users view are not there for SQL Server yet. See `TODO.md`.
- **Backups** (`dump.rs`) run `mysqldump` / `pg_dump` or copy the SQLite file. Passwords go through
`MYSQL_PWD` / `PGPASSWORD`.
`MYSQL_PWD` / `PGPASSWORD`. The tools run with `--verbose`. `DumpLog` reads their stderr for the current
table and keeps only the real error lines. Progress (file size, time, table) goes to the frontend through a
`Channel` about once per second. `cancel_dump` kills the tool and deletes the `.part` file.
Esc stops a backup only when Escape has no other job there (`Shortcuts.cancelsBackup`).
- **AI notes** (`service/notes.rs`): each database has a `claude.md` file at
`~/.sql-pro/<database>-<hash>/claude.md` (`~/.sql-pro-dev/` in a debug build). The hash (FNV-1a, 8 hex) is
of driver, server host, port and database (SQLite: the file path), not the user. The user edits it in Ask AI. The AI adds facts to it (`remember`).
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ parking_lot = "0.13"
# Version 4 finds the same items as version 3, so saved passwords stay.
keyring = "4"
# Runs the system ssh program for tunnels.
tokio = { version = "1", features = ["process", "net", "time", "io-util"] }
tokio = { version = "1", features = ["process", "net", "time", "io-util", "macros"] }
tauri-plugin-updater = "2"
# Lists the fonts installed on the machine, for the font settings. WKWebView cannot do it.
fontdb = "0.24"
Expand Down
26 changes: 21 additions & 5 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
use std::path::PathBuf;

use tauri::State;
use tauri::ipc::Channel;

use crate::error::{AppError, AppResult};
use crate::model::{
AccessLevel, AiOptions, Attachment, BrowseRequest, ClaudeReply, ColumnInfo, ColumnSpec,
ConnectionConfig, CsvImport, CsvPreview, DataDiff, DataKinds, DbObject, DbProcess, Diagram,
ExportRequest, NewColumn, NewForeignKey, NewIndex, NewUser, Notes, QueryPlan, QueryStat,
ResultSet, RowUpdate, RowsExport, RowsSql, SaveResult, SchemaChange, SyncSql, TableKeys,
TablePage, TableRef, UserList, Values,
DumpProgress, ExportRequest, NewColumn, NewForeignKey, NewIndex, NewUser, Notes, QueryPlan,
QueryStat, ResultSet, RowUpdate, RowsExport, RowsSql, SaveResult, SchemaChange, SyncSql,
TableKeys, TablePage, TableRef, UserList, Values,
};
use crate::open_file::OpenedFiles;
use crate::repository::PasswordRepository;
Expand Down Expand Up @@ -369,8 +370,23 @@ pub async fn truncate_table(service: Service<'_>, id: String, table: TableRef) -
}

#[tauri::command]
pub async fn dump_database(service: Service<'_>, id: String, path: PathBuf) -> AppResult<()> {
service.dump_database(&id, &path).await
pub async fn dump_database(
service: Service<'_>,
id: String,
path: PathBuf,
progress: Channel<DumpProgress>,
) -> AppResult<()> {
service
.dump_database(&id, &path, |step| {
// The page may be gone. The backup goes on anyway.
let _ = progress.send(step);
})
.await
}

#[tauri::command]
pub fn cancel_dump(service: Service<'_>, id: String) {
service.cancel_dump(&id);
}

#[tauri::command]
Expand Down
9 changes: 9 additions & 0 deletions src-tauri/src/constants/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ pub const CREATE_NO_WINDOW: u32 = 0x0800_0000;
/// What we add to the path of a dump while it is being written.
pub const PARTIAL_DUMP_SUFFIX: &str = ".part";

/// The error of a backup that the user cancelled.
pub const BACKUP_CANCELLED: &str = "Backup cancelled";

/// The error when the user starts a second backup in a tab whose first one still runs.
pub const BACKUP_RUNS: &str = "A backup already runs in this tab";

/// How often a running backup tells the frontend how far it is.
pub const DUMP_PROGRESS_EVERY: std::time::Duration = std::time::Duration::from_secs(1);

/// The `MySQL` account host that means "from any host".
pub const ANY_HOST: &str = "%";

Expand Down
3 changes: 3 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use tauri::Manager as _;
///
/// Panics when the window cannot be created.
#[cfg_attr(mobile, tauri::mobile_entry_point)]
// Most of its lines are the list of commands.
#[allow(clippy::too_many_lines)]
pub fn run() {
#[cfg(all(debug_assertions, target_os = "macos"))]
run_under_dev_name();
Expand Down Expand Up @@ -93,6 +95,7 @@ pub fn run() {
commands::save_object,
commands::drop_object,
commands::dump_database,
commands::cancel_dump,
commands::export_tables,
commands::export_rows,
commands::rows_insert_sql,
Expand Down
14 changes: 14 additions & 0 deletions src-tauri/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,20 @@ impl ExportFormat {
}
}

/// How far a running backup is. The backend sends it about once per second.
#[derive(Clone, Debug, Default, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct DumpProgress {
/// The size of the dump file so far.
pub bytes: u64,
/// The time since the backup started.
pub seconds: u64,
/// The table the dump tool works on now. None before the first table, and for `SQLite`.
pub table: Option<String>,
/// How many tables the dump tool has started, this one included.
pub tables: usize,
}

/// What to export, and where to write it.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down
Loading
Loading