-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path1_initialize_schema.up.sql
52 lines (49 loc) · 1.86 KB
/
1_initialize_schema.up.sql
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
-- create tables
CREATE TABLE IF NOT EXISTS trust_domains
(
id text PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
description TEXT,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS relationships
(
id TEXT PRIMARY KEY,
trust_domain_a_id TEXT NOT NULL,
trust_domain_b_id TEXT NOT NULL,
trust_domain_a_consent TEXT NOT NULL DEFAULT 'pending',
trust_domain_b_consent TEXT NOT NULL DEFAULT 'pending',
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE (trust_domain_a_id, trust_domain_b_id),
FOREIGN KEY (trust_domain_a_id)
REFERENCES trust_domains (id),
FOREIGN KEY (trust_domain_b_id)
REFERENCES trust_domains (id)
);
CREATE TABLE IF NOT EXISTS bundles
(
id TEXT PRIMARY KEY,
trust_domain_id TEXT NOT NULL UNIQUE,
data BLOB NOT NULL,
digest BLOB NOT NULL,
signature BLOB,
signing_certificate BLOB,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (trust_domain_id)
REFERENCES trust_domains (id)
);
CREATE TABLE IF NOT EXISTS join_tokens
(
id TEXT PRIMARY KEY,
trust_domain_id TEXT NOT NULL,
token TEXT NOT NULL UNIQUE,
used BOOL NOT NULL DEFAULT 0,
expires_at TIMESTAMP NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (trust_domain_id)
REFERENCES trust_domains (id)
);