summaryrefslogtreecommitdiff
path: root/synapse/storage/schema/full_schemas/54/full.sql.postgres
blob: 098434356f0c36831e08582746d757976b5c5a93 (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
CREATE TABLE access_tokens (
    id bigint NOT NULL,
    user_id text NOT NULL,
    device_id text,
    token text NOT NULL,
    last_used bigint
);



CREATE TABLE account_data (
    user_id text NOT NULL,
    account_data_type text NOT NULL,
    stream_id bigint NOT NULL,
    content text NOT NULL
);



CREATE TABLE account_data_max_stream_id (
    lock character(1) DEFAULT 'X'::bpchar NOT NULL,
    stream_id bigint NOT NULL,
    CONSTRAINT private_user_data_max_stream_id_lock_check CHECK ((lock = 'X'::bpchar))
);



CREATE TABLE account_validity (
    user_id text NOT NULL,
    expiration_ts_ms bigint NOT NULL,
    email_sent boolean NOT NULL,
    renewal_token text
);



CREATE TABLE application_services_state (
    as_id text NOT NULL,
    state character varying(5),
    last_txn integer
);



CREATE TABLE application_services_txns (
    as_id text NOT NULL,
    txn_id integer NOT NULL,
    event_ids text NOT NULL
);



CREATE TABLE appservice_room_list (
    appservice_id text NOT NULL,
    network_id text NOT NULL,
    room_id text NOT NULL
);



CREATE TABLE appservice_stream_position (
    lock character(1) DEFAULT 'X'::bpchar NOT NULL,
    stream_ordering bigint,
    CONSTRAINT appservice_stream_position_lock_check CHECK ((lock = 'X'::bpchar))
);



CREATE TABLE background_updates (
    update_name text NOT NULL,
    progress_json text NOT NULL,
    depends_on text
);



CREATE TABLE blocked_rooms (
    room_id text NOT NULL,
    user_id text NOT NULL
);



CREATE TABLE cache_invalidation_stream (
    stream_id bigint,
    cache_func text,
    keys text[],
    invalidation_ts bigint
);



CREATE TABLE current_state_delta_stream (
    stream_id bigint NOT NULL,
    room_id text NOT NULL,
    type text NOT NULL,
    state_key text NOT NULL,
    event_id text,
    prev_event_id text
);



CREATE TABLE current_state_events (
    event_id text NOT NULL,
    room_id text NOT NULL,
    type text NOT NULL,
    state_key text NOT NULL
);



CREATE TABLE deleted_pushers (
    stream_id bigint NOT NULL,
    app_id text NOT NULL,
    pushkey text NOT NULL,
    user_id text NOT NULL
);



CREATE TABLE destinations (
    destination text NOT NULL,
    retry_last_ts bigint,
    retry_interval integer
);



CREATE TABLE device_federation_inbox (
    origin text NOT NULL,
    message_id text NOT NULL,
    received_ts bigint NOT NULL
);



CREATE TABLE device_federation_outbox (
    destination text NOT NULL,
    stream_id bigint NOT NULL,
    queued_ts bigint NOT NULL,
    messages_json text NOT NULL
);



CREATE TABLE device_inbox (
    user_id text NOT NULL,
    device_id text NOT NULL,
    stream_id bigint NOT NULL,
    message_json text NOT NULL
);



CREATE TABLE device_lists_outbound_last_success (
    destination text NOT NULL,
    user_id text NOT NULL,
    stream_id bigint NOT NULL
);



CREATE TABLE device_lists_outbound_pokes (
    destination text NOT NULL,
    stream_id bigint NOT NULL,
    user_id text NOT NULL,
    device_id text NOT NULL,
    sent boolean NOT NULL,
    ts bigint NOT NULL
);



CREATE TABLE device_lists_remote_cache (
    user_id text NOT NULL,
    device_id text NOT NULL,
    content text NOT NULL
);



CREATE TABLE device_lists_remote_extremeties (
    user_id text NOT NULL,
    stream_id text NOT NULL
);



CREATE TABLE device_lists_stream (
    stream_id bigint NOT NULL,
    user_id text NOT NULL,
    device_id text NOT NULL
);



CREATE TABLE device_max_stream_id (
    stream_id bigint NOT NULL
);



CREATE TABLE devices (
    user_id text NOT NULL,
    device_id text NOT NULL,
    display_name text
);



CREATE TABLE e2e_device_keys_json (
    user_id text NOT NULL,
    device_id text NOT NULL,
    ts_added_ms bigint NOT NULL,
    key_json text NOT NULL
);



CREATE TABLE e2e_one_time_keys_json (
    user_id text NOT NULL,
    device_id text NOT NULL,
    algorithm text NOT NULL,
    key_id text NOT NULL,
    ts_added_ms bigint NOT NULL,
    key_json text NOT NULL
);



CREATE TABLE e2e_room_keys (
    user_id text NOT NULL,
    room_id text NOT NULL,
    session_id text NOT NULL,
    version bigint NOT NULL,
    first_message_index integer,
    forwarded_count integer,
    is_verified boolean,
    session_data text NOT NULL
);



CREATE TABLE e2e_room_keys_versions (
    user_id text NOT NULL,
    version bigint NOT NULL,
    algorithm text NOT NULL,
    auth_data text NOT NULL,
    deleted smallint DEFAULT 0 NOT NULL
);



CREATE TABLE erased_users (
    user_id text NOT NULL
);



CREATE TABLE event_auth (
    event_id text NOT NULL,
    auth_id text NOT NULL,
    room_id text NOT NULL
);



CREATE TABLE event_backward_extremities (
    event_id text NOT NULL,
    room_id text NOT NULL
);



CREATE TABLE event_edges (
    event_id text NOT NULL,
    prev_event_id text NOT NULL,
    room_id text NOT NULL,
    is_state boolean NOT NULL
);



CREATE TABLE event_forward_extremities (
    event_id text NOT NULL,
    room_id text NOT NULL
);



CREATE TABLE event_json (
    event_id text NOT NULL,
    room_id text NOT NULL,
    internal_metadata text NOT NULL,
    json text NOT NULL,
    format_version integer
);



CREATE TABLE event_push_actions (
    room_id text NOT NULL,
    event_id text NOT NULL,
    user_id text NOT NULL,
    profile_tag character varying(32),
    actions text NOT NULL,
    topological_ordering bigint,
    stream_ordering bigint,
    notif smallint,
    highlight smallint
);



CREATE TABLE event_push_actions_staging (
    event_id text NOT NULL,
    user_id text NOT NULL,
    actions text NOT NULL,
    notif smallint NOT NULL,
    highlight smallint NOT NULL
);



CREATE TABLE event_push_summary (
    user_id text NOT NULL,
    room_id text NOT NULL,
    notif_count bigint NOT NULL,
    stream_ordering bigint NOT NULL
);



CREATE TABLE event_push_summary_stream_ordering (
    lock character(1) DEFAULT 'X'::bpchar NOT NULL,
    stream_ordering bigint NOT NULL,
    CONSTRAINT event_push_summary_stream_ordering_lock_check CHECK ((lock = 'X'::bpchar))
);



CREATE TABLE event_reference_hashes (
    event_id text,
    algorithm text,
    hash bytea
);



CREATE TABLE event_relations (
    event_id text NOT NULL,
    relates_to_id text NOT NULL,
    relation_type text NOT NULL,
    aggregation_key text
);



CREATE TABLE event_reports (
    id bigint NOT NULL,
    received_ts bigint NOT NULL,
    room_id text NOT NULL,
    event_id text NOT NULL,
    user_id text NOT NULL,
    reason text,
    content text
);



CREATE TABLE event_search (
    event_id text,
    room_id text,
    sender text,
    key text,
    vector tsvector,
    origin_server_ts bigint,
    stream_ordering bigint
);



CREATE TABLE event_to_state_groups (
    event_id text NOT NULL,
    state_group bigint NOT NULL
);



CREATE TABLE events (
    stream_ordering integer NOT NULL,
    topological_ordering bigint NOT NULL,
    event_id text NOT NULL,
    type text NOT NULL,
    room_id text NOT NULL,
    content text,
    unrecognized_keys text,
    processed boolean NOT NULL,
    outlier boolean NOT NULL,
    depth bigint DEFAULT 0 NOT NULL,
    origin_server_ts bigint,
    received_ts bigint,
    sender text,
    contains_url boolean
);



CREATE TABLE ex_outlier_stream (
    event_stream_ordering bigint NOT NULL,
    event_id text NOT NULL,
    state_group bigint NOT NULL
);



CREATE TABLE federation_stream_position (
    type text NOT NULL,
    stream_id integer NOT NULL
);



CREATE TABLE group_attestations_remote (
    group_id text NOT NULL,
    user_id text NOT NULL,
    valid_until_ms bigint NOT NULL,
    attestation_json text NOT NULL
);



CREATE TABLE group_attestations_renewals (
    group_id text NOT NULL,
    user_id text NOT NULL,
    valid_until_ms bigint NOT NULL
);



CREATE TABLE group_invites (
    group_id text NOT NULL,
    user_id text NOT NULL
);



CREATE TABLE group_roles (
    group_id text NOT NULL,
    role_id text NOT NULL,
    profile text NOT NULL,
    is_public boolean NOT NULL
);



CREATE TABLE group_room_categories (
    group_id text NOT NULL,
    category_id text NOT NULL,
    profile text NOT NULL,
    is_public boolean NOT NULL
);



CREATE TABLE group_rooms (
    group_id text NOT NULL,
    room_id text NOT NULL,
    is_public boolean NOT NULL
);



CREATE TABLE group_summary_roles (
    group_id text NOT NULL,
    role_id text NOT NULL,
    role_order bigint NOT NULL,
    CONSTRAINT group_summary_roles_role_order_check CHECK ((role_order > 0))
);



CREATE TABLE group_summary_room_categories (
    group_id text NOT NULL,
    category_id text NOT NULL,
    cat_order bigint NOT NULL,
    CONSTRAINT group_summary_room_categories_cat_order_check CHECK ((cat_order > 0))
);



CREATE TABLE group_summary_rooms (
    group_id text NOT NULL,
    room_id text NOT NULL,
    category_id text NOT NULL,
    room_order bigint NOT NULL,
    is_public boolean NOT NULL,
    CONSTRAINT group_summary_rooms_room_order_check CHECK ((room_order > 0))
);



CREATE TABLE group_summary_users (
    group_id text NOT NULL,
    user_id text NOT NULL,
    role_id text NOT NULL,
    user_order bigint NOT NULL,
    is_public boolean NOT NULL
);



CREATE TABLE group_users (
    group_id text NOT NULL,
    user_id text NOT NULL,
    is_admin boolean NOT NULL,
    is_public boolean NOT NULL
);



CREATE TABLE groups (
    group_id text NOT NULL,
    name text,
    avatar_url text,
    short_description text,
    long_description text,
    is_public boolean NOT NULL,
    join_policy text DEFAULT 'invite'::text NOT NULL
);



CREATE TABLE guest_access (
    event_id text NOT NULL,
    room_id text NOT NULL,
    guest_access text NOT NULL
);



CREATE TABLE history_visibility (
    event_id text NOT NULL,
    room_id text NOT NULL,
    history_visibility text NOT NULL
);



CREATE TABLE local_group_membership (
    group_id text NOT NULL,
    user_id text NOT NULL,
    is_admin boolean NOT NULL,
    membership text NOT NULL,
    is_publicised boolean NOT NULL,
    content text NOT NULL
);



CREATE TABLE local_group_updates (
    stream_id bigint NOT NULL,
    group_id text NOT NULL,
    user_id text NOT NULL,
    type text NOT NULL,
    content text NOT NULL
);



CREATE TABLE local_invites (
    stream_id bigint NOT NULL,
    inviter text NOT NULL,
    invitee text NOT NULL,
    event_id text NOT NULL,
    room_id text NOT NULL,
    locally_rejected text,
    replaced_by text
);



CREATE TABLE local_media_repository (
    media_id text,
    media_type text,
    media_length integer,
    created_ts bigint,
    upload_name text,
    user_id text,
    quarantined_by text,
    url_cache text,
    last_access_ts bigint
);



CREATE TABLE local_media_repository_thumbnails (
    media_id text,
    thumbnail_width integer,
    thumbnail_height integer,
    thumbnail_type text,
    thumbnail_method text,
    thumbnail_length integer
);



CREATE TABLE local_media_repository_url_cache (
    url text,
    response_code integer,
    etag text,
    expires_ts bigint,
    og text,
    media_id text,
    download_ts bigint
);



CREATE TABLE monthly_active_users (
    user_id text NOT NULL,
    "timestamp" bigint NOT NULL
);



CREATE TABLE open_id_tokens (
    token text NOT NULL,
    ts_valid_until_ms bigint NOT NULL,
    user_id text NOT NULL
);



CREATE TABLE presence (
    user_id text NOT NULL,
    state character varying(20),
    status_msg text,
    mtime bigint
);



CREATE TABLE presence_allow_inbound (
    observed_user_id text NOT NULL,
    observer_user_id text NOT NULL
);



CREATE TABLE presence_stream (
    stream_id bigint,
    user_id text,
    state text,
    last_active_ts bigint,
    last_federation_update_ts bigint,
    last_user_sync_ts bigint,
    status_msg text,
    currently_active boolean
);



CREATE TABLE profiles (
    user_id text NOT NULL,
    displayname text,
    avatar_url text
);



CREATE TABLE public_room_list_stream (
    stream_id bigint NOT NULL,
    room_id text NOT NULL,
    visibility boolean NOT NULL,
    appservice_id text,
    network_id text
);



CREATE TABLE push_rules (
    id bigint NOT NULL,
    user_name text NOT NULL,
    rule_id text NOT NULL,
    priority_class smallint NOT NULL,
    priority integer DEFAULT 0 NOT NULL,
    conditions text NOT NULL,
    actions text NOT NULL
);



CREATE TABLE push_rules_enable (
    id bigint NOT NULL,
    user_name text NOT NULL,
    rule_id text NOT NULL,
    enabled smallint
);



CREATE TABLE push_rules_stream (
    stream_id bigint NOT NULL,
    event_stream_ordering bigint NOT NULL,
    user_id text NOT NULL,
    rule_id text NOT NULL,
    op text NOT NULL,
    priority_class smallint,
    priority integer,
    conditions text,
    actions text
);



CREATE TABLE pusher_throttle (
    pusher bigint NOT NULL,
    room_id text NOT NULL,
    last_sent_ts bigint,
    throttle_ms bigint
);



CREATE TABLE pushers (
    id bigint NOT NULL,
    user_name text NOT NULL,
    access_token bigint,
    profile_tag text NOT NULL,
    kind text NOT NULL,
    app_id text NOT NULL,
    app_display_name text NOT NULL,
    device_display_name text NOT NULL,
    pushkey text NOT NULL,
    ts bigint NOT NULL,
    lang text,
    data text,
    last_stream_ordering integer,
    last_success bigint,
    failing_since bigint
);



CREATE TABLE ratelimit_override (
    user_id text NOT NULL,
    messages_per_second bigint,
    burst_count bigint
);



CREATE TABLE receipts_graph (
    room_id text NOT NULL,
    receipt_type text NOT NULL,
    user_id text NOT NULL,
    event_ids text NOT NULL,
    data text NOT NULL
);



CREATE TABLE receipts_linearized (
    stream_id bigint NOT NULL,
    room_id text NOT NULL,
    receipt_type text NOT NULL,
    user_id text NOT NULL,
    event_id text NOT NULL,
    data text NOT NULL
);



CREATE TABLE received_transactions (
    transaction_id text,
    origin text,
    ts bigint,
    response_code integer,
    response_json bytea,
    has_been_referenced smallint DEFAULT 0
);



CREATE TABLE redactions (
    event_id text NOT NULL,
    redacts text NOT NULL
);



CREATE TABLE rejections (
    event_id text NOT NULL,
    reason text NOT NULL,
    last_check text NOT NULL
);



CREATE TABLE remote_media_cache (
    media_origin text,
    media_id text,
    media_type text,
    created_ts bigint,
    upload_name text,
    media_length integer,
    filesystem_id text,
    last_access_ts bigint,
    quarantined_by text
);



CREATE TABLE remote_media_cache_thumbnails (
    media_origin text,
    media_id text,
    thumbnail_width integer,
    thumbnail_height integer,
    thumbnail_method text,
    thumbnail_type text,
    thumbnail_length integer,
    filesystem_id text
);



CREATE TABLE remote_profile_cache (
    user_id text NOT NULL,
    displayname text,
    avatar_url text,
    last_check bigint NOT NULL
);



CREATE TABLE room_account_data (
    user_id text NOT NULL,
    room_id text NOT NULL,
    account_data_type text NOT NULL,
    stream_id bigint NOT NULL,
    content text NOT NULL
);



CREATE TABLE room_alias_servers (
    room_alias text NOT NULL,
    server text NOT NULL
);



CREATE TABLE room_aliases (
    room_alias text NOT NULL,
    room_id text NOT NULL,
    creator text
);



CREATE TABLE room_depth (
    room_id text NOT NULL,
    min_depth integer NOT NULL
);



CREATE TABLE room_memberships (
    event_id text NOT NULL,
    user_id text NOT NULL,
    sender text NOT NULL,
    room_id text NOT NULL,
    membership text NOT NULL,
    forgotten integer DEFAULT 0,
    display_name text,
    avatar_url text
);



CREATE TABLE room_names (
    event_id text NOT NULL,
    room_id text NOT NULL,
    name text NOT NULL
);



CREATE TABLE room_state (
    room_id text NOT NULL,
    join_rules text,
    history_visibility text,
    encryption text,
    name text,
    topic text,
    avatar text,
    canonical_alias text
);



CREATE TABLE room_stats (
    room_id text NOT NULL,
    ts bigint NOT NULL,
    bucket_size integer NOT NULL,
    current_state_events integer NOT NULL,
    joined_members integer NOT NULL,
    invited_members integer NOT NULL,
    left_members integer NOT NULL,
    banned_members integer NOT NULL,
    state_events integer NOT NULL
);



CREATE TABLE room_stats_earliest_token (
    room_id text NOT NULL,
    token bigint NOT NULL
);



CREATE TABLE room_tags (
    user_id text NOT NULL,
    room_id text NOT NULL,
    tag text NOT NULL,
    content text NOT NULL
);



CREATE TABLE room_tags_revisions (
    user_id text NOT NULL,
    room_id text NOT NULL,
    stream_id bigint NOT NULL
);



CREATE TABLE rooms (
    room_id text NOT NULL,
    is_public boolean,
    creator text
);



CREATE TABLE server_keys_json (
    server_name text NOT NULL,
    key_id text NOT NULL,
    from_server text NOT NULL,
    ts_added_ms bigint NOT NULL,
    ts_valid_until_ms bigint NOT NULL,
    key_json bytea NOT NULL
);



CREATE TABLE server_signature_keys (
    server_name text,
    key_id text,
    from_server text,
    ts_added_ms bigint,
    verify_key bytea,
    ts_valid_until_ms bigint
);



CREATE TABLE state_events (
    event_id text NOT NULL,
    room_id text NOT NULL,
    type text NOT NULL,
    state_key text NOT NULL,
    prev_state text
);



CREATE TABLE state_group_edges (
    state_group bigint NOT NULL,
    prev_state_group bigint NOT NULL
);



CREATE SEQUENCE state_group_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;



CREATE TABLE state_groups (
    id bigint NOT NULL,
    room_id text NOT NULL,
    event_id text NOT NULL
);



CREATE TABLE state_groups_state (
    state_group bigint NOT NULL,
    room_id text NOT NULL,
    type text NOT NULL,
    state_key text NOT NULL,
    event_id text NOT NULL
);



CREATE TABLE stats_stream_pos (
    lock character(1) DEFAULT 'X'::bpchar NOT NULL,
    stream_id bigint,
    CONSTRAINT stats_stream_pos_lock_check CHECK ((lock = 'X'::bpchar))
);



CREATE TABLE stream_ordering_to_exterm (
    stream_ordering bigint NOT NULL,
    room_id text NOT NULL,
    event_id text NOT NULL
);



CREATE TABLE threepid_guest_access_tokens (
    medium text,
    address text,
    guest_access_token text,
    first_inviter text
);



CREATE TABLE topics (
    event_id text NOT NULL,
    room_id text NOT NULL,
    topic text NOT NULL
);



CREATE TABLE user_daily_visits (
    user_id text NOT NULL,
    device_id text,
    "timestamp" bigint NOT NULL
);



CREATE TABLE user_directory (
    user_id text NOT NULL,
    room_id text,
    display_name text,
    avatar_url text
);



CREATE TABLE user_directory_search (
    user_id text NOT NULL,
    vector tsvector
);



CREATE TABLE user_directory_stream_pos (
    lock character(1) DEFAULT 'X'::bpchar NOT NULL,
    stream_id bigint,
    CONSTRAINT user_directory_stream_pos_lock_check CHECK ((lock = 'X'::bpchar))
);



CREATE TABLE user_filters (
    user_id text,
    filter_id bigint,
    filter_json bytea
);



CREATE TABLE user_ips (
    user_id text NOT NULL,
    access_token text NOT NULL,
    device_id text,
    ip text NOT NULL,
    user_agent text NOT NULL,
    last_seen bigint NOT NULL
);



CREATE TABLE user_stats (
    user_id text NOT NULL,
    ts bigint NOT NULL,
    bucket_size integer NOT NULL,
    public_rooms integer NOT NULL,
    private_rooms integer NOT NULL
);



CREATE TABLE user_threepid_id_server (
    user_id text NOT NULL,
    medium text NOT NULL,
    address text NOT NULL,
    id_server text NOT NULL
);



CREATE TABLE user_threepids (
    user_id text NOT NULL,
    medium text NOT NULL,
    address text NOT NULL,
    validated_at bigint NOT NULL,
    added_at bigint NOT NULL
);



CREATE TABLE users (
    name text,
    password_hash text,
    creation_ts bigint,
    admin smallint DEFAULT 0 NOT NULL,
    upgrade_ts bigint,
    is_guest smallint DEFAULT 0 NOT NULL,
    appservice_id text,
    consent_version text,
    consent_server_notice_sent text,
    user_type text
);



CREATE TABLE users_in_public_rooms (
    user_id text NOT NULL,
    room_id text NOT NULL
);



CREATE TABLE users_pending_deactivation (
    user_id text NOT NULL
);



CREATE TABLE users_who_share_private_rooms (
    user_id text NOT NULL,
    other_user_id text NOT NULL,
    room_id text NOT NULL
);



ALTER TABLE ONLY access_tokens
    ADD CONSTRAINT access_tokens_pkey PRIMARY KEY (id);



ALTER TABLE ONLY access_tokens
    ADD CONSTRAINT access_tokens_token_key UNIQUE (token);



ALTER TABLE ONLY account_data
    ADD CONSTRAINT account_data_uniqueness UNIQUE (user_id, account_data_type);



ALTER TABLE ONLY account_validity
    ADD CONSTRAINT account_validity_pkey PRIMARY KEY (user_id);



ALTER TABLE ONLY application_services_state
    ADD CONSTRAINT application_services_state_pkey PRIMARY KEY (as_id);



ALTER TABLE ONLY application_services_txns
    ADD CONSTRAINT application_services_txns_as_id_txn_id_key UNIQUE (as_id, txn_id);



ALTER TABLE ONLY appservice_stream_position
    ADD CONSTRAINT appservice_stream_position_lock_key UNIQUE (lock);



ALTER TABLE ONLY background_updates
    ADD CONSTRAINT background_updates_uniqueness UNIQUE (update_name);



ALTER TABLE ONLY current_state_events
    ADD CONSTRAINT current_state_events_event_id_key UNIQUE (event_id);



ALTER TABLE ONLY current_state_events
    ADD CONSTRAINT current_state_events_room_id_type_state_key_key UNIQUE (room_id, type, state_key);



ALTER TABLE ONLY destinations
    ADD CONSTRAINT destinations_pkey PRIMARY KEY (destination);



ALTER TABLE ONLY devices
    ADD CONSTRAINT device_uniqueness UNIQUE (user_id, device_id);



ALTER TABLE ONLY e2e_device_keys_json
    ADD CONSTRAINT e2e_device_keys_json_uniqueness UNIQUE (user_id, device_id);



ALTER TABLE ONLY e2e_one_time_keys_json
    ADD CONSTRAINT e2e_one_time_keys_json_uniqueness UNIQUE (user_id, device_id, algorithm, key_id);



ALTER TABLE ONLY event_backward_extremities
    ADD CONSTRAINT event_backward_extremities_event_id_room_id_key UNIQUE (event_id, room_id);



ALTER TABLE ONLY event_edges
    ADD CONSTRAINT event_edges_event_id_prev_event_id_room_id_is_state_key UNIQUE (event_id, prev_event_id, room_id, is_state);



ALTER TABLE ONLY event_forward_extremities
    ADD CONSTRAINT event_forward_extremities_event_id_room_id_key UNIQUE (event_id, room_id);



ALTER TABLE ONLY event_push_actions
    ADD CONSTRAINT event_id_user_id_profile_tag_uniqueness UNIQUE (room_id, event_id, user_id, profile_tag);



ALTER TABLE ONLY event_json
    ADD CONSTRAINT event_json_event_id_key UNIQUE (event_id);



ALTER TABLE ONLY event_push_summary_stream_ordering
    ADD CONSTRAINT event_push_summary_stream_ordering_lock_key UNIQUE (lock);



ALTER TABLE ONLY event_reference_hashes
    ADD CONSTRAINT event_reference_hashes_event_id_algorithm_key UNIQUE (event_id, algorithm);



ALTER TABLE ONLY event_reports
    ADD CONSTRAINT event_reports_pkey PRIMARY KEY (id);



ALTER TABLE ONLY event_to_state_groups
    ADD CONSTRAINT event_to_state_groups_event_id_key UNIQUE (event_id);



ALTER TABLE ONLY events
    ADD CONSTRAINT events_event_id_key UNIQUE (event_id);



ALTER TABLE ONLY events
    ADD CONSTRAINT events_pkey PRIMARY KEY (stream_ordering);



ALTER TABLE ONLY ex_outlier_stream
    ADD CONSTRAINT ex_outlier_stream_pkey PRIMARY KEY (event_stream_ordering);



ALTER TABLE ONLY group_roles
    ADD CONSTRAINT group_roles_group_id_role_id_key UNIQUE (group_id, role_id);



ALTER TABLE ONLY group_room_categories
    ADD CONSTRAINT group_room_categories_group_id_category_id_key UNIQUE (group_id, category_id);



ALTER TABLE ONLY group_summary_roles
    ADD CONSTRAINT group_summary_roles_group_id_role_id_role_order_key UNIQUE (group_id, role_id, role_order);



ALTER TABLE ONLY group_summary_room_categories
    ADD CONSTRAINT group_summary_room_categories_group_id_category_id_cat_orde_key UNIQUE (group_id, category_id, cat_order);



ALTER TABLE ONLY group_summary_rooms
    ADD CONSTRAINT group_summary_rooms_group_id_category_id_room_id_room_order_key UNIQUE (group_id, category_id, room_id, room_order);



ALTER TABLE ONLY guest_access
    ADD CONSTRAINT guest_access_event_id_key UNIQUE (event_id);



ALTER TABLE ONLY history_visibility
    ADD CONSTRAINT history_visibility_event_id_key UNIQUE (event_id);



ALTER TABLE ONLY local_media_repository
    ADD CONSTRAINT local_media_repository_media_id_key UNIQUE (media_id);



ALTER TABLE ONLY local_media_repository_thumbnails
    ADD CONSTRAINT local_media_repository_thumbn_media_id_thumbnail_width_thum_key UNIQUE (media_id, thumbnail_width, thumbnail_height, thumbnail_type);



ALTER TABLE ONLY user_threepids
    ADD CONSTRAINT medium_address UNIQUE (medium, address);



ALTER TABLE ONLY open_id_tokens
    ADD CONSTRAINT open_id_tokens_pkey PRIMARY KEY (token);



ALTER TABLE ONLY presence_allow_inbound
    ADD CONSTRAINT presence_allow_inbound_observed_user_id_observer_user_id_key UNIQUE (observed_user_id, observer_user_id);



ALTER TABLE ONLY presence
    ADD CONSTRAINT presence_user_id_key UNIQUE (user_id);



ALTER TABLE ONLY account_data_max_stream_id
    ADD CONSTRAINT private_user_data_max_stream_id_lock_key UNIQUE (lock);



ALTER TABLE ONLY profiles
    ADD CONSTRAINT profiles_user_id_key UNIQUE (user_id);



ALTER TABLE ONLY push_rules_enable
    ADD CONSTRAINT push_rules_enable_pkey PRIMARY KEY (id);



ALTER TABLE ONLY push_rules_enable
    ADD CONSTRAINT push_rules_enable_user_name_rule_id_key UNIQUE (user_name, rule_id);



ALTER TABLE ONLY push_rules
    ADD CONSTRAINT push_rules_pkey PRIMARY KEY (id);



ALTER TABLE ONLY push_rules
    ADD CONSTRAINT push_rules_user_name_rule_id_key UNIQUE (user_name, rule_id);



ALTER TABLE ONLY pusher_throttle
    ADD CONSTRAINT pusher_throttle_pkey PRIMARY KEY (pusher, room_id);



ALTER TABLE ONLY pushers
    ADD CONSTRAINT pushers2_app_id_pushkey_user_name_key UNIQUE (app_id, pushkey, user_name);



ALTER TABLE ONLY pushers
    ADD CONSTRAINT pushers2_pkey PRIMARY KEY (id);



ALTER TABLE ONLY receipts_graph
    ADD CONSTRAINT receipts_graph_uniqueness UNIQUE (room_id, receipt_type, user_id);



ALTER TABLE ONLY receipts_linearized
    ADD CONSTRAINT receipts_linearized_uniqueness UNIQUE (room_id, receipt_type, user_id);



ALTER TABLE ONLY received_transactions
    ADD CONSTRAINT received_transactions_transaction_id_origin_key UNIQUE (transaction_id, origin);



ALTER TABLE ONLY redactions
    ADD CONSTRAINT redactions_event_id_key UNIQUE (event_id);



ALTER TABLE ONLY rejections
    ADD CONSTRAINT rejections_event_id_key UNIQUE (event_id);



ALTER TABLE ONLY remote_media_cache
    ADD CONSTRAINT remote_media_cache_media_origin_media_id_key UNIQUE (media_origin, media_id);



ALTER TABLE ONLY remote_media_cache_thumbnails
    ADD CONSTRAINT remote_media_cache_thumbnails_media_origin_media_id_thumbna_key UNIQUE (media_origin, media_id, thumbnail_width, thumbnail_height, thumbnail_type);



ALTER TABLE ONLY room_account_data
    ADD CONSTRAINT room_account_data_uniqueness UNIQUE (user_id, room_id, account_data_type);



ALTER TABLE ONLY room_aliases
    ADD CONSTRAINT room_aliases_room_alias_key UNIQUE (room_alias);



ALTER TABLE ONLY room_depth
    ADD CONSTRAINT room_depth_room_id_key UNIQUE (room_id);



ALTER TABLE ONLY room_memberships
    ADD CONSTRAINT room_memberships_event_id_key UNIQUE (event_id);



ALTER TABLE ONLY room_names
    ADD CONSTRAINT room_names_event_id_key UNIQUE (event_id);



ALTER TABLE ONLY room_tags_revisions
    ADD CONSTRAINT room_tag_revisions_uniqueness UNIQUE (user_id, room_id);



ALTER TABLE ONLY room_tags
    ADD CONSTRAINT room_tag_uniqueness UNIQUE (user_id, room_id, tag);



ALTER TABLE ONLY rooms
    ADD CONSTRAINT rooms_pkey PRIMARY KEY (room_id);



ALTER TABLE ONLY server_keys_json
    ADD CONSTRAINT server_keys_json_uniqueness UNIQUE (server_name, key_id, from_server);



ALTER TABLE ONLY server_signature_keys
    ADD CONSTRAINT server_signature_keys_server_name_key_id_key UNIQUE (server_name, key_id);



ALTER TABLE ONLY state_events
    ADD CONSTRAINT state_events_event_id_key UNIQUE (event_id);



ALTER TABLE ONLY state_groups
    ADD CONSTRAINT state_groups_pkey PRIMARY KEY (id);



ALTER TABLE ONLY stats_stream_pos
    ADD CONSTRAINT stats_stream_pos_lock_key UNIQUE (lock);



ALTER TABLE ONLY topics
    ADD CONSTRAINT topics_event_id_key UNIQUE (event_id);



ALTER TABLE ONLY user_directory_stream_pos
    ADD CONSTRAINT user_directory_stream_pos_lock_key UNIQUE (lock);



ALTER TABLE ONLY users
    ADD CONSTRAINT users_name_key UNIQUE (name);



CREATE INDEX access_tokens_device_id ON access_tokens USING btree (user_id, device_id);



CREATE INDEX account_data_stream_id ON account_data USING btree (user_id, stream_id);



CREATE INDEX application_services_txns_id ON application_services_txns USING btree (as_id);



CREATE UNIQUE INDEX appservice_room_list_idx ON appservice_room_list USING btree (appservice_id, network_id, room_id);



CREATE UNIQUE INDEX blocked_rooms_idx ON blocked_rooms USING btree (room_id);



CREATE INDEX cache_invalidation_stream_id ON cache_invalidation_stream USING btree (stream_id);



CREATE INDEX current_state_delta_stream_idx ON current_state_delta_stream USING btree (stream_id);



CREATE INDEX current_state_events_member_index ON current_state_events USING btree (state_key) WHERE (type = 'm.room.member'::text);



CREATE INDEX deleted_pushers_stream_id ON deleted_pushers USING btree (stream_id);



CREATE INDEX device_federation_inbox_sender_id ON device_federation_inbox USING btree (origin, message_id);



CREATE INDEX device_federation_outbox_destination_id ON device_federation_outbox USING btree (destination, stream_id);



CREATE INDEX device_federation_outbox_id ON device_federation_outbox USING btree (stream_id);



CREATE INDEX device_inbox_stream_id_user_id ON device_inbox USING btree (stream_id, user_id);



CREATE INDEX device_inbox_user_stream_id ON device_inbox USING btree (user_id, device_id, stream_id);



CREATE INDEX device_lists_outbound_last_success_idx ON device_lists_outbound_last_success USING btree (destination, user_id, stream_id);



CREATE INDEX device_lists_outbound_pokes_id ON device_lists_outbound_pokes USING btree (destination, stream_id);



CREATE INDEX device_lists_outbound_pokes_stream ON device_lists_outbound_pokes USING btree (stream_id);



CREATE INDEX device_lists_outbound_pokes_user ON device_lists_outbound_pokes USING btree (destination, user_id);



CREATE UNIQUE INDEX device_lists_remote_cache_unique_id ON device_lists_remote_cache USING btree (user_id, device_id);



CREATE UNIQUE INDEX device_lists_remote_extremeties_unique_idx ON device_lists_remote_extremeties USING btree (user_id);



CREATE INDEX device_lists_stream_id ON device_lists_stream USING btree (stream_id, user_id);



CREATE INDEX device_lists_stream_user_id ON device_lists_stream USING btree (user_id, device_id);



CREATE UNIQUE INDEX e2e_room_keys_idx ON e2e_room_keys USING btree (user_id, room_id, session_id);



CREATE UNIQUE INDEX e2e_room_keys_versions_idx ON e2e_room_keys_versions USING btree (user_id, version);



CREATE UNIQUE INDEX erased_users_user ON erased_users USING btree (user_id);



CREATE INDEX ev_b_extrem_id ON event_backward_extremities USING btree (event_id);



CREATE INDEX ev_b_extrem_room ON event_backward_extremities USING btree (room_id);



CREATE INDEX ev_edges_id ON event_edges USING btree (event_id);



CREATE INDEX ev_edges_prev_id ON event_edges USING btree (prev_event_id);



CREATE INDEX ev_extrem_id ON event_forward_extremities USING btree (event_id);



CREATE INDEX ev_extrem_room ON event_forward_extremities USING btree (room_id);



CREATE INDEX evauth_edges_id ON event_auth USING btree (event_id);



CREATE INDEX event_contains_url_index ON events USING btree (room_id, topological_ordering, stream_ordering) WHERE ((contains_url = true) AND (outlier = false));



CREATE INDEX event_json_room_id ON event_json USING btree (room_id);



CREATE INDEX event_push_actions_highlights_index ON event_push_actions USING btree (user_id, room_id, topological_ordering, stream_ordering) WHERE (highlight = 1);



CREATE INDEX event_push_actions_rm_tokens ON event_push_actions USING btree (user_id, room_id, topological_ordering, stream_ordering);



CREATE INDEX event_push_actions_room_id_user_id ON event_push_actions USING btree (room_id, user_id);



CREATE INDEX event_push_actions_staging_id ON event_push_actions_staging USING btree (event_id);



CREATE INDEX event_push_actions_stream_ordering ON event_push_actions USING btree (stream_ordering, user_id);



CREATE INDEX event_push_actions_u_highlight ON event_push_actions USING btree (user_id, stream_ordering);



CREATE INDEX event_push_summary_user_rm ON event_push_summary USING btree (user_id, room_id);



CREATE INDEX event_reference_hashes_id ON event_reference_hashes USING btree (event_id);



CREATE UNIQUE INDEX event_relations_id ON event_relations USING btree (event_id);



CREATE INDEX event_relations_relates ON event_relations USING btree (relates_to_id, relation_type, aggregation_key);



CREATE INDEX event_search_ev_ridx ON event_search USING btree (room_id);



CREATE UNIQUE INDEX event_search_event_id_idx ON event_search USING btree (event_id);



CREATE INDEX event_search_fts_idx ON event_search USING gin (vector);



CREATE INDEX event_to_state_groups_sg_index ON event_to_state_groups USING btree (state_group);



CREATE INDEX events_order_room ON events USING btree (room_id, topological_ordering, stream_ordering);



CREATE INDEX events_room_stream ON events USING btree (room_id, stream_ordering);



CREATE INDEX events_ts ON events USING btree (origin_server_ts, stream_ordering);



CREATE INDEX group_attestations_remote_g_idx ON group_attestations_remote USING btree (group_id, user_id);



CREATE INDEX group_attestations_remote_u_idx ON group_attestations_remote USING btree (user_id);



CREATE INDEX group_attestations_remote_v_idx ON group_attestations_remote USING btree (valid_until_ms);



CREATE INDEX group_attestations_renewals_g_idx ON group_attestations_renewals USING btree (group_id, user_id);



CREATE INDEX group_attestations_renewals_u_idx ON group_attestations_renewals USING btree (user_id);



CREATE INDEX group_attestations_renewals_v_idx ON group_attestations_renewals USING btree (valid_until_ms);



CREATE UNIQUE INDEX group_invites_g_idx ON group_invites USING btree (group_id, user_id);



CREATE INDEX group_invites_u_idx ON group_invites USING btree (user_id);



CREATE UNIQUE INDEX group_rooms_g_idx ON group_rooms USING btree (group_id, room_id);



CREATE INDEX group_rooms_r_idx ON group_rooms USING btree (room_id);



CREATE UNIQUE INDEX group_summary_rooms_g_idx ON group_summary_rooms USING btree (group_id, room_id, category_id);



CREATE INDEX group_summary_users_g_idx ON group_summary_users USING btree (group_id);



CREATE UNIQUE INDEX group_users_g_idx ON group_users USING btree (group_id, user_id);



CREATE INDEX group_users_u_idx ON group_users USING btree (user_id);



CREATE UNIQUE INDEX groups_idx ON groups USING btree (group_id);



CREATE INDEX local_group_membership_g_idx ON local_group_membership USING btree (group_id);



CREATE INDEX local_group_membership_u_idx ON local_group_membership USING btree (user_id, group_id);



CREATE INDEX local_invites_for_user_idx ON local_invites USING btree (invitee, locally_rejected, replaced_by, room_id);



CREATE INDEX local_invites_id ON local_invites USING btree (stream_id);



CREATE INDEX local_media_repository_thumbnails_media_id ON local_media_repository_thumbnails USING btree (media_id);



CREATE INDEX local_media_repository_url_cache_by_url_download_ts ON local_media_repository_url_cache USING btree (url, download_ts);



CREATE INDEX local_media_repository_url_cache_expires_idx ON local_media_repository_url_cache USING btree (expires_ts);



CREATE INDEX local_media_repository_url_cache_media_idx ON local_media_repository_url_cache USING btree (media_id);



CREATE INDEX local_media_repository_url_idx ON local_media_repository USING btree (created_ts) WHERE (url_cache IS NOT NULL);



CREATE INDEX monthly_active_users_time_stamp ON monthly_active_users USING btree ("timestamp");



CREATE UNIQUE INDEX monthly_active_users_users ON monthly_active_users USING btree (user_id);



CREATE INDEX open_id_tokens_ts_valid_until_ms ON open_id_tokens USING btree (ts_valid_until_ms);



CREATE INDEX presence_stream_id ON presence_stream USING btree (stream_id, user_id);



CREATE INDEX presence_stream_user_id ON presence_stream USING btree (user_id);



CREATE INDEX public_room_index ON rooms USING btree (is_public);



CREATE INDEX public_room_list_stream_idx ON public_room_list_stream USING btree (stream_id);



CREATE INDEX public_room_list_stream_rm_idx ON public_room_list_stream USING btree (room_id, stream_id);



CREATE INDEX push_rules_enable_user_name ON push_rules_enable USING btree (user_name);



CREATE INDEX push_rules_stream_id ON push_rules_stream USING btree (stream_id);



CREATE INDEX push_rules_stream_user_stream_id ON push_rules_stream USING btree (user_id, stream_id);



CREATE INDEX push_rules_user_name ON push_rules USING btree (user_name);



CREATE UNIQUE INDEX ratelimit_override_idx ON ratelimit_override USING btree (user_id);



CREATE INDEX receipts_linearized_id ON receipts_linearized USING btree (stream_id);



CREATE INDEX receipts_linearized_room_stream ON receipts_linearized USING btree (room_id, stream_id);



CREATE INDEX receipts_linearized_user ON receipts_linearized USING btree (user_id);



CREATE INDEX received_transactions_ts ON received_transactions USING btree (ts);



CREATE INDEX redactions_redacts ON redactions USING btree (redacts);



CREATE INDEX remote_profile_cache_time ON remote_profile_cache USING btree (last_check);



CREATE UNIQUE INDEX remote_profile_cache_user_id ON remote_profile_cache USING btree (user_id);



CREATE INDEX room_account_data_stream_id ON room_account_data USING btree (user_id, stream_id);



CREATE INDEX room_alias_servers_alias ON room_alias_servers USING btree (room_alias);



CREATE INDEX room_aliases_id ON room_aliases USING btree (room_id);



CREATE INDEX room_depth_room ON room_depth USING btree (room_id);



CREATE INDEX room_memberships_room_id ON room_memberships USING btree (room_id);



CREATE INDEX room_memberships_user_id ON room_memberships USING btree (user_id);



CREATE INDEX room_names_room_id ON room_names USING btree (room_id);



CREATE UNIQUE INDEX room_state_room ON room_state USING btree (room_id);



CREATE UNIQUE INDEX room_stats_earliest_token_idx ON room_stats_earliest_token USING btree (room_id);



CREATE UNIQUE INDEX room_stats_room_ts ON room_stats USING btree (room_id, ts);



CREATE INDEX state_group_edges_idx ON state_group_edges USING btree (state_group);



CREATE INDEX state_group_edges_prev_idx ON state_group_edges USING btree (prev_state_group);



CREATE INDEX state_groups_state_type_idx ON state_groups_state USING btree (state_group, type, state_key);



CREATE INDEX stream_ordering_to_exterm_idx ON stream_ordering_to_exterm USING btree (stream_ordering);



CREATE INDEX stream_ordering_to_exterm_rm_idx ON stream_ordering_to_exterm USING btree (room_id, stream_ordering);



CREATE UNIQUE INDEX threepid_guest_access_tokens_index ON threepid_guest_access_tokens USING btree (medium, address);



CREATE INDEX topics_room_id ON topics USING btree (room_id);



CREATE INDEX user_daily_visits_ts_idx ON user_daily_visits USING btree ("timestamp");



CREATE INDEX user_daily_visits_uts_idx ON user_daily_visits USING btree (user_id, "timestamp");



CREATE INDEX user_directory_room_idx ON user_directory USING btree (room_id);



CREATE INDEX user_directory_search_fts_idx ON user_directory_search USING gin (vector);



CREATE UNIQUE INDEX user_directory_search_user_idx ON user_directory_search USING btree (user_id);



CREATE UNIQUE INDEX user_directory_user_idx ON user_directory USING btree (user_id);



CREATE INDEX user_filters_by_user_id_filter_id ON user_filters USING btree (user_id, filter_id);



CREATE INDEX user_ips_device_id ON user_ips USING btree (user_id, device_id, last_seen);



CREATE INDEX user_ips_last_seen ON user_ips USING btree (user_id, last_seen);



CREATE INDEX user_ips_last_seen_only ON user_ips USING btree (last_seen);



CREATE UNIQUE INDEX user_ips_user_token_ip_unique_index ON user_ips USING btree (user_id, access_token, ip);



CREATE UNIQUE INDEX user_stats_user_ts ON user_stats USING btree (user_id, ts);



CREATE UNIQUE INDEX user_threepid_id_server_idx ON user_threepid_id_server USING btree (user_id, medium, address, id_server);



CREATE INDEX user_threepids_medium_address ON user_threepids USING btree (medium, address);



CREATE INDEX user_threepids_user_id ON user_threepids USING btree (user_id);



CREATE INDEX users_creation_ts ON users USING btree (creation_ts);



CREATE UNIQUE INDEX users_in_public_rooms_u_idx ON users_in_public_rooms USING btree (user_id, room_id);



CREATE INDEX users_who_share_private_rooms_o_idx ON users_who_share_private_rooms USING btree (other_user_id);



CREATE INDEX users_who_share_private_rooms_r_idx ON users_who_share_private_rooms USING btree (room_id);



CREATE UNIQUE INDEX users_who_share_private_rooms_u_idx ON users_who_share_private_rooms USING btree (user_id, other_user_id, room_id);