04_event_auth_chains.sql 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Copyright 2020 The Matrix.org Foundation C.I.C
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. -- See docs/auth_chain_difference_algorithm.md
  16. CREATE TABLE event_auth_chains (
  17. event_id TEXT PRIMARY KEY,
  18. chain_id BIGINT NOT NULL,
  19. sequence_number BIGINT NOT NULL
  20. );
  21. CREATE UNIQUE INDEX event_auth_chains_c_seq_index ON event_auth_chains (chain_id, sequence_number);
  22. CREATE TABLE event_auth_chain_links (
  23. origin_chain_id BIGINT NOT NULL,
  24. origin_sequence_number BIGINT NOT NULL,
  25. target_chain_id BIGINT NOT NULL,
  26. target_sequence_number BIGINT NOT NULL
  27. );
  28. CREATE INDEX event_auth_chain_links_idx ON event_auth_chain_links (origin_chain_id, target_chain_id);
  29. -- Events that we have persisted but not calculated auth chains for,
  30. -- e.g. out of band memberships (where we don't have the auth chain)
  31. CREATE TABLE event_auth_chain_to_calculate (
  32. event_id TEXT PRIMARY KEY,
  33. room_id TEXT NOT NULL,
  34. type TEXT NOT NULL,
  35. state_key TEXT NOT NULL
  36. );
  37. CREATE INDEX event_auth_chain_to_calculate_rm_id ON event_auth_chain_to_calculate(room_id);
  38. -- Whether we've calculated the above index for a room.
  39. ALTER TABLE rooms ADD COLUMN has_auth_chain_index BOOLEAN;