Debian Codegraph @

third_party/rust/webext-storage/sql/tests/create_schema_v1.sql

raw
1 -- This Source Code Form is subject to the terms of the Mozilla Public
2 -- License, v. 2.0. If a copy of the MPL was not distributed with this
3 -- file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 -- This is a very simple schema for a chrome.storage.* implementation. At time
6 -- of writing, only chrome.storage.sync is supported, but this can be trivially
7 -- enhanced to support chrome.storage.local (the api is identical, it's just a
8 -- different "bucket" and doesn't sync).
9 --
10 -- Even though the spec allows for a single extension to have any number of
11 -- "keys", we've made the decision to store all keys for a given extension in a
12 -- single row as a JSON representation of all keys and values.
13 -- We've done this primarily due to:
14 -- * The shape of the API is very JSON, and it almost encourages multiple keys
15 -- to be fetched at one time.
16 -- * The defined max sizes that extensions are allowed to store using this API
17 -- is sufficiently small that we don't have many concerns around record sizes.
18 -- * We'd strongly prefer to keep one record per extension when syncing this
19 -- data, so having the local store in this shape makes syncing easier.
20
21 CREATE TABLE IF NOT EXISTS storage_sync_data (
22 ext_id TEXT NOT NULL PRIMARY KEY,
23
24 /* The JSON payload. NULL means it's a tombstone */
25 data TEXT,
26
27 /* Same "sync change counter" strategy used by other components. */
28 sync_change_counter INTEGER NOT NULL DEFAULT 1
29 );
30
31 CREATE TABLE IF NOT EXISTS storage_sync_mirror (
32 guid TEXT NOT NULL PRIMARY KEY,
33
34 /* The extension_id is explicitly not the GUID used on the server.
35 It can't be a regular foreign-key relationship back to storage_sync_data
36 as items with no data on the server (ie, deleted items) will not appear
37 in storage_sync_data.
38 */
39 ext_id TEXT NOT NULL UNIQUE,
40
41 /* The JSON payload. We *do* allow NULL here - it means "deleted" */
42 data TEXT
43 );
44
45 -- This table holds key-value metadata - primarily for sync.
46 CREATE TABLE IF NOT EXISTS meta (
47 key TEXT PRIMARY KEY,
48 value NOT NULL
49 ) WITHOUT ROWID;
50
51 -- Insert a couple test rows
52 INSERT INTO storage_sync_mirror(guid, ext_id, data)
53 VALUES
54 ('guid-1', 'ext-id-1', 'data-1'),
55 ('guid-2', 'ext-id-2', 'data-2');
56
57 PRAGMA user_version = 1;