-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.sql
77 lines (67 loc) · 2.26 KB
/
db.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
CREATE TABLE IF NOT EXISTS snapshots (
snapshot_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
total_effective_usd_balance DOUBLE NULL,
creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- query separator
CREATE INDEX IF NOT EXISTS snapshotsByDate ON snapshots(creation_date);
-- query separator
CREATE TABLE IF NOT EXISTS exchange_rates (
snapshot_id INTEGER NOT NULL,
home_asset CHAR(42) NOT NULL,
home_symbol VARCHAR(20) NOT NULL,
exchange_rate DOUBLE NOT NULL,
creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (snapshot_id) REFERENCES snapshots(snapshot_id)
);
-- query separator
CREATE INDEX IF NOT EXISTS exchangeRatesBySnapshotId ON exchange_rates(snapshot_id);
-- query separator
CREATE TABLE IF NOT EXISTS balances (
snapshot_id INTEGER NOT NULL,
address CHAR(32) NOT NULL,
home_asset CHAR(42) NOT NULL,
home_symbol VARCHAR(20) NOT NULL,
balance DOUBLE NOT NULL,
effective_balance DOUBLE NOT NULL,
effective_usd_balance DOUBLE NOT NULL,
creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (snapshot_id) REFERENCES snapshots(snapshot_id),
UNIQUE (snapshot_id, address, home_asset)
);
-- query separator
CREATE TABLE IF NOT EXISTS average_balances (
period CHAR(7) NOT NULL, -- 2023-05
address CHAR(32) NOT NULL,
home_asset CHAR(42) NOT NULL,
home_symbol VARCHAR(20) NOT NULL,
balance DOUBLE NOT NULL,
effective_balance DOUBLE NOT NULL,
effective_usd_balance DOUBLE NOT NULL,
creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (period, address, home_asset)
);
-- query separator
CREATE TABLE IF NOT EXISTS address_types (
address CHAR(32) NOT NULL UNIQUE,
type VARCHAR(10) NOT NULL
);
-- query separator
CREATE TABLE IF NOT EXISTS total_rewards (
period CHAR(7) NOT NULL UNIQUE, -- 2023-05
total_reward INT NOT NULL, -- in bytes
creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
pay_date TIMESTAMP NULL
);
-- query separator
CREATE TABLE IF NOT EXISTS rewards (
period CHAR(7) NOT NULL, -- 2023-05
address CHAR(32) NOT NULL,
share DOUBLE NOT NULL,
reward INT NOT NULL, -- in bytes
creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
pay_date TIMESTAMP NULL,
payment_unit CHAR(44) NULL,
FOREIGN KEY (payment_unit) REFERENCES units(unit),
UNIQUE(period, address)
);