calendars_11.2.sql 20 KB

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