-
-
Notifications
You must be signed in to change notification settings - Fork 0
Add sync tombstones to propagate sub-table deletions across clients #424
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
Changes from all commits
57e60c5
42d592d
a523fde
989fc2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -237,7 +237,15 @@ export const LOCAL_SCHEMA_DDL_SQL = ` | |||||||||
| UNIQUE(contact_id, tag) | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TABLE IF NOT EXISTS sync_tombstones ( | ||||||||||
| table_name TEXT NOT NULL, | ||||||||||
| row_id TEXT NOT NULL, | ||||||||||
| deleted_at INTEGER NOT NULL, | ||||||||||
| PRIMARY KEY (table_name, row_id) | ||||||||||
| ); | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding an index on
Suggested change
|
||||||||||
|
|
||||||||||
| CREATE INDEX IF NOT EXISTS idx_contact_tags_contact_id ON contact_tags(contact_id); | ||||||||||
| CREATE INDEX IF NOT EXISTS idx_sync_tombstones_deleted_at ON sync_tombstones(deleted_at); | ||||||||||
| CREATE INDEX IF NOT EXISTS idx_contact_emails_contact_id ON contact_emails(contact_id); | ||||||||||
| CREATE UNIQUE INDEX IF NOT EXISTS idx_contact_emails_contact_email ON contact_emails(contact_id, email); | ||||||||||
| CREATE INDEX IF NOT EXISTS idx_contact_phones_contact_id ON contact_phones(contact_id); | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -85,16 +85,6 @@ function runSharedMigrations(db: Database.Database): void { | |||||||||||||||||||||||||||||
| if (version < 1) { | ||||||||||||||||||||||||||||||
| db.pragma('user_version = 1'); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing migration for the shared DB. Same issue as the local DB: A new
Suggested change
Note: the example migration template that was deleted from this file in this PR contained an important warning about using |
||||||||||||||||||||||||||||||
| // Future migration blocks go here. Example: | ||||||||||||||||||||||||||||||
| // if (version < 2) { | ||||||||||||||||||||||||||||||
| // db.prepare('ALTER TABLE contacts ADD COLUMN foo TEXT').run(); | ||||||||||||||||||||||||||||||
| // db.prepare( | ||||||||||||||||||||||||||||||
| // `INSERT OR REPLACE INTO shared_meta (key, value) VALUES ('min_app_version', '0.2.0')` | ||||||||||||||||||||||||||||||
| // ).run(); | ||||||||||||||||||||||||||||||
| // // Note: always use INSERT OR REPLACE here, not ON CONFLICT ... WHERE value > ..., | ||||||||||||||||||||||||||||||
| // // because SQLite compares TEXT lexicographically and '0.9.0' > '0.10.0' is true. | ||||||||||||||||||||||||||||||
| // db.pragma('user_version = 2'); | ||||||||||||||||||||||||||||||
| // } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export function createSharedDb( | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing migration block — this will break existing databases.
sync_tombstonesis added toLOCAL_SCHEMA_DDL_SQL, but that SQL only runs for brand-new databases viainitDatabase. Existing users whoseuser_versionis already atDB_VERSIONwill hit thereturnguard above and skip this function entirely, so their databases will never get the table. Any call toINSERT INTO sync_tombstonesorSELECT FROM sync_tombstoneswill throwno such table: sync_tombstonesat runtime.DB_VERSIONneeds to be bumped and a migration block needs to be added here:The
DB_VERSIONconstant (wherever it's defined) must also be incremented to match.