larkery / zsh-histdb

A slightly better history for zsh
MIT License
1.27k stars 75 forks source link

histdb tries to migrate when db is locked on shell open #64

Closed phiresky closed 4 years ago

phiresky commented 4 years ago

When a shell is started while the histdb database is locked, the shell interprets that as the current schema version being "" so it thinks the schema is outdated:

Error: database is locked        
History database ~/.histdb/zsh-history.db is using an older schema () and will be updated to version 2.
There is no migration script from version  to 2.
larkery commented 4 years ago

Does this still make a problem? I haven't seen this happen.

phiresky commented 4 years ago

This also only happened to me when my disk was overloaded so the db was kept locked for longer periods of time..

Testing it by forcing the db to lock via

❯ sqlite3 ~/.histdb/zsh-history.db
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
sqlite> begin;
sqlite> create table a(b);
sqlite> # just keep it open

it does seem like it doesn't happen anymore - i think that's because of WAL - when wal is active, read queries like PRAGMA user_version which migrate does still work when db is locked

tmpm697 commented 4 years ago

I have same issue, I can't make this plugin work.

steps:

❯ sqlite3 ~/.histdb/zsh-history.db
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
sqlite> begin;
sqlite> create table a(b);
sqlite> # just keep it open

Open new shell -> Error: near line 8: database is locked

histdb strace give empty result.

phiresky commented 4 years ago

@tmpm697 just that alone is not indicative of an issue, it's expected that if you keep the db locked intentionally you won't be able to write to it

phiresky commented 4 years ago

This still seems to happen when the database does not exist at all (on the first run). not sure why

larkery commented 4 years ago

I'll see if I can reproduce and put in a check to make it not happen.

swuecho commented 4 years ago

sqlite3 ~/.histdb/zsh-history.db and copy the content of https://github.com/larkery/zsh-histdb/blob/master/db_migrations/0to2.sql to the sqlite shell solve the problem