1CREATE TABLE IF NOT EXISTS record (
2 did text NOT NULL,
3 collection text NOT NULL,
4 rkey text NOT NULL,
5 rev text NOT NULL,
6 cid text NOT NULL,
7 live boolean NOT NULL,
8 data jsonb NOT NULL,
9
10 PRIMARY KEY (did, collection, rkey)
11);
12
13CREATE INDEX ON record (collection);
14
15CREATE TABLE IF NOT EXISTS deleted_record (
16 LIKE record
17 INCLUDING all
18);
19
20DO $$ BEGIN
21 CREATE TYPE identity_status AS ENUM (
22 'active',
23 'takendown',
24 'suspended',
25 'deactivated',
26 'deleted'
27 );
28EXCEPTION
29 WHEN duplicate_object THEN null;
30END $$;
31
32CREATE TABLE IF NOT EXISTS identity (
33 did text NOT NULL,
34 handle text NOT NULL,
35 active boolean NOT NULL,
36 status identity_status NOT NULL,
37
38 PRIMARY KEY (did)
39);
40
41CREATE INDEX ON identity (handle);
42
43CREATE OR REPLACE VIEW record_by_collection AS
44 SELECT collection,
45 count(*) AS count
46 FROM record
47 GROUP BY collection
48 ORDER BY (count(*)) DESC;