-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.txt
65 lines (53 loc) · 2.38 KB
/
solution.txt
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
---------------------------------------------------------------------
1.Create Database and connect to it
---------------------------------------------------------------------
psql --username=freecodecamp --dbname=postgres;
CREATE DATABASE salon;
\c salon
---------------------------------------------------------------------
2. Create tables as required conditions
---------------------------------------------------------------------
CREATE TABLE appointments (
appointment_id SERIAL NOT NULL,
customer_id INTEGER NOT NULL
service_id INTEGER NOT NULL,
time VARCHAR(50) NOT NULL
);
CREATE TABLE customers (
customer_id SERIAL NOT NULL,
name VARCHAR(50) NOT NULL,
phone VARCHAR(50) UNIQUE NOT NULL
);
CREATE TABLE services (
service_id SERIAL NOT NULL,
name VARCHAR(50) NOT NULL
);
---------------------------------------------------------------------
3.Fill table services with initial data
---------------------------------------------------------------------
INSERT INTO services VALUES
(1, 'cut' ), (2, 'color'), (3, 'perm' ),
(4, 'style'), (5, 'trim');
---------------------------------------------------------------------
4. Primary Key and Foreign Key assignment
---------------------------------------------------------------------
ALTER TABLE appointments ADD PRIMARY KEY (appointment_id)
ALTER TABLE services ADD PRIMARY KEY (service_id)
ALTER TABLE customers ADD PRIMARY KEY (customer_id)
ALTER TABLE appointments ADD FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
ALTER TABLE appointments ADD FOREIGN KEY (service_id) REFERENCES services (service_id)
---------------------------------------------------------------------
5. Compact sql db queries into worldcup.sql file.
---------------------------------------------------------------------
pg_dump -cC --inserts -U freecodecamp salon > salon.sql
---------------------------------------------------------------------
6.Create shell scipt files and give executable permission to the file
---------------------------------------------------------------------
quit
clear
touch salon.sh
chmod +x salon.sh
---------------------------------------------------------------------
7.Copy & Run shell script files
---------------------------------------------------------------------
./salon.sh