Last active
October 4, 2017 03:40
-
-
Save SUPERCILEX/103b9b746d1e33c02f42b9d0e77023ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating tables for v1 | |
db.execSQL("CREATE TABLE mutation_queues (uid TEXT PRIMARY KEY, last_acknowledged_batch_id INTEGER, last_stream_token BLOB)"); | |
db.execSQL("CREATE TABLE mutations (uid TEXT, batch_id INTEGER, mutations BLOB, PRIMARY KEY (uid, batch_id))"); | |
db.execSQL("CREATE TABLE document_mutations (uid TEXT, path TEXT, batch_id INTEGER, PRIMARY KEY (uid, path, batch_id))"); | |
db.execSQL("CREATE TABLE targets (target_id INTEGER PRIMARY KEY, canonical_id TEXT, snapshot_version_seconds INTEGER, snapshot_version_nanos INTEGER, resume_token BLOB, last_listen_sequence_number INTEGER,target_proto BLOB)"); | |
db.execSQL("CREATE INDEX query_targets ON targets (canonical_id, target_id)"); | |
db.execSQL("CREATE TABLE target_globals (highest_target_id INTEGER, highest_listen_sequence_number INTEGER)"); | |
db.execSQL("CREATE TABLE target_documents (target_id INTEGER, path TEXT, PRIMARY KEY (target_id, path))"); | |
db.execSQL("CREATE INDEX document_targets ON target_documents (path, target_id)"); | |
db.execSQL("CREATE TABLE remote_documents (path TEXT PRIMARY KEY, contents BLOB)"); | |
// Already migrating tables to v2 | |
db.execSQL("ALTER TABLE target_globals ADD COLUMN last_remote_snapshot_version_seconds INTEGER"); | |
db.execSQL("ALTER TABLE target_globals ADD COLUMN last_remote_snapshot_version_nanos INTEGER"); | |
db.execSQL("UPDATE target_globals SET last_remote_snapshot_version_seconds=0, last_remote_snapshot_version_nanos=0"); | |
// Some of the queries I found | |
"SELECT path FROM target_documents WHERE target_id = ?" | |
"SELECT target_proto FROM targets WHERE canonical_id = ?" | |
"SELECT m.mutations FROM document_mutations dm, mutations m WHERE dm.uid = ? AND dm.path = ? AND dm.uid = m.uid AND dm.batch_id = m.batch_id" | |
"INSERT INTO target_globals (highest_target_id, highest_listen_sequence_number, last_remote_snapshot_version_seconds, last_remote_snapshot_version_nanos) VALUES (?, ?, ?, ?)" | |
"INSERT OR IGNORE INTO target_documents (target_id, path) VALUES (?, ?)" | |
"INSERT OR REPLACE INTO targets (target_id, canonical_id, snapshot_version_seconds, snapshot_version_nanos, resume_token, target_proto) VALUES (?, ?, ?, ?, ?, ?)" | |
"DELETE FROM target_documents WHERE target_id = ?" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment