-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbcreate.js
More file actions
64 lines (56 loc) · 1.66 KB
/
Copy pathdbcreate.js
File metadata and controls
64 lines (56 loc) · 1.66 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
var pg = require('pg');
var config = {
user: 'postgres',
password: 'postgres',
database: 'Student-Donor',
port: 5432,
host: 'localhost'
}
var createStudentTableQuery =
'CREATE TABLE Student (' +
' id SERIAL PRIMARY KEY,' +
' firstname text,' +
' lastname text NOT NULL,' +
' street text,' +
' city text,' +
' state text,' +
' zip text,' +
' age integer' +
')';
var createDonorTableQuery =
'CREATE TABLE Donor (' +
' id SERIAL PRIMARY KEY,' +
' firstname text,' +
' lastname text NOT NULL,' +
' street text,' +
' city text,' +
' state text,' +
' zip text' +
')';
var createTripTableQuery =
'CREATE TABLE Trip (' +
' id SERIAL PRIMARY KEY,' +
' name text,' +
' start_date date,' +
' end_date date' +
')';
var createTripAttendanceTableQuery =
'CREATE TABLE TripAttendance (' +
' id SERIAL PRIMARY KEY,' +
' student_id integer REFERENCES Student (id) ON DELETE CASCADE,' +
' trip_id integer REFERENCES Trip (id) ON DELETE CASCADE' +
')';
var createDonationTableQuery =
'CREATE TABLE Donation (' +
' id SERIAL PRIMARY KEY,' +
' donor_id integer REFERENCES Donor (id) ON DELETE CASCADE,' +
' trip_attendance_id integer REFERENCES TripAttendance (id) ON DELETE CASCADE,' +
' amount NUMERIC(7,2)' +
')';
var client = new pg.Client(config);
client.connect();
client.query(createStudentTableQuery);
client.query(createDonorTableQuery);
client.query(createTripTableQuery);
client.query(createDonationTableQuery);
client.query(createTripAttendanceTableQuery);