|
| 1 | +SELECT load_extension("uuid"); |
| 2 | +SELECT uuid_blob(); |
| 3 | + |
| 4 | +CREATE TABLE new_principals ( |
| 5 | + -- uuid is an internal identifier to allow the principal |
| 6 | + -- to be renamed in the future |
| 7 | + uuid BLOB PRIMARY KEY, |
| 8 | + -- id is the principl identifier used by public interfaces |
| 9 | + id TEXT UNIQUE NOT NULL, |
| 10 | + displayname TEXT, |
| 11 | + principal_type TEXT NOT NULL, |
| 12 | + password_hash TEXT |
| 13 | +) STRICT; |
| 14 | + |
| 15 | +CREATE TABLE new_calendars ( |
| 16 | + -- UUID to be saved as 16-byte BLOB (much more efficient than text) |
| 17 | + -- disadvantage: less ergonomic in sqlite shell |
| 18 | + uuid BLOB PRIMARY KEY, -- a globally unique UUID (not the resource path, reference for calendar objects) |
| 19 | + owner BLOB NOT NULL, -- only the owner can manage shares |
| 20 | + synctoken INTEGER DEFAULT 0 NOT NULL, |
| 21 | + subscription_url TEXT, |
| 22 | + push_topic TEXT UNIQUE NOT NULL, |
| 23 | + comp_event BOOLEAN NOT NULL, |
| 24 | + comp_todo BOOLEAN NOT NULL, |
| 25 | + comp_journal BOOLEAN NOT NULL, |
| 26 | + timezone_id TEXT, |
| 27 | + CONSTRAINT fk_calendar_owner FOREIGN KEY (owner) |
| 28 | + REFERENCES new_principals (uuid) ON DELETE RESTRICT |
| 29 | +) STRICT; |
| 30 | + |
| 31 | +CREATE TABLE calendar_views ( |
| 32 | + ref TEXT NOT NULL, -- the underlying calendar |
| 33 | + principal BLOB NOT NULL, -- the principal having access to this calendar view |
| 34 | + name TEXT NOT NULL, -- the path (what previously was the id) |
| 35 | + access TEXT NOT NULL, -- read, write |
| 36 | + |
| 37 | + displayname TEXT, |
| 38 | + description TEXT, |
| 39 | + "order" INT DEFAULT 0 NOT NULL, |
| 40 | + color TEXT, |
| 41 | + deleted_at DATETIME, -- a user can delete its calendar view without deleting it for everyone |
| 42 | + |
| 43 | + PRIMARY KEY (principal, name), |
| 44 | + CONSTRAINT uniq_cal_principal(ref, principal) UNIQUE, -- a user should not have mutiple views on a calendar |
| 45 | + CONSTRAINT fk_calendar_view_principal FOREIGN KEY (principal) |
| 46 | + REFERENCES new_principals (uuid) ON DELETE CASCADE, |
| 47 | + CONSTRAINT fk_calendar_view_calendar FOREIGN KEY (ref) |
| 48 | + REFERENCES calendars (id) ON DELETE CASCADE |
| 49 | +) STRICT; |
0 commit comments