-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_schema.sql
More file actions
59 lines (53 loc) · 1.55 KB
/
Copy pathdb_schema.sql
File metadata and controls
59 lines (53 loc) · 1.55 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
CREATE TABLE setting(
name TEXT NOT NULL PRIMARY KEY,
value TEXT NOT NULL
);
CREATE TABLE metadata(
ipfs_cid TEXT NOT NULL PRIMARY KEY,
content TEXT NOT NULL
);
CREATE TABLE shortcut(
id TEXT NOT NULL PRIMARY KEY,
content TEXT NOT NULL
);
CREATE TABLE merchant(
address TEXT NOT NULL,
chain TEXT NOT NULL,
initiator TEXT NOT NULL,
PRIMARY KEY(address, chain)
);
CREATE TABLE product(
hash TEXT NOT NULL PRIMARY KEY,
chain TEXT NOT NULL,
merchant_address TEXT NOT NULL,
token_address TEXT NOT NULL,
token_symbol TEXT NOT NULL,
token_decimals BIGINT NOT NULL,
uint_amount NUMERIC(32, 0) NOT NULL, -- 10^18 * token amount = a big number of digits can happen
human_amount FLOAT NOT NULL,
period BIGINT NOT NULL,
free_trial_length BIGINT NOT NULL,
payment_period BIGINT NOT NULL,
metadata_cid TEXT NOT NULL REFERENCES metadata(ipfs_cid),
merchant_domain TEXT NOT NULL,
product_name TEXT NOT NULL
);
CREATE TABLE subscription(
hash TEXT NOT NULL PRIMARY KEY,
product_hash TEXT NOT NULL REFERENCES product(hash) ON DELETE CASCADE,
user_address TEXT NOT NULL,
start_ts BIGINT NOT NULL,
payments_made BIGINT NOT NULL,
terminated BOOLEAN NOT NULL,
metadata_cid TEXT NOT NULL REFERENCES metadata(ipfs_cid),
subscription_id TEXT, -- nullable
user_id TEXT -- nullable
);
CREATE TABLE subscription_log(
log_id SERIAL PRIMARY KEY,
log_type TEXT NOT NULL,
subscription_hash TEXT NOT NULL REFERENCES subscription(hash) ON DELETE CASCADE,
payment_number BIGINT NOT NULL,
message TEXT NOT NULL,
timestamp BIGINT NOT NULL
);