2015-03-04 14:34:38 +01:00
|
|
|
/* Copyright 2014, 2015 OpenMarket Ltd
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS event_forward_extremities(
|
2015-04-02 11:06:22 +02:00
|
|
|
event_id VARCHAR(150) NOT NULL,
|
|
|
|
room_id VARCHAR(150) NOT NULL,
|
2015-03-18 12:18:49 +01:00
|
|
|
UNIQUE (event_id, room_id)
|
2015-04-01 15:12:33 +02:00
|
|
|
) ;
|
2015-03-04 14:34:38 +01:00
|
|
|
|
|
|
|
CREATE INDEX IF NOT EXISTS ev_extrem_room ON event_forward_extremities(room_id);
|
|
|
|
CREATE INDEX IF NOT EXISTS ev_extrem_id ON event_forward_extremities(event_id);
|
|
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS event_backward_extremities(
|
2015-04-02 11:06:22 +02:00
|
|
|
event_id VARCHAR(150) NOT NULL,
|
|
|
|
room_id VARCHAR(150) NOT NULL,
|
2015-03-18 12:18:49 +01:00
|
|
|
UNIQUE (event_id, room_id)
|
2015-04-01 15:12:33 +02:00
|
|
|
) ;
|
2015-03-04 14:34:38 +01:00
|
|
|
|
|
|
|
CREATE INDEX IF NOT EXISTS ev_b_extrem_room ON event_backward_extremities(room_id);
|
|
|
|
CREATE INDEX IF NOT EXISTS ev_b_extrem_id ON event_backward_extremities(event_id);
|
|
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS event_edges(
|
2015-04-02 11:06:22 +02:00
|
|
|
event_id VARCHAR(150) NOT NULL,
|
|
|
|
prev_event_id VARCHAR(150) NOT NULL,
|
|
|
|
room_id VARCHAR(150) NOT NULL,
|
2015-03-18 12:18:49 +01:00
|
|
|
is_state BOOL NOT NULL,
|
|
|
|
UNIQUE (event_id, prev_event_id, room_id, is_state)
|
2015-04-01 15:12:33 +02:00
|
|
|
) ;
|
2015-03-04 14:34:38 +01:00
|
|
|
|
|
|
|
CREATE INDEX IF NOT EXISTS ev_edges_id ON event_edges(event_id);
|
|
|
|
CREATE INDEX IF NOT EXISTS ev_edges_prev_id ON event_edges(prev_event_id);
|
|
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS room_depth(
|
2015-04-02 11:06:22 +02:00
|
|
|
room_id VARCHAR(150) NOT NULL,
|
2015-03-04 14:34:38 +01:00
|
|
|
min_depth INTEGER NOT NULL,
|
2015-03-18 12:18:49 +01:00
|
|
|
UNIQUE (room_id)
|
2015-04-01 15:12:33 +02:00
|
|
|
) ;
|
2015-03-04 14:34:38 +01:00
|
|
|
|
|
|
|
CREATE INDEX IF NOT EXISTS room_depth_room ON room_depth(room_id);
|
|
|
|
|
|
|
|
|
|
|
|
create TABLE IF NOT EXISTS event_destinations(
|
2015-04-02 11:06:22 +02:00
|
|
|
event_id VARCHAR(150) NOT NULL,
|
|
|
|
destination VARCHAR(150) NOT NULL,
|
2015-03-19 14:42:39 +01:00
|
|
|
delivered_ts BIGINT DEFAULT 0, -- or 0 if not delivered
|
2015-03-18 12:18:49 +01:00
|
|
|
UNIQUE (event_id, destination)
|
2015-04-01 15:12:33 +02:00
|
|
|
) ;
|
2015-03-04 14:34:38 +01:00
|
|
|
|
|
|
|
CREATE INDEX IF NOT EXISTS event_destinations_id ON event_destinations(event_id);
|
|
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS state_forward_extremities(
|
2015-04-02 11:06:22 +02:00
|
|
|
event_id VARCHAR(150) NOT NULL,
|
|
|
|
room_id VARCHAR(150) NOT NULL,
|
|
|
|
type VARCHAR(150) NOT NULL,
|
|
|
|
state_key VARCHAR(150) NOT NULL,
|
2015-03-18 12:18:49 +01:00
|
|
|
UNIQUE (event_id, room_id)
|
2015-04-01 15:12:33 +02:00
|
|
|
) ;
|
2015-03-04 14:34:38 +01:00
|
|
|
|
|
|
|
CREATE INDEX IF NOT EXISTS st_extrem_keys ON state_forward_extremities(
|
|
|
|
room_id, type, state_key
|
2015-03-20 11:55:31 +01:00
|
|
|
);
|
2015-03-04 14:34:38 +01:00
|
|
|
CREATE INDEX IF NOT EXISTS st_extrem_id ON state_forward_extremities(event_id);
|
|
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS event_auth(
|
2015-04-02 11:06:22 +02:00
|
|
|
event_id VARCHAR(150) NOT NULL,
|
|
|
|
auth_id VARCHAR(150) NOT NULL,
|
|
|
|
room_id VARCHAR(150) NOT NULL,
|
2015-03-18 12:18:49 +01:00
|
|
|
UNIQUE (event_id, auth_id, room_id)
|
2015-04-01 15:12:33 +02:00
|
|
|
) ;
|
2015-03-04 14:34:38 +01:00
|
|
|
|
|
|
|
CREATE INDEX IF NOT EXISTS evauth_edges_id ON event_auth(event_id);
|
2015-03-18 12:18:49 +01:00
|
|
|
CREATE INDEX IF NOT EXISTS evauth_edges_auth_id ON event_auth(auth_id);
|