From fcea2b28d0cc488e63e07dfea2cc72e19702daa2 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Tue, 3 Mar 2026 23:40:45 +0100 Subject: fix: clear script database before rebuild to prevent unique constraint violation (#3232) The script store build() replays all records from the record store into SQLite but never cleared the database first. Stale rows from previous builds caused unique constraint violations on the name index when scripts were renamed or recreated. ## Checks - [ ] I am happy for maintainers to push small adjustments to this PR, to speed up the review cycle - [ ] I have checked that there are no existing pull requests for the same thing --- crates/atuin-scripts/src/database.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'crates/atuin-scripts/src/database.rs') diff --git a/crates/atuin-scripts/src/database.rs b/crates/atuin-scripts/src/database.rs index 26fb9328..be113526 100644 --- a/crates/atuin-scripts/src/database.rs +++ b/crates/atuin-scripts/src/database.rs @@ -188,6 +188,19 @@ impl Database { Ok(res) } + pub async fn clear(&self) -> Result<()> { + debug!("clearing all scripts from sqlite"); + + sqlx::query("delete from script_tags") + .execute(&self.pool) + .await?; + sqlx::query("delete from scripts") + .execute(&self.pool) + .await?; + + Ok(()) + } + pub async fn delete(&self, id: &str) -> Result<()> { debug!("deleting script {}", id); -- cgit v1.3.1