2022-03-18-historysync-store.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package upgrades
  2. import (
  3. "database/sql"
  4. )
  5. func init() {
  6. upgrades[40] = upgrade{"Store history syncs for later backfills", func(tx *sql.Tx, ctx context) error {
  7. _, err := tx.Exec(`
  8. CREATE TABLE history_sync_conversation (
  9. user_mxid TEXT,
  10. conversation_id TEXT,
  11. portal_jid TEXT,
  12. portal_receiver TEXT,
  13. last_message_timestamp TIMESTAMP,
  14. archived BOOLEAN,
  15. pinned INTEGER,
  16. mute_end_time TIMESTAMP,
  17. disappearing_mode INTEGER,
  18. end_of_history_transfer_type INTEGER,
  19. ephemeral_expiration INTEGER,
  20. marked_as_unread BOOLEAN,
  21. unread_count INTEGER,
  22. PRIMARY KEY (user_mxid, conversation_id),
  23. FOREIGN KEY (user_mxid) REFERENCES "user"(mxid) ON DELETE CASCADE ON UPDATE CASCADE,
  24. FOREIGN KEY (portal_jid, portal_receiver) REFERENCES portal(jid, receiver) ON DELETE CASCADE ON UPDATE CASCADE
  25. )
  26. `)
  27. if err != nil {
  28. return err
  29. }
  30. _, err = tx.Exec(`
  31. CREATE TABLE history_sync_message (
  32. user_mxid TEXT,
  33. conversation_id TEXT,
  34. message_id TEXT,
  35. timestamp TIMESTAMP,
  36. data BYTEA,
  37. PRIMARY KEY (user_mxid, conversation_id, message_id),
  38. FOREIGN KEY (user_mxid) REFERENCES "user"(mxid) ON DELETE CASCADE ON UPDATE CASCADE,
  39. FOREIGN KEY (user_mxid, conversation_id) REFERENCES history_sync_conversation(user_mxid, conversation_id) ON DELETE CASCADE
  40. )
  41. `)
  42. if err != nil {
  43. return err
  44. }
  45. return nil
  46. }}
  47. }