summary refs log tree commit diff
path: root/synapse/storage/schema/delta/16/unique_constraints.sql
blob: f9fbb6b448da70f1018c6c0457dd5c43f9dee4b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- We can use SQLite features here, since mysql support was only added in v16

--
DELETE FROM current_state_events WHERE rowid not in (
    SELECT MIN(rowid) FROM current_state_events GROUP BY event_id
);

DROP INDEX IF EXISTS current_state_events_event_id;
CREATE UNIQUE INDEX current_state_events_event_id ON current_state_events(event_id);

--
DELETE FROM room_memberships WHERE rowid not in (
    SELECT MIN(rowid) FROM room_memberships GROUP BY event_id
);

DROP INDEX IF EXISTS room_memberships_event_id;
CREATE UNIQUE INDEX room_memberships_event_id ON room_memberships(event_id);

--
DELETE FROM feedback WHERE rowid not in (
    SELECT MIN(rowid) FROM feedback GROUP BY event_id
);

DROP INDEX IF EXISTS feedback_event_id;
CREATE UNIQUE INDEX feedback_event_id ON feedback(event_id);

--
DELETE FROM topics WHERE rowid not in (
    SELECT MIN(rowid) FROM topics GROUP BY event_id
);

DROP INDEX IF EXISTS topics_event_id;
CREATE UNIQUE INDEX topics_event_id ON topics(event_id);

--
DELETE FROM room_names WHERE rowid not in (
    SELECT MIN(rowid) FROM room_names GROUP BY event_id
);

DROP INDEX IF EXISTS room_names_id;
CREATE UNIQUE INDEX room_names_id ON room_names(event_id);

--
DELETE FROM presence WHERE rowid not in (
    SELECT MIN(rowid) FROM presence GROUP BY user_id
);

DROP INDEX IF EXISTS presence_id;
CREATE UNIQUE INDEX presence_id ON presence(user_id);

--
DELETE FROM presence_allow_inbound WHERE rowid not in (
    SELECT MIN(rowid) FROM presence_allow_inbound
    GROUP BY observed_user_id, observer_user_id
);

DROP INDEX IF EXISTS presence_allow_inbound_observers;
CREATE UNIQUE INDEX presence_allow_inbound_observers ON presence_allow_inbound(
    observed_user_id, observer_user_id
);

--
DELETE FROM presence_list WHERE rowid not in (
    SELECT MIN(rowid) FROM presence_list
    GROUP BY user_id, observed_user_id
);

DROP INDEX IF EXISTS presence_list_observers;
CREATE UNIQUE INDEX presence_list_observers ON presence_list(
    user_id, observed_user_id
);