forked from forbole/callisto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07-pricefeed.sql
More file actions
42 lines (34 loc) · 1.26 KB
/
07-pricefeed.sql
File metadata and controls
42 lines (34 loc) · 1.26 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
/* ---- TOKENS ---- */
CREATE TABLE token
(
name TEXT NOT NULL UNIQUE
);
CREATE TABLE token_unit
(
token_name TEXT NOT NULL REFERENCES token (name),
denom TEXT NOT NULL UNIQUE,
exponent INT NOT NULL,
aliases TEXT[],
price_id TEXT
);
/* ---- TOKEN PRICES ---- */
CREATE TABLE token_price
(
/* Needed for the below token_price function to work properly */
id SERIAL NOT NULL PRIMARY KEY,
unit_name TEXT NOT NULL REFERENCES token_unit (denom) UNIQUE,
price DECIMAL NOT NULL,
market_cap BIGINT NOT NULL,
timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL
);
CREATE INDEX token_price_timestamp_index ON token_price (timestamp);
CREATE TABLE token_price_history
(
id SERIAL NOT NULL PRIMARY KEY,
unit_name TEXT NOT NULL REFERENCES token_unit (denom),
price DECIMAL NOT NULL,
market_cap BIGINT NOT NULL,
timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL,
CONSTRAINT unique_price_for_timestamp UNIQUE (unit_name, timestamp)
);
CREATE INDEX token_price_history_timestamp_index ON token_price_history (timestamp);