Skip to content

fix: clear script database before rebuild to prevent unique constraint violation#3232

Merged
ellie merged 1 commit intomainfrom
ellie/script-constraint-fix
Mar 3, 2026
Merged

fix: clear script database before rebuild to prevent unique constraint violation#3232
ellie merged 1 commit intomainfrom
ellie/script-constraint-fix

Conversation

@ellie
Copy link
Member

@ellie ellie commented Mar 3, 2026

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

…t violations

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.
@ellie ellie changed the title fix: clear script database before rebuild to prevent unique constrain… fix: clear script database before rebuild to prevent unique constraint Mar 3, 2026
@ellie ellie changed the title fix: clear script database before rebuild to prevent unique constraint fix: clear script database before rebuild to prevent unique constraint violation Mar 3, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 3, 2026

Greptile Summary

Fixes the reported bug where stale SQLite rows caused unique constraint violations during script rebuild. The fix correctly clears existing data before replaying records, preventing name conflicts from renamed scripts. The approach is straightforward and solves the problem as described.

Important Files Changed

Filename Overview
crates/atuin-scripts/src/store.rs Adds clear() call before replaying records in build(). Correctly prevents unique constraint violations when scripts are renamed or recreated. Includes helpful comment explaining the fix.
crates/atuin-scripts/src/database.rs Adds new clear() method that deletes all rows from script_tags then scripts in the correct FK order. Effectively prevents stale rows from causing conflicts during rebuild.

Last reviewed commit: 5fa1fc0

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@ellie ellie merged commit fcea2b2 into main Mar 3, 2026
22 checks passed
@ellie ellie deleted the ellie/script-constraint-fix branch March 3, 2026 22:40
pull bot pushed a commit to hareki/atuin that referenced this pull request Mar 4, 2026
…t violation (atuinsh#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.

<!-- Thank you for making a PR! Bug fixes are always welcome, but if
you're adding a new feature or changing an existing one, we'd really
appreciate if you open an issue, post on the forum, or drop in on
Discord -->

## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant