calendars_10.3.3.sql 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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. creator_bundle_id TEXT,
  14. creator_code_signing_identity TEXT,
  15. only_creator_can_modify INTEGER,
  16. external_mod_tag TEXT,
  17. preferred_event_private_value INTEGER,
  18. strictest_event_private_value INTEGER);
  19. CREATE TABLE sqlite_sequence(name,seq);
  20. CREATE TABLE StoreChanges (record INTEGER,
  21. type INTEGER,
  22. sequence_number INTEGER);
  23. CREATE TRIGGER delete_store_members AFTER DELETE ON Store
  24. BEGIN
  25. DELETE FROM Calendar WHERE store_id = OLD.ROWID;
  26. END;
  27. CREATE TRIGGER delete_store_changes AFTER DELETE ON Store
  28. BEGIN
  29. 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;
  30. END;
  31. CREATE INDEX StoreExternalId on Store(external_id);
  32. CREATE TABLE Calendar (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  33. store_id INTEGER,
  34. title TEXT,
  35. flags INTEGER,
  36. color TEXT,
  37. symbolic_color_name TEXT,
  38. color_is_display INTEGER,
  39. type TEXT,
  40. supported_entity_types INTEGER,
  41. external_id TEXT,
  42. external_mod_tag TEXT,
  43. external_id_tag TEXT,
  44. external_rep BLOB,
  45. display_order INTEGER,
  46. UUID TEXT,
  47. shared_owner_name TEXT,
  48. shared_owner_email TEXT,
  49. sharing_status INTEGER,
  50. sharing_invitation_response INTEGER,
  51. published_URL TEXT,
  52. is_published INTEGER,
  53. invitation_status INTEGER,
  54. sync_token TEXT,
  55. self_identity_id INTEGER,
  56. self_identity_email TEXT,
  57. owner_identity_id INTEGER,
  58. owner_identity_email TEXT,
  59. notes TEXT,
  60. bulk_requests BLOB,
  61. subcal_account_id TEXT,
  62. push_key TEXT,
  63. digest BLOB);
  64. CREATE TABLE CalendarChanges (record INTEGER,
  65. type INTEGER,
  66. sequence_number INTEGER,
  67. store_id INTEGER,
  68. flags INTEGER,
  69. external_id TEXT,
  70. external_id_tag TEXT,
  71. UUID TEXT);
  72. CREATE INDEX CalendarExternalId on Calendar(external_id);
  73. CREATE INDEX CalendarStoreId on Calendar(store_id);
  74. CREATE INDEX CalendarUUID on Calendar(UUID);
  75. CREATE INDEX CalendarSelfIdentityId on Calendar(self_identity_id);
  76. CREATE TRIGGER delete_calendar_members AFTER DELETE ON Calendar
  77. BEGIN
  78. 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;DELETE FROM Alarm WHERE calendar_owner_id = OLD.ROWID;
  79. END;
  80. CREATE TABLE Recurrence (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  81. frequency INTEGER,
  82. interval INTEGER,
  83. week_start INTEGER,
  84. count INTEGER,
  85. cached_end_date REAL,
  86. cached_end_date_tz TEXT,
  87. end_date REAL,
  88. specifier TEXT,
  89. by_month_months INTEGER,
  90. owner_id INTEGER,
  91. external_id TEXT,
  92. external_mod_tag TEXT,
  93. external_id_tag TEXT,
  94. external_rep BLOB,
  95. UUID TEXT);
  96. CREATE TABLE RecurrenceChanges (record INTEGER,
  97. type INTEGER,
  98. sequence_number INTEGER,
  99. external_id TEXT,
  100. store_id INTEGER,
  101. event_id_tomb INTEGER,
  102. calendar_id INTEGER,
  103. end_date_tomb REAL,
  104. UUID TEXT);
  105. CREATE INDEX RecurrenceEndCountIndex on Recurrence(end_date,
  106. count);
  107. CREATE INDEX RecurrenceExternalId on Recurrence(external_id);
  108. CREATE INDEX RecurrenceOwnerIdIndex on Recurrence(owner_id);
  109. CREATE INDEX RecurrenceUUID on Recurrence(UUID);
  110. CREATE TABLE Alarm (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  111. trigger_date REAL,
  112. trigger_interval INTEGER,
  113. type INTEGER,
  114. calendaritem_owner_id INTEGER,
  115. calendar_owner_id INTEGER,
  116. external_id TEXT,
  117. external_mod_tag TEXT,
  118. external_id_tag TEXT,
  119. external_rep BLOB,
  120. UUID TEXT,
  121. proximity INTEGER,
  122. disabled INTEGER,
  123. location_id INTEGER,
  124. acknowledgedDate REAL,
  125. default_alarm INTEGER,
  126. orig_alarm_id INTEGER);
  127. CREATE TABLE AlarmChanges (record INTEGER,
  128. type INTEGER,
  129. sequence_number INTEGER,
  130. calendaritem_owner_id INTEGER,
  131. calendar_owner_id INTEGER,
  132. external_id TEXT,
  133. store_id INTEGER,
  134. calendar_id INTEGER,
  135. UUID TEXT);
  136. CREATE INDEX AlarmExternalId on Alarm(external_id);
  137. CREATE INDEX AlarmUUID on Alarm(UUID);
  138. CREATE INDEX AlarmTriggerDate on Alarm(trigger_date);
  139. CREATE INDEX AlarmCalendarItemOwnerId on Alarm(calendaritem_owner_id);
  140. CREATE INDEX AlarmCalendarOwnerId on Alarm(calendar_owner_id);
  141. CREATE TRIGGER cascade_alarm_delete AFTER DELETE ON Alarm
  142. BEGIN
  143. DELETE FROM Location WHERE alarm_owner_id = OLD.ROWID;
  144. END;
  145. CREATE TABLE Participant (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  146. entity_type INTEGER,
  147. type INTEGER,
  148. status INTEGER,
  149. pending_status INTEGER,
  150. role INTEGER,
  151. identity_id INTEGER,
  152. owner_id INTEGER,
  153. external_rep BLOB,
  154. UUID TEXT,
  155. email TEXT,
  156. is_self INTEGER,
  157. comment TEXT,
  158. schedule_agent INTEGER,
  159. flags INTEGER,
  160. last_modified REAL,
  161. proposed_start_date REAL,
  162. invited_by TEXT,
  163. proposed_start_date_status INTEGER,
  164. comment_last_modified REAL);
  165. CREATE TABLE ParticipantChanges (record INTEGER,
  166. type INTEGER,
  167. sequence_number INTEGER,
  168. entity_type INTEGER,
  169. owner_id INTEGER,
  170. UUID TEXT,
  171. email TEXT,
  172. comment TEXT,
  173. store_id INTEGER,
  174. calendar_id INTEGER);
  175. CREATE INDEX ParticipantUUID on Participant(UUID);
  176. CREATE INDEX ParticipantEntityType on Participant(entity_type);
  177. CREATE INDEX ParticipantOwnerId on Participant(owner_id);
  178. CREATE INDEX ParticipantIdentityId on Participant(identity_id);
  179. CREATE INDEX ParticipantEmail on Participant(email);
  180. CREATE TABLE Identity (display_name TEXT,
  181. address TEXT,
  182. first_name TEXT,
  183. last_name TEXT,
  184. UNIQUE (display_name,
  185. address,
  186. first_name,
  187. last_name));
  188. CREATE TABLE EventAction (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  189. event_id INTEGER,
  190. external_id TEXT,
  191. external_mod_tag TEXT,
  192. external_folder_id TEXT,
  193. external_schedule_id TEXT,
  194. external_rep BLOB);
  195. CREATE TABLE EventActionChanges (record INTEGER,
  196. type INTEGER,
  197. sequence_number INTEGER,
  198. event_id INTEGER,
  199. external_id TEXT,
  200. external_folder_id TEXT,
  201. external_schedule_id TEXT,
  202. store_id INTEGER,
  203. calendar_id INTEGER);
  204. CREATE INDEX EventActionEventId on EventAction(event_id);
  205. CREATE INDEX EventActionExternalId on EventAction(external_id);
  206. CREATE INDEX EventActionFolderId on EventAction(external_folder_id);
  207. CREATE TABLE CalendarItem (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  208. summary TEXT,
  209. location_id INTEGER,
  210. client_location_id INTEGER,
  211. description TEXT,
  212. start_date REAL,
  213. start_tz TEXT,
  214. end_date REAL,
  215. end_tz TEXT,
  216. all_day INTEGER,
  217. calendar_id INTEGER,
  218. orig_item_id INTEGER,
  219. orig_date REAL,
  220. organizer_id INTEGER,
  221. self_attendee_id INTEGER,
  222. status INTEGER,
  223. invitation_status INTEGER,
  224. availability INTEGER,
  225. privacy_level INTEGER,
  226. url TEXT,
  227. last_modified REAL,
  228. sequence_num INTEGER,
  229. birthday_id INTEGER,
  230. modified_properties INTEGER,
  231. external_tracking_status INTEGER,
  232. external_id TEXT,
  233. external_mod_tag TEXT,
  234. unique_identifier TEXT,
  235. external_schedule_id TEXT,
  236. external_rep BLOB,
  237. response_comment TEXT,
  238. last_synced_response_comment TEXT,
  239. hidden INTEGER,
  240. has_recurrences INTEGER,
  241. has_attendees INTEGER,
  242. UUID TEXT,
  243. entity_type INTEGER,
  244. priority INTEGER,
  245. due_date REAL,
  246. due_tz TEXT,
  247. due_all_day INTEGER,
  248. completion_date REAL,
  249. creation_date REAL,
  250. conference TEXT,
  251. app_link BLOB,
  252. display_order INTEGER,
  253. created_by_id INTEGER,
  254. modified_by_id INTEGER,
  255. shared_item_created_date REAL,
  256. shared_item_created_tz TEXT,
  257. shared_item_modified_date REAL,
  258. shared_item_modified_tz TEXT,
  259. invitation_changed_properties INTEGER,
  260. default_alarm_removed INTEGER,
  261. phantom_master INTEGER,
  262. participation_status_modified_date REAL,
  263. calendar_scale TEXT,
  264. travel_time INTEGER,
  265. travel_advisory_behavior INTEGER,
  266. start_location_id INTEGER,
  267. suggested_event_info_id INTEGER,
  268. first_alert_date REAL,
  269. proposed_start_date REAL,
  270. can_forward INTEGER,
  271. location_prediction_state INTEGER,
  272. fired_ttl INTEGER,
  273. disallow_propose_new_time INTEGER,
  274. junk_status INTEGER);
  275. CREATE TABLE CalendarItemChanges (record INTEGER,
  276. type INTEGER,
  277. sequence_number INTEGER,
  278. calendar_id INTEGER,
  279. external_id TEXT,
  280. unique_identifier TEXT,
  281. UUID TEXT,
  282. entity_type INTEGER,
  283. store_id INTEGER,
  284. has_dirty_instance_attributes INTEGER,
  285. old_calendar_id INTEGER,
  286. old_external_id TEXT);
  287. CREATE INDEX EventStatus on CalendarItem(status);
  288. CREATE INDEX EventHiddenEndDateStartDate on CalendarItem(hidden,
  289. end_date,
  290. start_date);
  291. CREATE INDEX EventExternalIdCalId on CalendarItem(external_id,
  292. calendar_id);
  293. CREATE INDEX EventExternalUniqueIdentifierCalId on CalendarItem(unique_identifier,
  294. calendar_id);
  295. CREATE INDEX EventUUID on CalendarItem(UUID);
  296. CREATE INDEX CalendarItemDueDate on CalendarItem(due_date);
  297. CREATE INDEX CalendarItemEntityTypeCompletionDate on CalendarItem(entity_type,
  298. completion_date);
  299. CREATE INDEX CalendarItemEntityTypeCalendarIdCompletionDateCreationDate on CalendarItem(entity_type,
  300. calendar_id,
  301. completion_date,
  302. creation_date);
  303. CREATE INDEX EventInvitationStatus on CalendarItem(invitation_status);
  304. CREATE INDEX CalendarItemOriginalItemId on CalendarItem(orig_item_id);
  305. CREATE INDEX CalendarItemOriginalDate on CalendarItem(orig_date);
  306. CREATE TRIGGER delete_event_alarms_recurs AFTER DELETE ON CalendarItem
  307. BEGIN
  308. DELETE FROM Location WHERE item_owner_id = OLD.ROWID;DELETE FROM Alarm WHERE calendaritem_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;DELETE FROM ScheduledTaskCache WHERE task_id = OLD.ROWID;DELETE FROM EventAction WHERE event_id = OLD.ROWID;DELETE FROM SuggestedEventInfo WHERE ROWID = OLD.suggested_event_info_id;
  309. END;
  310. CREATE TABLE ExceptionDate (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  311. owner_id INTEGER,
  312. date REAL,
  313. sync_order INTEGER);
  314. CREATE INDEX ExceptionDateOwnerId on ExceptionDate(owner_id);
  315. CREATE TABLE Attachment (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  316. owner_id INTEGER,
  317. external_id TEXT,
  318. external_mod_tag TEXT,
  319. external_rep BLOB,
  320. url TEXT,
  321. UUID TEXT,
  322. data BLOB,
  323. format TEXT,
  324. is_binary INTEGER,
  325. filename TEXT,
  326. local_url TEXT,
  327. file_size INTEGER);
  328. CREATE TABLE AttachmentChanges (record INTEGER,
  329. type INTEGER,
  330. sequence_number INTEGER,
  331. owner_id INTEGER,
  332. external_id TEXT,
  333. external_mod_tag TEXT,
  334. UUID TEXT,
  335. store_id INTEGER,
  336. calendar_id INTEGER);
  337. CREATE INDEX AttachmentEventId on Attachment(owner_id);
  338. CREATE INDEX AttachmentUUID on Attachment(UUID);
  339. CREATE TABLE Category (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  340. name TEXT,
  341. entity_type INTEGER,
  342. hidden INTEGER);
  343. CREATE UNIQUE INDEX CategoryNameAndType on Category(name,
  344. entity_type);
  345. CREATE TABLE CategoryLink (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  346. owner_id INTEGER,
  347. category_id INTEGER);
  348. CREATE INDEX OwnerID on CategoryLink(owner_id);
  349. CREATE TABLE Location (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  350. title TEXT,
  351. address TEXT,
  352. latitude INTEGER,
  353. longitude INTEGER,
  354. reference_frame INTEGER,
  355. address_book_id TEXT,
  356. mapkit_handle BLOB,
  357. radius INTEGER,
  358. routing TEXT,
  359. derived_from TEXT,
  360. item_owner_id INTEGER,
  361. alarm_owner_id INTEGER);
  362. CREATE INDEX LocationOwnerItemId on Location(item_owner_id);
  363. CREATE TABLE Sharee (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  364. owner_id INTEGER,
  365. external_id TEXT,
  366. external_rep BLOB,
  367. UUID TEXT,
  368. identity_id INTEGER,
  369. status INTEGER,
  370. access_level INTEGER);
  371. CREATE TABLE ShareeChanges (record INTEGER,
  372. type INTEGER,
  373. sequence_number INTEGER,
  374. owner_id INTEGER,
  375. UUID TEXT,
  376. status INTEGER,
  377. access_level INTEGER,
  378. display_name TEXT,
  379. address TEXT,
  380. store_id INTEGER,
  381. calendar_id INTEGER,
  382. first_name TEXT,
  383. last_name TEXT);
  384. CREATE INDEX ShareeUUID on Sharee(UUID);
  385. CREATE INDEX ShareeOwnerId on Sharee(owner_id);
  386. CREATE INDEX ShareeStatus on Sharee(status);
  387. CREATE INDEX ShareeAccessLevel on Sharee(access_level);
  388. CREATE INDEX ShareeIdentityId on Sharee(identity_id);
  389. CREATE TABLE Notification (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  390. entity_type INTEGER,
  391. calendar_id INTEGER,
  392. external_id TEXT,
  393. external_mod_tag TEXT,
  394. UUID TEXT,
  395. summary TEXT,
  396. creation_date REAL,
  397. last_modified REAL,
  398. status INTEGER,
  399. host_url TEXT,
  400. in_reply_to TEXT,
  401. identity_id INTEGER,
  402. alerted INTEGER);
  403. CREATE TABLE NotificationChanges (record INTEGER,
  404. type INTEGER,
  405. sequence_number INTEGER,
  406. entity_type INTEGER,
  407. calendar_id INTEGER,
  408. external_id TEXT,
  409. UUID TEXT,
  410. store_id INTEGER);
  411. CREATE INDEX NotificationUUIDCalendarId on Notification(UUID,
  412. calendar_id);
  413. CREATE INDEX NotificationEntityType on Notification(entity_type);
  414. CREATE INDEX NotificationExternalIDCalendarId on Notification(external_id,
  415. calendar_id);
  416. CREATE INDEX NotificationCalendarId on Notification(calendar_id);
  417. CREATE TRIGGER delete_resource_changes_for_notification AFTER DELETE ON Notification
  418. BEGIN
  419. DELETE FROM ResourceChange WHERE notification_id NOT IN (SELECT ROWID FROM Notification WHERE entity_type = 17 OR entity_type = 19);
  420. END;
  421. CREATE TABLE ResourceChange (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  422. notification_id INTEGER,
  423. calendar_id INTEGER,
  424. calendar_item_id INTEGER,
  425. identity_id INTEGER,
  426. change_type INTEGER,
  427. timestamp REAL,
  428. changed_properties INTEGER,
  429. create_count INTEGER,
  430. update_count INTEGER,
  431. delete_count INTEGER,
  432. deleted_summary TEXT,
  433. deleted_start_date REAL,
  434. alerted INTEGER,
  435. public_status INTEGER);
  436. CREATE INDEX ResourceChangeNotificationID on ResourceChange(notification_id);
  437. CREATE INDEX ResourceChangeCalendarID on ResourceChange(calendar_item_id);
  438. CREATE INDEX ResourceChangeCalendarItemID on ResourceChange(calendar_item_id);
  439. CREATE INDEX ResourceChangeIdentityID on ResourceChange(identity_id);
  440. CREATE TRIGGER delete_notification_calendar AFTER DELETE ON ResourceChange
  441. BEGIN
  442. DELETE FROM ResourceChange WHERE calendar_id NOT IN (SELECT ROWID FROM Calendar);
  443. END;
  444. CREATE TABLE SuggestedEventInfo (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  445. owner_id INTEGER,
  446. opaque_key TEXT,
  447. unique_key TEXT,
  448. changed_fields INTEGER,
  449. changes_acknowledged INTEGER,
  450. timestamp REAL);
  451. CREATE INDEX SuggestedEventInfoOwnerId on SuggestedEventInfo(owner_id);
  452. CREATE TABLE Contact (ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  453. owner_id INTEGER,
  454. contact_id TEXT);
  455. CREATE TABLE ContactChanges (record INTEGER,
  456. type INTEGER,
  457. sequence_number INTEGER,
  458. owner_id INTEGER,
  459. contact_id TEXT,
  460. store_id INTEGER,
  461. calendar_id INTEGER);
  462. CREATE INDEX ContactID on Contact(contact_id);
  463. CREATE TABLE OccurrenceCache (day REAL,
  464. event_id INTEGER,
  465. calendar_id INTEGER,
  466. store_id INTEGER,
  467. occurrence_date REAL,
  468. occurrence_start_date REAL,
  469. occurrence_end_date REAL);
  470. CREATE TABLE OccurrenceCacheDays (calendar_id INTEGER,
  471. store_id INTEGER,
  472. day REAL,
  473. count INTEGER,
  474. PRIMARY KEY (calendar_id,
  475. day));
  476. CREATE TRIGGER update_cache_days_after_delete AFTER DELETE ON OccurrenceCache
  477. BEGIN
  478. 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;
  479. END;
  480. CREATE TRIGGER update_cache_days_after_insert AFTER INSERT ON OccurrenceCache
  481. BEGIN
  482. REPLACE INTO OccurrenceCacheDays VALUES (NEW.calendar_id,
  483. NEW.store_id,
  484. NEW.day,
  485. 1 + IFNULL((SELECT count FROM OccurrenceCacheDays WHERE day = NEW.day AND calendar_id = NEW.calendar_id),
  486. 0));
  487. REPLACE INTO OccurrenceCacheDays VALUES (-2,
  488. -2,
  489. NEW.day,
  490. 1 + IFNULL((SELECT count FROM OccurrenceCacheDays WHERE day = NEW.day AND calendar_id = -2),
  491. 0));
  492. END;
  493. CREATE TRIGGER update_cache_days_after_update AFTER UPDATE OF day ON OccurrenceCache
  494. BEGIN
  495. REPLACE INTO OccurrenceCacheDays VALUES (NEW.calendar_id,
  496. NEW.store_id,
  497. NEW.day,
  498. 1 + IFNULL((SELECT count FROM OccurrenceCacheDays WHERE day = NEW.day AND calendar_id = NEW.calendar_id),
  499. 0));
  500. REPLACE INTO OccurrenceCacheDays VALUES (-2,
  501. -2,
  502. NEW.day,
  503. 1 + IFNULL((SELECT count FROM OccurrenceCacheDays WHERE day = NEW.day AND calendar_id = -2),
  504. 0));
  505. 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;
  506. END;
  507. CREATE INDEX OccurrenceCacheDayEventIdOccurrenceDate on OccurrenceCache(day,
  508. event_id,
  509. occurrence_date);
  510. CREATE INDEX OccurrenceCacheOccurrenceDateEventId on OccurrenceCache(occurrence_date,
  511. event_id);
  512. CREATE INDEX OccurrenceCacheCalendarId on OccurrenceCache(calendar_id);
  513. CREATE INDEX OccurrenceCacheDaysCount on OccurrenceCacheDays(count);
  514. CREATE INDEX OccurrenceCacheDaysDayCalendarId on OccurrenceCacheDays(day,
  515. calendar_id);
  516. CREATE TABLE ScheduledTaskCache (day REAL,
  517. date_for_sorting REAL,
  518. completed INTEGER,
  519. task_id INTEGER,
  520. count INTEGER,
  521. PRIMARY KEY (day,
  522. task_id));
  523. CREATE TRIGGER update_task_cache_count_after_insert AFTER INSERT ON ScheduledTaskCache
  524. BEGIN
  525. REPLACE INTO ScheduledTaskCache VALUES (NEW.day,
  526. NULL,
  527. NULL,
  528. -2,
  529. 1 + IFNULL((SELECT count FROM ScheduledTaskCache WHERE day = NEW.day AND task_id = -2),
  530. 0));
  531. END;
  532. CREATE TRIGGER update_task_cache_count_after_update AFTER UPDATE OF day ON ScheduledTaskCache
  533. BEGIN
  534. UPDATE ScheduledTaskCache SET count = count - 1 WHERE day = OLD.day AND task_id = -2;
  535. REPLACE INTO ScheduledTaskCache VALUES (NEW.day,
  536. NULL,
  537. NULL,
  538. -2,
  539. IFNULL((SELECT count FROM ScheduledTaskCache WHERE day = NEW.day AND task_id = -2),
  540. 0));
  541. DELETE FROM ScheduledTaskCache WHERE day = OLD.day AND count = 0;
  542. END;
  543. CREATE TRIGGER update_task_cache_days_after_delete AFTER DELETE ON ScheduledTaskCache
  544. BEGIN
  545. UPDATE ScheduledTaskCache SET count = count - 1 WHERE day = OLD.day AND task_id = -2;
  546. DELETE FROM ScheduledTaskCache WHERE day = OLD.day AND count = 0;
  547. END;
  548. CREATE INDEX ScheduledTaskCacheDayTaskId on ScheduledTaskCache(day);
  549. CREATE INDEX ScheduledTaskCacheTaskId on ScheduledTaskCache(task_id);
  550. CREATE TABLE ClientCursor ( ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
  551. client_identifier TEXT,
  552. store_id INTEGER,
  553. latest_consumed_sequence_number INTEGER,
  554. latest_consumed_timestamp REAL,
  555. UNIQUE(client_identifier) );
  556. CREATE INDEX ClientCursorClientIdentifier ON ClientCursor(client_identifier);
  557. CREATE TABLE ClientSequence (client_identifier TEXT,
  558. sequence_number INTEGER );
  559. CREATE INDEX ClientSequenceClientIdentifier ON ClientSequence(client_identifier);
  560. CREATE TABLE ClientCursorConsumed ( client_identifier TEXT,
  561. consumed_entity_class INTEGER,
  562. consumed_entity_id INTEGER,
  563. consumed_change_id INTEGER,
  564. sequence_number INTEGER );
  565. CREATE INDEX ClientCursorConsumedClientIdentifier ON ClientCursorConsumed(client_identifier);
  566. CREATE TRIGGER delete_clientcursor_consumed AFTER DELETE ON ClientCursor BEGIN DELETE FROM ClientCursorConsumed WHERE client_identifier = OLD.client_identifier; DELETE FROM ClientSequence WHERE client_identifier = OLD.client_identifier; END;