Skip to content

Handle SQLite WAL and Journal files (.gitignore and db drop) - #451

Merged
cllns merged 2 commits into
mainfrom
sqlite-wal-files
Oct 2, 2026
Merged

cllns merged 2 commits into
mainfrom
sqlite-wal-files

Conversation

@cllns

@cllns cllns commented Oct 1, 2026

Copy link
Copy Markdown
Member

Handle the extra files SQLite keeps next to a database, now that hanami/hanami-db#21 makes WAL the default journal mode.

  • hanami new will now ignore db/*.sqlite* instead of db/*.sqlite, so -wal, -shm and -journal files aren't committed.
  • hanami db drop removes those files along with the database. A stale -wal or -journal left next to a recreated database of the same name can corrupt it.
Disclosure: I worked with AI to write this. I most likely would've missed this in my work integrating my changes from hanami/hanami-db#21 into hanami/hanami and would've had to fix these issues after the fact.

SQLite keeps -wal and -shm files next to the database in WAL mode, and a -journal file in rollback-journal mode, while a connection is open or after a crash. Widen db/*.sqlite to db/*.sqlite* so these are ignored too, along with databases named .sqlite3.
A stale -journal or -wal file left next to a recreated database of the same name can corrupt it (https://www.sqlite.org/howtocorrupt.html). Remove the -journal, -wal and -shm files along with the database file, even if the database file itself is already gone.

The database file is removed last, so a failure part-way through never leaves one of these files behind without its database.
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

ℹ️ Optional job failed: Ruby jruby

@timriley timriley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very nice, thanks @cllns!

@cllns
cllns merged commit e604adb into main Oct 2, 2026
11 checks passed
@cllns
cllns deleted the sqlite-wal-files branch October 2, 2026 05:29
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.

2 participants