-
Notifications
You must be signed in to change notification settings - Fork 0
/
database_schema.sql
79 lines (73 loc) · 1.85 KB
/
database_schema.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
77
78
79
CREATE TABLE stocks_user
(
id INTEGER GENERATED BY DEFAULT AS IDENTITY
CONSTRAINT user_pkey
PRIMARY KEY,
first_name VARCHAR NOT NULL,
second_name VARCHAR,
birthday DATE,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW(),
is_deleted BOOLEAN DEFAULT FALSE
);
CREATE TABLE role
(
role_id INTEGER NOT NULL
PRIMARY KEY,
role_name VARCHAR NOT NULL
);
CREATE TABLE security_info
(
id INTEGER NOT NULL
PRIMARY KEY
REFERENCES stocks_user
ON DELETE CASCADE,
username VARCHAR NOT NULL
UNIQUE,
password VARCHAR NOT NULL,
role_id INTEGER NOT NULL
REFERENCES role,
email VARCHAR NOT NULL
CONSTRAINT security_info_pk
UNIQUE
);
CREATE TABLE stock_meta
(
id INTEGER GENERATED BY DEFAULT AS IDENTITY
PRIMARY KEY,
symbol VARCHAR UNIQUE,
data_interval VARCHAR,
currency VARCHAR(5),
exchange_timezone VARCHAR,
exchange VARCHAR,
mic_code VARCHAR(4),
type_ VARCHAR,
stock_status VARCHAR
);
CREATE TABLE stock_value
(
id INTEGER GENERATED BY DEFAULT AS IDENTITY
PRIMARY KEY,
meta_id INTEGER
REFERENCES stock_meta
ON DELETE CASCADE,
date_time TIMESTAMP NOT NULL,
open NUMERIC(10, 5),
high NUMERIC(10, 5),
low NUMERIC(10, 5),
close NUMERIC(10, 5),
volume INTEGER
);
CREATE TABLE stock_users_fav_stocks
(
user_id INTEGER NOT NULL
REFERENCES stocks_user
ON DELETE CASCADE,
meta_id INTEGER NOT NULL
REFERENCES stock_meta
ON DELETE CASCADE,
PRIMARY KEY (user_id, meta_id)
);
INSERT INTO role (role_id, role_name)
VALUES (1, 'ADMIN'),
(2, 'USER');