-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathdatabase.sql
More file actions
314 lines (313 loc) · 14.1 KB
/
Copy pathdatabase.sql
File metadata and controls
314 lines (313 loc) · 14.1 KB
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
-- WARNING: This schema is for context only and is not meant to be run.
-- Table order and constraints may not be valid for execution.
CREATE TABLE public.atp_poll_records (
uri text NOT NULL,
cid text NOT NULL,
record jsonb NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT atp_poll_records_pkey PRIMARY KEY (uri)
);
CREATE TABLE public.atp_poll_votes (
uri text NOT NULL,
record jsonb NOT NULL,
voter_did text NOT NULL,
poll_uri text NOT NULL,
poll_cid text NOT NULL,
indexed_at timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT atp_poll_votes_pkey PRIMARY KEY (uri),
CONSTRAINT atp_poll_votes_poll_uri_fkey FOREIGN KEY (poll_uri) REFERENCES public.atp_poll_records(uri)
);
CREATE TABLE public.bsky_follows (
identity text NOT NULL DEFAULT ''::text,
follows text NOT NULL,
CONSTRAINT bsky_follows_pkey PRIMARY KEY (identity, follows),
CONSTRAINT bsky_follows_follows_fkey FOREIGN KEY (follows) REFERENCES public.identities(atp_did),
CONSTRAINT bsky_follows_identity_fkey FOREIGN KEY (identity) REFERENCES public.identities(atp_did)
);
CREATE TABLE public.bsky_posts (
uri text NOT NULL,
indexed_at timestamp with time zone NOT NULL DEFAULT now(),
post_view jsonb NOT NULL,
cid text NOT NULL,
CONSTRAINT bsky_posts_pkey PRIMARY KEY (uri)
);
CREATE TABLE public.bsky_profiles (
did text NOT NULL,
record jsonb NOT NULL,
indexed_at timestamp with time zone NOT NULL DEFAULT now(),
handle text,
CONSTRAINT bsky_profiles_pkey PRIMARY KEY (did),
CONSTRAINT bsky_profiles_did_fkey FOREIGN KEY (did) REFERENCES public.identities(atp_did)
);
CREATE TABLE public.comments_on_documents (
uri text NOT NULL,
record jsonb NOT NULL,
document text,
indexed_at timestamp with time zone NOT NULL DEFAULT now(),
profile text,
CONSTRAINT comments_on_documents_pkey PRIMARY KEY (uri),
CONSTRAINT comments_on_documents_document_fkey FOREIGN KEY (document) REFERENCES public.documents(uri),
CONSTRAINT comments_on_documents_profile_fkey FOREIGN KEY (profile) REFERENCES public.bsky_profiles(did)
);
CREATE TABLE public.custom_domain_routes (
id uuid NOT NULL DEFAULT gen_random_uuid(),
domain text NOT NULL,
route text NOT NULL,
edit_permission_token uuid NOT NULL,
view_permission_token uuid NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT custom_domain_routes_pkey PRIMARY KEY (id),
CONSTRAINT custom_domain_routes_edit_permission_token_fkey FOREIGN KEY (edit_permission_token) REFERENCES public.permission_tokens(id),
CONSTRAINT custom_domain_routes_view_permission_token_fkey FOREIGN KEY (view_permission_token) REFERENCES public.permission_tokens(id),
CONSTRAINT custom_domain_routes_domain_fkey FOREIGN KEY (domain) REFERENCES public.custom_domains(domain)
);
CREATE TABLE public.custom_domains (
domain text NOT NULL,
identity text DEFAULT ''::text,
confirmed boolean NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT now(),
identity_id uuid,
CONSTRAINT custom_domains_pkey PRIMARY KEY (domain),
CONSTRAINT custom_domains_identity_id_fkey FOREIGN KEY (identity_id) REFERENCES public.identities(id),
CONSTRAINT custom_domains_identity_fkey FOREIGN KEY (identity) REFERENCES public.identities(email)
);
CREATE TABLE public.document_mentions_in_bsky (
uri text NOT NULL,
link text NOT NULL,
document text NOT NULL,
indexed_at timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT document_mentions_in_bsky_pkey PRIMARY KEY (uri, document),
CONSTRAINT document_mentions_in_bsky_document_fkey FOREIGN KEY (document) REFERENCES public.documents(uri),
CONSTRAINT document_mentions_in_bsky_uri_fkey FOREIGN KEY (uri) REFERENCES public.bsky_posts(uri)
);
CREATE TABLE public.documents (
uri text NOT NULL,
data jsonb NOT NULL,
indexed_at timestamp with time zone NOT NULL DEFAULT now(),
sort_date timestamp with time zone DEFAULT LEAST(COALESCE(parse_iso_timestamp((data ->> 'publishedAt'::text)), indexed_at), indexed_at),
bsky_like_count integer NOT NULL DEFAULT 0,
CONSTRAINT documents_pkey PRIMARY KEY (uri)
);
CREATE TABLE public.documents_in_publications (
publication text NOT NULL,
document text NOT NULL,
indexed_at timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT documents_in_publications_pkey PRIMARY KEY (publication, document),
CONSTRAINT documents_in_publications_document_fkey FOREIGN KEY (document) REFERENCES public.documents(uri),
CONSTRAINT documents_in_publications_publication_fkey FOREIGN KEY (publication) REFERENCES public.publications(uri)
);
CREATE TABLE public.email_auth_tokens (
id uuid NOT NULL DEFAULT gen_random_uuid(),
created_at timestamp with time zone NOT NULL DEFAULT now(),
confirmed boolean NOT NULL DEFAULT false,
email text,
confirmation_code text NOT NULL,
identity uuid,
CONSTRAINT email_auth_tokens_pkey PRIMARY KEY (id),
CONSTRAINT email_auth_tokens_identity_fkey FOREIGN KEY (identity) REFERENCES public.identities(id)
);
CREATE TABLE public.email_subscriptions_to_entity (
id uuid NOT NULL DEFAULT gen_random_uuid(),
entity uuid NOT NULL,
email text NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT now(),
token uuid NOT NULL,
confirmed boolean NOT NULL DEFAULT false,
confirmation_code text NOT NULL,
CONSTRAINT email_subscriptions_to_entity_pkey PRIMARY KEY (id),
CONSTRAINT email_subscriptions_to_entity_entity_fkey FOREIGN KEY (entity) REFERENCES public.entities(id),
CONSTRAINT email_subscriptions_to_entity_token_fkey FOREIGN KEY (token) REFERENCES public.permission_tokens(id)
);
CREATE TABLE public.entities (
id uuid NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT now(),
set uuid NOT NULL,
CONSTRAINT entities_pkey PRIMARY KEY (id),
CONSTRAINT entities_set_fkey FOREIGN KEY (set) REFERENCES public.entity_sets(id)
);
CREATE TABLE public.entity_sets (
id uuid NOT NULL DEFAULT gen_random_uuid(),
created_at timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT entity_sets_pkey PRIMARY KEY (id)
);
CREATE TABLE public.facts (
id uuid NOT NULL,
entity uuid NOT NULL,
attribute text NOT NULL,
data jsonb NOT NULL,
created_at timestamp without time zone NOT NULL DEFAULT now(),
updated_at timestamp without time zone,
version bigint NOT NULL DEFAULT '0'::bigint,
CONSTRAINT facts_pkey PRIMARY KEY (id),
CONSTRAINT facts_entity_fkey FOREIGN KEY (entity) REFERENCES public.entities(id)
);
CREATE TABLE public.identities (
id uuid NOT NULL DEFAULT gen_random_uuid(),
created_at timestamp with time zone NOT NULL DEFAULT now(),
home_page uuid NOT NULL DEFAULT create_identity_homepage(),
email text UNIQUE,
atp_did text UNIQUE,
interface_state jsonb,
metadata jsonb,
CONSTRAINT identities_pkey PRIMARY KEY (id),
CONSTRAINT identities_home_page_fkey FOREIGN KEY (home_page) REFERENCES public.permission_tokens(id)
);
CREATE TABLE public.leaflets_in_publications (
publication text NOT NULL,
doc text DEFAULT ''::text,
leaflet uuid NOT NULL,
description text NOT NULL DEFAULT ''::text,
title text NOT NULL DEFAULT ''::text,
archived boolean,
tags ARRAY DEFAULT ARRAY[]::text[],
cover_image text,
preferences jsonb,
CONSTRAINT leaflets_in_publications_pkey PRIMARY KEY (publication, leaflet),
CONSTRAINT leaflets_in_publications_publication_fkey FOREIGN KEY (publication) REFERENCES public.publications(uri),
CONSTRAINT leaflets_in_publications_leaflet_fkey FOREIGN KEY (leaflet) REFERENCES public.permission_tokens(id),
CONSTRAINT leaflets_in_publications_doc_fkey FOREIGN KEY (doc) REFERENCES public.documents(uri)
);
CREATE TABLE public.leaflets_to_documents (
leaflet uuid NOT NULL,
document text NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT now(),
title text NOT NULL DEFAULT ''::text,
description text NOT NULL DEFAULT ''::text,
tags ARRAY DEFAULT ARRAY[]::text[],
cover_image text,
preferences jsonb,
CONSTRAINT leaflets_to_documents_pkey PRIMARY KEY (leaflet, document),
CONSTRAINT leaflets_to_documents_document_fkey FOREIGN KEY (document) REFERENCES public.documents(uri),
CONSTRAINT leaflets_to_documents_leaflet_fkey FOREIGN KEY (leaflet) REFERENCES public.permission_tokens(id)
);
CREATE TABLE public.notifications (
recipient text NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT now(),
read boolean NOT NULL DEFAULT false,
data jsonb NOT NULL,
id uuid NOT NULL,
CONSTRAINT notifications_pkey PRIMARY KEY (id),
CONSTRAINT notifications_recipient_fkey FOREIGN KEY (recipient) REFERENCES public.identities(atp_did)
);
CREATE TABLE public.oauth_session_store (
key text NOT NULL,
session jsonb NOT NULL,
CONSTRAINT oauth_session_store_pkey PRIMARY KEY (key)
);
CREATE TABLE public.oauth_state_store (
key text NOT NULL,
state jsonb NOT NULL,
CONSTRAINT oauth_state_store_pkey PRIMARY KEY (key)
);
CREATE TABLE public.permission_token_on_homepage (
token uuid NOT NULL,
identity uuid NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT now(),
archived boolean,
CONSTRAINT permission_token_on_homepage_pkey PRIMARY KEY (token, identity),
CONSTRAINT permission_token_creator_identity_fkey FOREIGN KEY (identity) REFERENCES public.identities(id),
CONSTRAINT permission_token_on_homepage_token_fkey FOREIGN KEY (token) REFERENCES public.permission_tokens(id)
);
CREATE TABLE public.permission_token_rights (
token uuid NOT NULL,
entity_set uuid NOT NULL,
read boolean NOT NULL DEFAULT false,
write boolean NOT NULL DEFAULT false,
created_at timestamp with time zone NOT NULL DEFAULT now(),
create_token boolean NOT NULL DEFAULT false,
change_entity_set boolean NOT NULL DEFAULT false,
CONSTRAINT permission_token_rights_pkey PRIMARY KEY (token, entity_set),
CONSTRAINT permission_token_rights_entity_set_fkey FOREIGN KEY (entity_set) REFERENCES public.entity_sets(id),
CONSTRAINT permission_token_rights_token_fkey FOREIGN KEY (token) REFERENCES public.permission_tokens(id)
);
CREATE TABLE public.permission_tokens (
id uuid NOT NULL DEFAULT gen_random_uuid(),
root_entity uuid NOT NULL,
blocked_by_admin boolean,
CONSTRAINT permission_tokens_pkey PRIMARY KEY (id),
CONSTRAINT permission_tokens_root_entity_fkey FOREIGN KEY (root_entity) REFERENCES public.entities(id)
);
CREATE TABLE public.phone_number_auth_tokens (
id uuid NOT NULL DEFAULT gen_random_uuid(),
created_at timestamp with time zone NOT NULL DEFAULT now(),
confirmed boolean NOT NULL DEFAULT false,
confirmation_code text NOT NULL,
phone_number text NOT NULL,
country_code text NOT NULL,
CONSTRAINT phone_number_auth_tokens_pkey PRIMARY KEY (id)
);
CREATE TABLE public.phone_rsvps_to_entity (
created_at timestamp with time zone NOT NULL DEFAULT now(),
phone_number text NOT NULL,
country_code text NOT NULL,
status USER-DEFINED NOT NULL,
id uuid NOT NULL DEFAULT gen_random_uuid(),
entity uuid NOT NULL,
name text NOT NULL DEFAULT ''::text,
plus_ones smallint NOT NULL DEFAULT '0'::smallint,
CONSTRAINT phone_rsvps_to_entity_pkey PRIMARY KEY (id),
CONSTRAINT phone_rsvps_to_entity_entity_fkey FOREIGN KEY (entity) REFERENCES public.entities(id)
);
CREATE TABLE public.poll_votes_on_entity (
id uuid NOT NULL DEFAULT gen_random_uuid(),
created_at timestamp with time zone NOT NULL DEFAULT now(),
poll_entity uuid NOT NULL,
option_entity uuid NOT NULL,
voter_token uuid NOT NULL,
CONSTRAINT poll_votes_on_entity_pkey PRIMARY KEY (id),
CONSTRAINT poll_votes_on_entity_option_entity_fkey FOREIGN KEY (option_entity) REFERENCES public.entities(id),
CONSTRAINT poll_votes_on_entity_poll_entity_fkey FOREIGN KEY (poll_entity) REFERENCES public.entities(id)
);
CREATE TABLE public.publication_domains (
publication text NOT NULL,
domain text NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT now(),
identity text NOT NULL,
CONSTRAINT publication_domains_pkey PRIMARY KEY (publication, domain),
CONSTRAINT publication_domains_domain_fkey FOREIGN KEY (domain) REFERENCES public.custom_domains(domain),
CONSTRAINT publication_domains_publication_fkey FOREIGN KEY (publication) REFERENCES public.publications(uri),
CONSTRAINT publication_domains_identity_fkey FOREIGN KEY (identity) REFERENCES public.identities(atp_did)
);
CREATE TABLE public.publication_subscriptions (
publication text NOT NULL,
identity text NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT now(),
record jsonb NOT NULL,
uri text NOT NULL UNIQUE,
CONSTRAINT publication_subscriptions_pkey PRIMARY KEY (publication, identity),
CONSTRAINT publication_subscriptions_publication_fkey FOREIGN KEY (publication) REFERENCES public.publications(uri),
CONSTRAINT publication_subscriptions_identity_fkey FOREIGN KEY (identity) REFERENCES public.identities(atp_did)
);
CREATE TABLE public.publications (
uri text NOT NULL,
indexed_at timestamp with time zone NOT NULL DEFAULT now(),
name text NOT NULL,
identity_did text NOT NULL,
record jsonb,
CONSTRAINT publications_pkey PRIMARY KEY (uri),
CONSTRAINT publications_identity_did_fkey FOREIGN KEY (identity_did) REFERENCES public.identities(atp_did)
);
CREATE TABLE public.recommends_on_documents (
uri text NOT NULL,
record jsonb NOT NULL,
document text NOT NULL,
recommender_did text NOT NULL,
indexed_at timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT recommends_on_documents_pkey PRIMARY KEY (uri),
CONSTRAINT recommends_on_documents_document_fkey FOREIGN KEY (document) REFERENCES public.documents(uri),
CONSTRAINT recommends_on_documents_recommender_did_fkey FOREIGN KEY (recommender_did) REFERENCES public.identities(atp_did)
);
CREATE TABLE public.replicache_clients (
client_id text NOT NULL,
client_group text NOT NULL,
last_mutation bigint NOT NULL,
CONSTRAINT replicache_clients_pkey PRIMARY KEY (client_id)
);
CREATE TABLE public.subscribers_to_publications (
identity text NOT NULL,
publication text NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT subscribers_to_publications_pkey PRIMARY KEY (identity, publication),
CONSTRAINT subscribers_to_publications_identity_fkey FOREIGN KEY (identity) REFERENCES public.identities(email),
CONSTRAINT subscribers_to_publications_publication_fkey FOREIGN KEY (publication) REFERENCES public.publications(uri)
);