-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.sql
More file actions
121 lines (105 loc) · 3.99 KB
/
Copy pathdatabase.sql
File metadata and controls
121 lines (105 loc) · 3.99 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* ---------------------------------------------------------------------- */
-- Create a table called 'users' with the following columns in postgresql:
-- id_user: integer, primary key, autoincrement
-- first_name: varchar
-- last_name: varchar
-- username: varchar
-- email: varchar
-- password: varchar
-- login_status: boolean
CREATE TABLE users (
id_user SERIAL PRIMARY KEY,
first_name VARCHAR,
last_name VARCHAR,
username VARCHAR,
email VARCHAR,
password VARCHAR,
login_status BOOLEAN
);
/* ---------------------------------------------------------------------- */
-- Create a table called 'fiat' with the following columns in postgresql:
-- id_fiat: integer, primary key, autoincrement
-- fiat_name: varchar
-- fiat_symbol: varchar
CREATE TABLE fiats (
id_fiat SERIAL PRIMARY KEY,
fiat_name VARCHAR,
fiat_symbol VARCHAR
);
/* ---------------------------------------------------------------------- */
-- Create a table called 'crypto' with the following columns in postgresql:
-- id_crypto: integer, primary key, autoincrement
-- crypto_name: varchar
-- crypto_symbol: varchar
CREATE TABLE crypto (
id_crypto SERIAL PRIMARY KEY,
crypto_name VARCHAR,
crypto_symbol VARCHAR
);
/* ---------------------------------------------------------------------- */
-- Create a table called 'holdings' with the following columns in postgresql:
-- id_holding: integer, primary key, autoincrement
-- id_user: integer, foreign key
-- id_crypto: integer, foreign key
-- crypto_amount: float
-- id_fiat: integer, foreign key
-- fiat_amount: float
CREATE TABLE holdings (
id_holding SERIAL PRIMARY KEY,
id_user INTEGER,
id_crypto INTEGER,
crypto_name VARCHAR,
crypto_amount FLOAT,
FOREIGN KEY (id_user) REFERENCES users(id_user),
FOREIGN KEY (id_crypto) REFERENCES crypto(id_crypto),
FOREIGN KEY (crypto_name) REFERENCES crypto(crypto_name)
);
/* ---------------------------------------------------------------------- */
-- Create a table called 'favorites' with the following columns in postgresql:
-- id_favorite: integer, primary key, autoincrement
-- id_user: integer, foreign key
-- url: varchar
CREATE TABLE favorites (
id_favorite SERIAL PRIMARY KEY,
id_user INTEGER,
url VARCHAR,
FOREIGN KEY (id_user) REFERENCES users(id_user)
);
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
-- Insert data into the 'users' table:
INSERT INTO users (first_name, last_name, username, email, password, login_status)
VALUES
('John', 'Doe', 'johndoe', 'johndoe@example.com', 'password123', false),
('Jane', 'Smith', 'janesmith', 'janesmith@example.com', 'password456', false);
/* ---------------------------------------------------------------------- */
-- Insert data into the 'fiats' table:
INSERT INTO fiats (fiat_name, fiat_symbol)
VALUES
('US Dollar', 'USD'), ('Euro', 'EUR'),
('British Pound', 'GBP');
/* ---------------------------------------------------------------------- */
-- Insert data into the 'crypto' table:
INSERT INTO crypto (crypto_name, crypto_symbol)
VALUES
('Bitcoin', 'XXBT'),
('Ethereum', 'XETH'),
('Ripple', 'XXRP');
-- Update data in 'crypto' table:
UPDATE crypto
SET crypto_symbol = 'XETH'
WHERE crypto_name = 'Ethereum';
/* ---------------------------------------------------------------------- */
-- Insert data into the 'holdings' table:
INSERT INTO holdings (id_user, id_crypto, crypto_name, crypto_amount)
VALUES
(1, 1, 'Bitcoin', 0.5),
(1, 2, 'Ethereum', 12.2),
(1, 3, 'Ripple', 542.44);
/* ---------------------------------------------------------------------- */
-- Insert data into the 'favorites' table:
INSERT INTO favorites (id_user, url)
VALUES
(1, 'https://api.kraken.com/0/public/OHLC?pair=XETHZUSD&interval=1440&since=1704067200'),
(2, 'https://api.kraken.com/0/public/OHLC?pair=XXBTZGBP&interval=240&since=1704067200');