Fix creating message_fts table during database migration. #13809
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First time contributor checklist
Contributor checklist
Fixes #1234
syntaxDescription
In database migration 175, the full text search table is dropped and recreated with a new name (
mms
->message
). First the old table and triggers are dropped:Signal-Android/app/src/main/java/org/thoughtcrime/securesms/database/helpers/migration/V175_FixFullTextSearchLink.kt
Lines 14 to 17 in 49eb80b
Then the new one is created:
Signal-Android/app/src/main/java/org/thoughtcrime/securesms/database/helpers/migration/V175_FixFullTextSearchLink.kt
Line 24 in 49eb80b
Because no data is actually migrated from the old to the new search table (the old one doesn't even exist anymore), the new one is empty. However, the content table is (likely) not:
content=message
. This leaves the new table in an inconsistent state.After this particular migration, any SQL statement that triggers one of the
TRIGGER
s of themessage_fts
table will result in a corrupted database (database disk image is malformed
). This can happen while migrating to 191, which is issue #13034, and while migrating to 229, which is issue #13506. Possibly other migrations are also affected.Besides rebuilding the search table, the old data could also be transferred over. But because:
mms_fts
table before the 175 migration, it showscontent=mms
. While at this point, themms
table was already dropped. Without knowing with certainty the database use between the v174 and v175 migration, I would not dare assert that themms_fts
table is fully consistent at this point.I went with the rebuild-option. It is also a smaller diff.
Simple demonstration of v175-migration corrupting a database (click to show)
This code can be executed directly in a sqlite shell.
If a rebuild is performed right after the
CREATE VIRTUAL TABLE
statement, the error disappears.Examples of migration before and after patch (click to show)
A database with a doubled message (wrt recipient, thread, and timestamp), at version 170. This is #13034. Excerpt from the debug log before the patch:
After the patch:
A database with missed call messages with
notified=0
. This is #13506. Before the patch:After the patch:
Notes:
https://sqlite.org/fts5.html#external_content_table_pitfalls
Please let me know if any edits to this PR are required, I'd be happy to make any changes you need.
Thanks!