calendars_6.1.6.sql 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. CREATE TABLE _SqliteDatabaseProperties (key TEXT,
  2. value TEXT,
  3. UNIQUE(key));
  4. CREATE TABLE Store (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  5. name TEXT,
  6. default_alarm_offset INTEGER,
  7. type INTEGER,
  8. constraint_path TEXT,
  9. disabled INTEGER,
  10. external_id TEXT,
  11. persistent_id TEXT,
  12. flags INTEGER);
  13. CREATE TABLE sqlite_sequence(name,seq);
  14. CREATE TRIGGER delete_store_members AFTER DELETE ON Store
  15. BEGIN
  16. DELETE FROM Calendar WHERE store_id = OLD.ROWID;
  17. END;
  18. CREATE TRIGGER delete_store_changes AFTER DELETE ON Store
  19. BEGIN
  20. DELETE FROM CalendarChanges WHERE store_id = OLD.ROWID;DELETE FROM CalendarItemChanges WHERE store_id = OLD.ROWID;DELETE FROM AlarmChanges WHERE store_id = OLD.ROWID;DELETE FROM RecurrenceChanges WHERE store_id = OLD.ROWID;DELETE FROM ParticipantChanges WHERE store_id = OLD.ROWID;
  21. END;
  22. CREATE INDEX StoreExternalId on Store(external_id);
  23. CREATE TABLE Calendar (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  24. store_id INTEGER,
  25. title TEXT,
  26. flags INTEGER,
  27. color TEXT,
  28. color_is_display INTEGER,
  29. type TEXT,
  30. supported_entity_types INTEGER,
  31. external_id TEXT,
  32. external_mod_tag TEXT,
  33. external_id_tag TEXT,
  34. external_rep BLOB,
  35. display_order INTEGER,
  36. UUID TEXT,
  37. shared_owner_name TEXT,
  38. shared_owner_email TEXT,
  39. sharing_status INTEGER,
  40. sharing_invitation_response INTEGER,
  41. published_URL TEXT,
  42. is_published INTEGER,
  43. invitation_status INTEGER,
  44. sync_token TEXT,
  45. self_identity_id INTEGER,
  46. self_identity_email TEXT,
  47. owner_identity_id INTEGER,
  48. owner_identity_email TEXT);
  49. CREATE TABLE CalendarChanges (record INTEGER,
  50. type INTEGER,
  51. store_id INTEGER,
  52. flags INTEGER,
  53. external_id TEXT,
  54. external_id_tag TEXT,
  55. UUID TEXT);
  56. CREATE INDEX CalendarExternalId on Calendar(external_id);
  57. CREATE INDEX CalendarStoreId on Calendar(store_id);
  58. CREATE INDEX CalendarUUID on Calendar(UUID);
  59. CREATE TRIGGER delete_calendar_members AFTER DELETE ON Calendar
  60. BEGIN
  61. DELETE FROM OccurrenceCacheDays where calendar_id = OLD.ROWID;DELETE FROM OccurrenceCache where calendar_id = OLD.ROWID;DELETE FROM CalendarItem WHERE calendar_id = OLD.ROWID;DELETE FROM OccurrenceCacheDays WHERE count = 0;DELETE FROM Notification WHERE calendar_id = OLD.ROWID; DELETE FROM sharee where owner_id = OLD.ROWID;
  62. END;
  63. CREATE TABLE Recurrence (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  64. frequency INTEGER,
  65. interval INTEGER,
  66. week_start INTEGER,
  67. count INTEGER,
  68. cached_end_date REAL,
  69. cached_end_date_tz TEXT,
  70. end_date REAL,
  71. specifier TEXT,
  72. by_month_months INTEGER,
  73. owner_id INTEGER,
  74. external_id TEXT,
  75. external_mod_tag TEXT,
  76. external_id_tag TEXT,
  77. external_rep BLOB,
  78. UUID TEXT);
  79. CREATE TABLE RecurrenceChanges (record INTEGER,
  80. type INTEGER,
  81. external_id TEXT,
  82. store_id INTEGER,
  83. event_id_tomb INTEGER,
  84. calendar_id INTEGER,
  85. end_date_tomb REAL,
  86. UUID TEXT);
  87. CREATE INDEX RecurrenceEndCountIndex on Recurrence(end_date,
  88. count);
  89. CREATE INDEX RecurrenceExternalId on Recurrence(external_id);
  90. CREATE INDEX RecurrenceOwnerIdIndex on Recurrence(owner_id);
  91. CREATE INDEX RecurrenceUUID on Recurrence(UUID);
  92. CREATE TABLE Alarm (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  93. trigger_date REAL,
  94. trigger_interval INTEGER,
  95. type INTEGER,
  96. owner_id INTEGER,
  97. external_id TEXT,
  98. external_mod_tag TEXT,
  99. external_id_tag TEXT,
  100. external_rep BLOB,
  101. UUID TEXT,
  102. proximity INTEGER,
  103. disabled INTEGER,
  104. location_id INTEGER,
  105. acknowledgedDate REAL,
  106. default_alarm INTEGER,
  107. orig_alarm_id INTEGER);
  108. CREATE TABLE AlarmChanges (record INTEGER,
  109. type INTEGER,
  110. owner_id INTEGER,
  111. external_id TEXT,
  112. store_id INTEGER,
  113. calendar_id INTEGER,
  114. UUID TEXT);
  115. CREATE INDEX AlarmExternalId on Alarm(external_id);
  116. CREATE INDEX AlarmUUID on Alarm(UUID);
  117. CREATE INDEX AlarmOwnerId on Alarm(owner_id);
  118. CREATE INDEX AlarmTriggerDate on Alarm(trigger_date);
  119. CREATE TABLE Participant (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  120. entity_type INTEGER,
  121. type INTEGER,
  122. status INTEGER,
  123. pending_status INTEGER,
  124. role INTEGER,
  125. identity_id INTEGER,
  126. owner_id INTEGER,
  127. external_rep BLOB,
  128. UUID TEXT,
  129. email TEXT,
  130. is_self INTEGER);
  131. CREATE TABLE ParticipantChanges (record INTEGER,
  132. type INTEGER,
  133. entity_type INTEGER,
  134. owner_id INTEGER,
  135. UUID TEXT,
  136. email TEXT,
  137. store_id INTEGER,
  138. calendar_id INTEGER);
  139. CREATE INDEX ParticipantUUID on Participant(UUID);
  140. CREATE INDEX ParticipantEntityType on Participant(entity_type);
  141. CREATE INDEX ParticipantOwnerId on Participant(owner_id);
  142. CREATE TABLE Identity (display_name TEXT,
  143. address TEXT,
  144. first_name TEXT,
  145. last_name TEXT,
  146. UNIQUE (display_name,
  147. address,
  148. first_name,
  149. last_name));
  150. CREATE TABLE EventAction (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  151. event_id INTEGER,
  152. external_id TEXT,
  153. external_mod_tag TEXT,
  154. external_folder_id TEXT,
  155. external_schedule_id TEXT,
  156. external_rep BLOB);
  157. CREATE TABLE EventActionChanges (record INTEGER,
  158. type INTEGER,
  159. event_id INTEGER,
  160. external_id TEXT,
  161. external_folder_id TEXT,
  162. external_schedule_id TEXT,
  163. store_id INTEGER,
  164. calendar_id INTEGER);
  165. CREATE INDEX EventActionEventId on EventAction(event_id);
  166. CREATE INDEX EventActionExternalId on EventAction(external_id);
  167. CREATE INDEX EventActionFolderId on EventAction(external_folder_id);
  168. CREATE TABLE CalendarItem (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  169. summary TEXT,
  170. location_id INTEGER,
  171. description TEXT,
  172. start_date REAL,
  173. start_tz TEXT,
  174. end_date REAL,
  175. all_day INTEGER,
  176. calendar_id INTEGER,
  177. orig_item_id INTEGER,
  178. orig_date REAL,
  179. organizer_id INTEGER,
  180. self_attendee_id INTEGER,
  181. status INTEGER,
  182. invitation_status INTEGER,
  183. availability INTEGER,
  184. privacy_level INTEGER,
  185. url TEXT,
  186. last_modified REAL,
  187. sequence_num INTEGER,
  188. birthday_id INTEGER,
  189. modified_properties INTEGER,
  190. external_tracking_status INTEGER,
  191. external_id TEXT,
  192. external_mod_tag TEXT,
  193. unique_identifier TEXT,
  194. external_schedule_id TEXT,
  195. external_rep BLOB,
  196. response_comment TEXT,
  197. hidden INTEGER,
  198. has_recurrences INTEGER,
  199. has_attendees INTEGER,
  200. UUID TEXT,
  201. entity_type INTEGER,
  202. priority INTEGER,
  203. due_date REAL,
  204. due_tz TEXT,
  205. due_all_day INTEGER,
  206. completion_date REAL,
  207. creation_date REAL,
  208. conference TEXT,
  209. display_order INTEGER,
  210. created_by_id INTEGER,
  211. modified_by_id INTEGER,
  212. shared_item_created_date REAL,
  213. shared_item_created_tz TEXT,
  214. shared_item_modified_date REAL,
  215. shared_item_modified_tz TEXT,
  216. invitation_changed_properties INTEGER,
  217. default_alarm_removed INTEGER,
  218. phantom_master INTEGER);
  219. CREATE TABLE CalendarItemChanges (record INTEGER,
  220. type INTEGER,
  221. calendar_id INTEGER,
  222. external_id TEXT,
  223. unique_identifier TEXT,
  224. UUID TEXT,
  225. entity_type INTEGER,
  226. store_id INTEGER,
  227. has_dirty_instance_attributes INTEGER,
  228. old_calendar_id INTEGER,
  229. old_external_id TEXT);
  230. CREATE INDEX EventStatus on CalendarItem(status);
  231. CREATE INDEX EventHiddenEndDateStartDate on CalendarItem(hidden,
  232. end_date,
  233. start_date);
  234. CREATE INDEX EventCalendarIdHiddenEndDateStartDate on CalendarItem(calendar_id,
  235. hidden,
  236. end_date,
  237. start_date);
  238. CREATE INDEX EventExternalIdCalId on CalendarItem(external_id,
  239. calendar_id);
  240. CREATE INDEX EventExternalUniqueIdentifierCalId on CalendarItem(unique_identifier,
  241. calendar_id);
  242. CREATE INDEX EventUUID on CalendarItem(UUID);
  243. CREATE INDEX CalendarItemDueDate on CalendarItem(due_date);
  244. CREATE INDEX CalendarItemEntityTypeCompletionDate on CalendarItem(entity_type,
  245. completion_date);
  246. CREATE INDEX CalendarItemEntityTypeCalendarIdCompletionDateCreationDate on CalendarItem(entity_type,
  247. calendar_id,
  248. completion_date,
  249. creation_date);
  250. CREATE INDEX EventInvitationStatus on CalendarItem(invitation_status);
  251. CREATE INDEX CalendarItemOriginalItemId on CalendarItem(orig_item_id);
  252. CREATE INDEX CalendarItemOriginalDate on CalendarItem(orig_date);
  253. CREATE TRIGGER delete_event_alarms_recurs AFTER DELETE ON CalendarItem
  254. BEGIN
  255. DELETE FROM Location WHERE item_owner_id = OLD.ROWID;DELETE FROM Alarm WHERE owner_id = OLD.ROWID;DELETE FROM Recurrence WHERE owner_id = OLD.ROWID;DELETE FROM Participant WHERE owner_id = OLD.ROWID;DELETE FROM ExceptionDate WHERE owner_id = OLD.ROWID;DELETE FROM OccurrenceCache WHERE event_id = OLD.ROWID;DELETE FROM OccurrenceCacheDays WHERE count = 0;DELETE FROM Attachment WHERE owner_id = OLD.ROWID;
  256. END;
  257. CREATE TABLE ExceptionDate (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  258. owner_id INTEGER,
  259. date REAL,
  260. sync_order INTEGER);
  261. CREATE INDEX ExceptionDateOwnerId on ExceptionDate(owner_id);
  262. CREATE TABLE Attachment (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  263. owner_id INTEGER,
  264. external_id TEXT,
  265. external_mod_tag TEXT,
  266. external_rep BLOB,
  267. url TEXT,
  268. UUID TEXT,
  269. data BLOB,
  270. format TEXT,
  271. is_binary INTEGER,
  272. filename TEXT,
  273. local_url TEXT,
  274. file_size INTEGER);
  275. CREATE TABLE AttachmentChanges (record INTEGER,
  276. type INTEGER,
  277. owner_id INTEGER,
  278. external_id TEXT,
  279. external_mod_tag TEXT,
  280. UUID TEXT,
  281. store_id INTEGER,
  282. calendar_id INTEGER);
  283. CREATE INDEX AttachmentEventId on Attachment(owner_id);
  284. CREATE INDEX AttachmentUUID on Attachment(UUID);
  285. CREATE TABLE Category (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  286. name TEXT,
  287. entity_type INTEGER,
  288. hidden INTEGER);
  289. CREATE UNIQUE INDEX CategoryNameAndType on Category(name,
  290. entity_type);
  291. CREATE TABLE CategoryLink (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  292. owner_id INTEGER,
  293. category_id INTEGER);
  294. CREATE INDEX OwnerID on CategoryLink(owner_id);
  295. CREATE TABLE Location (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  296. title TEXT,
  297. latitude INTEGER,
  298. longitude INTEGER,
  299. address_book_id TEXT,
  300. radius INTEGER,
  301. item_owner_id INTEGER,
  302. alarm_owner_id INTEGER);
  303. CREATE INDEX LocationOwnerItemId on Location(item_owner_id);
  304. CREATE TABLE Sharee (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  305. owner_id INTEGER,
  306. external_id TEXT,
  307. external_rep BLOB,
  308. UUID TEXT,
  309. identity_id INTEGER,
  310. status INTEGER,
  311. access_level INTEGER);
  312. CREATE TABLE ShareeChanges (record INTEGER,
  313. type INTEGER,
  314. owner_id INTEGER,
  315. UUID TEXT,
  316. status INTEGER,
  317. access_level INTEGER,
  318. display_name TEXT,
  319. address TEXT,
  320. store_id INTEGER,
  321. calendar_id INTEGER,
  322. first_name TEXT,
  323. last_name TEXT);
  324. CREATE INDEX ShareeUUID on Sharee(UUID);
  325. CREATE INDEX ShareeOwnerId on Sharee(owner_id);
  326. CREATE INDEX ShareeStatus on Sharee(status);
  327. CREATE INDEX ShareeAccessLevel on Sharee(access_level);
  328. CREATE TABLE Notification (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  329. entity_type INTEGER,
  330. calendar_id INTEGER,
  331. external_id TEXT,
  332. external_mod_tag TEXT,
  333. UUID TEXT,
  334. summary TEXT,
  335. creation_date REAL,
  336. last_modified REAL,
  337. status INTEGER,
  338. host_url TEXT,
  339. in_reply_to TEXT,
  340. identity_id INTEGER,
  341. alerted INTEGER);
  342. CREATE TABLE NotificationChanges (record INTEGER,
  343. type INTEGER,
  344. entity_type INTEGER,
  345. calendar_id INTEGER,
  346. external_id TEXT,
  347. UUID TEXT,
  348. store_id INTEGER);
  349. CREATE INDEX NotificationUUIDCalendarId on Notification(UUID,
  350. calendar_id);
  351. CREATE INDEX NotificationEntityType on Notification(entity_type);
  352. CREATE INDEX NotificationExternalIDCalendarId on Notification(external_id,
  353. calendar_id);
  354. CREATE INDEX NotificationCalendarId on Notification(calendar_id);
  355. CREATE TRIGGER delete_resource_changes_for_notification AFTER DELETE ON Notification
  356. BEGIN
  357. DELETE FROM ResourceChange WHERE notification_id NOT IN (SELECT ROWID FROM Notification WHERE entity_type = 17);
  358. END;
  359. CREATE TABLE ResourceChange (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  360. notification_id INTEGER,
  361. calendar_id INTEGER,
  362. calendar_item_id INTEGER,
  363. identity_id INTEGER,
  364. change_type INTEGER,
  365. timestamp REAL,
  366. changed_properties INTEGER,
  367. create_count INTEGER,
  368. update_count INTEGER,
  369. delete_count INTEGER,
  370. deleted_summary TEXT,
  371. deleted_start_date REAL,
  372. alerted INTEGER,
  373. public_status INTEGER);
  374. CREATE INDEX ResourceChangeNotificationID on ResourceChange(notification_id);
  375. CREATE INDEX ResourceChangeCalendarID on ResourceChange(calendar_item_id);
  376. CREATE INDEX ResourceChangeCalendarItemID on ResourceChange(calendar_item_id);
  377. CREATE INDEX ResourceChangeIdentityID on ResourceChange(identity_id);
  378. CREATE TRIGGER delete_notification_calendar AFTER DELETE ON ResourceChange
  379. BEGIN
  380. DELETE FROM ResourceChange WHERE calendar_id NOT IN (SELECT ROWID FROM Calendar);
  381. END;
  382. CREATE TABLE OccurrenceCache (day REAL,
  383. event_id INTEGER,
  384. calendar_id INTEGER,
  385. store_id INTEGER,
  386. occurrence_date REAL,
  387. occurrence_start_date REAL,
  388. occurrence_end_date REAL);
  389. CREATE TABLE OccurrenceCacheDays (calendar_id INTEGER,
  390. store_id INTEGER,
  391. day REAL,
  392. count INTEGER,
  393. PRIMARY KEY (calendar_id,
  394. day));
  395. CREATE TRIGGER update_cache_days_after_delete AFTER DELETE ON OccurrenceCache
  396. BEGIN
  397. UPDATE OccurrenceCacheDays SET count = count - 1 WHERE day = OLD.day AND calendar_id = OLD.calendar_id;UPDATE OccurrenceCacheDays SET count = count - 1 WHERE day = OLD.day AND calendar_id = -2;
  398. END;
  399. CREATE TRIGGER update_cache_days_after_insert AFTER INSERT ON OccurrenceCache
  400. BEGIN
  401. REPLACE INTO OccurrenceCacheDays VALUES (NEW.calendar_id,
  402. NEW.store_id,
  403. NEW.day,
  404. 1 + IFNULL((SELECT count FROM OccurrenceCacheDays WHERE day = NEW.day AND calendar_id = NEW.calendar_id),
  405. 0));
  406. REPLACE INTO OccurrenceCacheDays VALUES (-2,
  407. -2,
  408. NEW.day,
  409. 1 + IFNULL((SELECT count FROM OccurrenceCacheDays WHERE day = NEW.day AND calendar_id = -2),
  410. 0));
  411. END;
  412. CREATE TRIGGER update_cache_days_after_update AFTER UPDATE OF day ON OccurrenceCache
  413. BEGIN
  414. REPLACE INTO OccurrenceCacheDays VALUES (NEW.calendar_id,
  415. NEW.store_id,
  416. NEW.day,
  417. 1 + IFNULL((SELECT count FROM OccurrenceCacheDays WHERE day = NEW.day AND calendar_id = NEW.calendar_id),
  418. 0));
  419. REPLACE INTO OccurrenceCacheDays VALUES (-2,
  420. -2,
  421. NEW.day,
  422. 1 + IFNULL((SELECT count FROM OccurrenceCacheDays WHERE day = NEW.day AND calendar_id = -2),
  423. 0));
  424. UPDATE OccurrenceCacheDays SET count = count - 1 WHERE day = OLD.day AND calendar_id = OLD.calendar_id;UPDATE OccurrenceCacheDays SET count = count - 1 WHERE day = OLD.day AND calendar_id = -2;
  425. END;
  426. CREATE INDEX OccurrenceCacheDay on OccurrenceCache(day);
  427. CREATE INDEX OccurrenceCacheDayCalendarId on OccurrenceCache(day,
  428. calendar_id);
  429. CREATE INDEX OccurrenceCacheDayStoreId on OccurrenceCache(day,
  430. store_id);
  431. CREATE INDEX OccurrenceCacheOccurrenceDate on OccurrenceCache(occurrence_date);
  432. CREATE INDEX OccurrenceCacheStoreIdOccurrenceDate on OccurrenceCache(store_id,
  433. occurrence_date);
  434. CREATE INDEX OccurrenceCacheCalendarIdOccurrenceDate on OccurrenceCache(calendar_id,
  435. occurrence_date);
  436. CREATE INDEX OccurrenceCacheEventId on OccurrenceCache(event_id);
  437. CREATE INDEX OccurrenceCacheDaysStoreIdDay on OccurrenceCacheDays(store_id,
  438. day);
  439. CREATE INDEX OccurrenceCacheDaysCount on OccurrenceCacheDays(count);