const CREATE_SHARED_SCHEMA_SQL: &str = "-- This Source Code Form is subject to the terms of the Mozilla Public\n-- License, v. 2.0. If a copy of the MPL was not distributed with this\n-- file, You can obtain one at http://mozilla.org/MPL/2.0/.\n\n-- XXX - TODO - moz_annos\n-- XXX - TODO - moz_anno_attributes\n-- XXX - TODO - moz_items_annos\n\nCREATE TABLE IF NOT EXISTS moz_places (\n id INTEGER PRIMARY KEY,\n url LONGVARCHAR NOT NULL,\n title LONGVARCHAR,\n -- note - desktop has rev_host here - that\'s now in moz_origin.\n visit_count_local INTEGER NOT NULL DEFAULT 0,\n visit_count_remote INTEGER NOT NULL DEFAULT 0,\n hidden INTEGER DEFAULT 0 NOT NULL,\n typed INTEGER DEFAULT 0 NOT NULL, -- XXX - is \'typed\' ok? Note also we want this as a *count*, not a bool.\n frecency INTEGER DEFAULT -1 NOT NULL,\n -- XXX - splitting last visit into local and remote correct?\n last_visit_date_local INTEGER NOT NULL DEFAULT 0,\n last_visit_date_remote INTEGER NOT NULL DEFAULT 0,\n guid TEXT NOT NULL UNIQUE,\n foreign_count INTEGER DEFAULT 0 NOT NULL,\n url_hash INTEGER DEFAULT 0 NOT NULL,\n description TEXT, -- XXXX - title above?\n preview_image_url TEXT,\n -- origin_id would ideally be NOT NULL, but we use a trigger to keep\n -- it up to date, so do perform the initial insert with a null.\n origin_id INTEGER,\n -- a couple of sync-related fields.\n sync_status TINYINT NOT NULL DEFAULT 1, -- 1 is SyncStatus::New\n sync_change_counter INTEGER NOT NULL DEFAULT 0, -- adding visits will increment this\n\n FOREIGN KEY(origin_id) REFERENCES moz_origins(id) ON DELETE CASCADE\n);\n\nCREATE INDEX IF NOT EXISTS url_hashindex ON moz_places(url_hash);\nCREATE INDEX IF NOT EXISTS visitcountlocal ON moz_places(visit_count_local);\nCREATE INDEX IF NOT EXISTS visitcountremote ON moz_places(visit_count_remote);\nCREATE INDEX IF NOT EXISTS frecencyindex ON moz_places(frecency);\nCREATE INDEX IF NOT EXISTS lastvisitdatelocalindex ON moz_places(last_visit_date_local);\nCREATE INDEX IF NOT EXISTS lastvisitdateremoteindex ON moz_places(last_visit_date_remote);\nCREATE UNIQUE INDEX IF NOT EXISTS guid_uniqueindex ON moz_places(guid);\nCREATE INDEX IF NOT EXISTS originidindex ON moz_places(origin_id);\n\n\nCREATE TABLE IF NOT EXISTS moz_places_tombstones (\n guid TEXT PRIMARY KEY\n) WITHOUT ROWID;\n\n\n-- This table stores Place IDs with stale frecencies, along with the time they\n-- were marked as stale. Maintenance and Sync periodically recalculate\n-- frecencies for Place IDs in this table.\nCREATE TABLE IF NOT EXISTS moz_places_stale_frecencies (\n place_id INTEGER PRIMARY KEY NOT NULL REFERENCES moz_places(id)\n ON DELETE CASCADE,\n stale_at INTEGER NOT NULL -- In milliseconds.\n);\n\n\nCREATE TABLE IF NOT EXISTS moz_historyvisits (\n id INTEGER PRIMARY KEY,\n is_local INTEGER NOT NULL, -- XXX - not in desktop - will always be true for visits added locally, always false visits added by sync.\n from_visit INTEGER, -- XXX - self-reference?\n place_id INTEGER NOT NULL,\n visit_date INTEGER NOT NULL,\n visit_type INTEGER NOT NULL,\n -- session INTEGER, -- XXX - what is \'session\'? Appears unused.\n\n FOREIGN KEY(place_id) REFERENCES moz_places(id) ON DELETE CASCADE,\n FOREIGN KEY(from_visit) REFERENCES moz_historyvisits(id)\n);\n\nCREATE INDEX IF NOT EXISTS placedateindex ON moz_historyvisits(place_id, visit_date);\nCREATE INDEX IF NOT EXISTS fromindex ON moz_historyvisits(from_visit);\nCREATE INDEX IF NOT EXISTS dateindex ON moz_historyvisits(visit_date);\nCREATE INDEX IF NOT EXISTS islocalindex ON moz_historyvisits(is_local);\n\n-- Greatly helps the multi-join query in frecency.\nCREATE INDEX IF NOT EXISTS visits_from_type_idx ON moz_historyvisits(from_visit, visit_type);\n\nCREATE TABLE IF NOT EXISTS moz_historyvisit_tombstones (\n place_id INTEGER NOT NULL,\n visit_date INTEGER NOT NULL,\n FOREIGN KEY(place_id) REFERENCES moz_places(id) ON DELETE CASCADE,\n PRIMARY KEY(place_id, visit_date)\n);\n\n\nCREATE TABLE IF NOT EXISTS moz_inputhistory (\n place_id INTEGER NOT NULL,\n input LONGVARCHAR NOT NULL,\n use_count INTEGER,\n\n PRIMARY KEY (place_id, input),\n FOREIGN KEY(place_id) REFERENCES moz_places(id) ON DELETE CASCADE\n);\n\n\nCREATE TABLE IF NOT EXISTS moz_bookmarks (\n id INTEGER PRIMARY KEY,\n fk INTEGER DEFAULT NULL, -- place_id\n type INTEGER NOT NULL,\n parent INTEGER,\n position INTEGER NOT NULL,\n title TEXT, -- a\'la bug 1356159, NULL is special here - it means \'not edited\'\n dateAdded INTEGER NOT NULL DEFAULT 0,\n lastModified INTEGER NOT NULL DEFAULT 0,\n guid TEXT NOT NULL UNIQUE CHECK(length(guid) == 12),\n\n syncStatus INTEGER NOT NULL DEFAULT 0,\n syncChangeCounter INTEGER NOT NULL DEFAULT 1,\n\n -- bookmarks must have a fk to a URL, other types must not.\n CHECK((type == 1 AND fk IS NOT NULL) OR (type > 1 AND fk IS NULL))\n -- only the root is allowed to have a non-null parent\n CHECK(guid == \"root________\" OR parent IS NOT NULL)\n\n FOREIGN KEY(fk) REFERENCES moz_places(id) ON DELETE RESTRICT\n FOREIGN KEY(parent) REFERENCES moz_bookmarks(id) ON DELETE CASCADE\n);\n\n-- CREATE INDEX IF NOT EXISTS itemindex ON moz_bookmarks(fk, type);\n-- CREATE INDEX IF NOT EXISTS parentindex ON moz_bookmarks(parent, position);\nCREATE INDEX IF NOT EXISTS itemlastmodifiedindex ON moz_bookmarks(fk, lastModified);\n-- CREATE INDEX IF NOT EXISTS dateaddedindex ON moz_bookmarks(dateAdded);\nCREATE UNIQUE INDEX IF NOT EXISTS guid_uniqueindex ON moz_bookmarks(guid);\n\n\nCREATE TABLE IF NOT EXISTS moz_bookmarks_deleted (\n guid TEXT PRIMARY KEY,\n dateRemoved INTEGER NOT NULL\n) WITHOUT ROWID;\n\n-- Note: desktop has/had a \'keywords\' table, but we intentionally do not.\n\n\nCREATE TABLE IF NOT EXISTS moz_origins (\n id INTEGER PRIMARY KEY,\n prefix TEXT NOT NULL,\n host TEXT NOT NULL,\n rev_host TEXT NOT NULL,\n frecency INTEGER NOT NULL, -- XXX - why not default of -1 like in moz_places?\n UNIQUE (prefix, host)\n);\n\nCREATE INDEX IF NOT EXISTS hostindex ON moz_origins(rev_host);\n\n\n-- This table holds key-value metadata for Places and its consumers. Sync stores\n-- the sync IDs for the bookmarks and history collections in this table, and the\n-- last sync time for history.\nCREATE TABLE IF NOT EXISTS moz_meta (\n key TEXT PRIMARY KEY,\n value NOT NULL\n) WITHOUT ROWID;\n\n-- Support for tags.\nCREATE TABLE IF NOT EXISTS moz_tags(\n id INTEGER PRIMARY KEY,\n tag TEXT UNIQUE NOT NULL,\n lastModified INTEGER NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS moz_tags_relation(\n tag_id INTEGER NOT NULL REFERENCES moz_tags(id) ON DELETE CASCADE,\n place_id INTEGER NOT NULL REFERENCES moz_places(id) ON DELETE CASCADE,\n PRIMARY KEY(tag_id, place_id)\n) WITHOUT ROWID;\n\n-- This table holds synced items, including tombstones. It\'s unused if Sync\n-- isn\'t configured. At the end of a sync, this table\'s contents should match\n-- both what\'s on the server, and the local tree in `moz_bookmarks`.\nCREATE TABLE IF NOT EXISTS moz_bookmarks_synced(\n id INTEGER PRIMARY KEY,\n -- We intentionally don\'t validate GUIDs, as we allow and fix up invalid\n -- ones.\n guid TEXT UNIQUE NOT NULL,\n -- The `parentid` from the record.\n parentGuid TEXT,\n -- The server modified time, in milliseconds. This is *not* a\n -- ServerTimestamp, which is in fractional seconds.\n serverModified INTEGER NOT NULL DEFAULT 0,\n needsMerge BOOLEAN NOT NULL DEFAULT 0,\n validity INTEGER NOT NULL DEFAULT 1, -- SyncValidity::Valid\n isDeleted BOOLEAN NOT NULL DEFAULT 0,\n kind INTEGER NOT NULL DEFAULT -1,\n -- The creation date, in milliseconds.\n dateAdded INTEGER NOT NULL DEFAULT 0,\n title TEXT,\n placeId INTEGER REFERENCES moz_places(id)\n ON DELETE SET NULL,\n keyword TEXT,\n description TEXT,\n loadInSidebar BOOLEAN,\n smartBookmarkName TEXT,\n feedURL TEXT,\n siteURL TEXT\n);\n\nCREATE INDEX IF NOT EXISTS moz_bookmarks_synced_urls ON moz_bookmarks_synced(placeId);\nCREATE INDEX IF NOT EXISTS moz_bookmarks_synced_keywords ON moz_bookmarks_synced(keyword)\n WHERE keyword NOT NULL;\n\n-- This table holds parent-child relationships and positions for synced items,\n-- from each folder\'s `children`. Unlike `moz_bookmarks`, this is stored\n-- separately because we might see an incoming folder before its children. This\n-- also lets us catch disagreements between a folder\'s `children` and its\n-- childrens\' `parentid`.\nCREATE TABLE IF NOT EXISTS moz_bookmarks_synced_structure(\n guid TEXT,\n parentGuid TEXT REFERENCES moz_bookmarks_synced(guid)\n ON DELETE CASCADE,\n position INTEGER NOT NULL,\n PRIMARY KEY(parentGuid, guid)\n) WITHOUT ROWID;\n\n-- This table holds tags for synced items.\nCREATE TABLE IF NOT EXISTS moz_bookmarks_synced_tag_relation(\n itemId INTEGER NOT NULL REFERENCES moz_bookmarks_synced(id)\n ON DELETE CASCADE,\n tagId INTEGER NOT NULL REFERENCES moz_tags(id)\n ON DELETE CASCADE,\n PRIMARY KEY(itemId, tagId)\n) WITHOUT ROWID;\n\n-- This table holds search keywords for URLs. Desktop would like to replace\n-- these with custom search engines eventually (bug 648398); however, we\n-- must still round-trip keywords imported via Sync or migrated from Fennec.\n-- Since none of the `moz_bookmarks_synced_*` tables are durable, we store\n-- keywords for URLs in a separate table. Unlike Desktop, we don\'t support\n-- custom POST data, since we don\'t sync it (bug 1345417), and Fennec\n-- doesn\'t write it.\nCREATE TABLE IF NOT EXISTS moz_keywords(\n place_id INTEGER PRIMARY KEY REFERENCES moz_places(id)\n ON DELETE RESTRICT,\n keyword TEXT NOT NULL UNIQUE\n);\n";