Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upfront database integrity check #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tserong
Copy link

@tserong tserong commented Aug 9, 2023

If the SQLite database is itself corrupt, there's little point checking
the files on the disk, because we have no metadata to check them against.
So this is a special check that happens right at the start before all
other checks.

If the file is so trashed it doesn't even look like an SQLite database
then PRAGMA integrity_check will return immediately with an error and
you'll see something like sqlite3_exec error: file is not a database (26)
or sqlite3_exec error: database disk image is malformed (11).

If the file isn't too badly damaged (in my test I chopped 1KB off the end),
the integrity check will actually run, and you'll see potentially several
lines of output, e.g.:

*** in database main ***
Fragmentation of 206 bytes reported as 0 on page 28
row 1 missing from index versioned_object_objid_vid_unique
row 2 missing from index versioned_object_objid_vid_unique
row 3 missing from index versioned_object_objid_vid_unique

This PR also updates the README and bumps the expected metadata schema to version 3

tserong added 3 commits August 8, 2023 18:00
If the SQLite database is itself corrupt, there's little point checking
the files on the disk, because we have no metadata to check them against.
So this is a special check that happens right at the start before all
other checks.

If the file is _so_ trashed it doesn't even look like an SQLite database
then `PRAGMA integrity_check` will return immediately with an error and
you'll see something like `sqlite3_exec error: file is not a database (26)`
or `sqlite3_exec error: database disk image is malformed (11)`.

If the file isn't too badly damaged (in my test I chopped 1KB off the end),
the integrity check will actually run, and you'll see potentially several
lines of output, e.g.:

```
*** in database main ***
Fragmentation of 206 bytes reported as 0 on page 28
row 1 missing from index versioned_object_objid_vid_unique
row 2 missing from index versioned_object_objid_vid_unique
row 3 missing from index versioned_object_objid_vid_unique
```

Signed-off-by: Tim Serong <[email protected]>
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