-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdatabase.sql
More file actions
87 lines (73 loc) · 2.76 KB
/
Copy pathdatabase.sql
File metadata and controls
87 lines (73 loc) · 2.76 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
-- USER is a reserved keyword with Postgres
-- You must use double quotes in every query that user is in:
-- ex. SELECT * FROM "user";
-- Otherwise you will have errors!
-- CREATE TABLE "user" (
-- "id" SERIAL PRIMARY KEY,
-- "username" VARCHAR (80) UNIQUE NOT NULL,
-- "password" VARCHAR (1000) NOT NULL
-- );
-- create user table
CREATE TABLE "user" (
"id" SERIAL PRIMARY KEY,
"username" VARCHAR (80) UNIQUE NOT NULL,
"password" VARCHAR (1000) NOT NULL,
"admin" BOOLEAN DEFAULT false,
"approved" BOOLEAN DEFAULT false,
"registration_date" DATE DEFAULT CURRENT_DATE
);
-- create property table
CREATE TABLE "property" (
"id" SERIAL PRIMARY KEY,
"name" VARCHAR (500),
"address" VARCHAR( 500)
);
-- create booking table
CREATE TABLE "booking" (
"id" SERIAL PRIMARY KEY,
"customer_first_name" VARCHAR (200) NOT NULL,
"customer_last_name" VARCHAR (200) NOT NULL,
"customer_email" VARCHAR (200),
"customer_phone" VARCHAR (200),
"vendor" VARCHAR (200) NOT NULL,
"check_in_date" DATE NOT NULL,
"check_out_date" DATE NOT NULL,
"tax_responsible" BOOLEAN,
"cleaning_fee" MONEY NOT NULL,
"pet_fee" MONEY NOT NULL,
"cost_per_night" MONEY NOT NULL,
"vendor_commission" MONEY NOT NULL,
"vendor_fee" MONEY NOT NULL,
"discount" MONEY NOT NULL,
"lodging_tax" MONEY NOT NULL,
"finalized" BOOLEAN,
"date_entry" TIMESTAMP DEFAULT NOW(),
"property_id" INT REFERENCES "property"
);
-- create comment table
CREATE TABLE "comment" (
"id" SERIAL PRIMARY KEY,
"comment" VARCHAR (1000) NOT NULL,
"user_id" INT REFERENCES "user",
"booking_id" INT REFERENCES "booking"
);
-- create vendor table
CREATE TABLE "vendor" (
"id" SERIAL PRIMARY KEY,
"name" VARCHAR (500) NOT NULL
);
------- for testing only ----------
-- testing tables (money/date)
CREATE TABLE "money" ("money" MONEY );
CREATE TABLE "date" ("date" date);
-- how to insert date
INSERT INTO "date" ("date") VALUES ('2023/03/15'); -- year/month/day
INSERT INTO "date" ("date") values ('10/2/23'); -- month/day/year
INSERT INTO "date" ("date") VALUES ('12-31-2023'); -- month/day/year
-- how to insert money
INSERT INTO "money" ("money") VALUES (500); -- no quotation marks
INSERT INTO "money" ("money") VALUES ('300'); -- with quotation marks
INSERT INTO "money" ("money") VALUES (1000.50); -- with decimal
-- testing a Booking
INSERT INTO "booking" ("customer_first_name", "customer_last_name", "customer_phone", "customer_email", "vendor", "check_in_date", "check_out_date", "tax_responsible", "cleaning_fee", "pet_fee", "cost_per_night", "vendor_commission", "vendor_fee", "discount", "lodging_tax", "finalized", "property_id")
VALUES ('Jerry', 'Bine', '6758 15th Street W', '612-555-3534', 'AirBnb', '05/25/2023', '05/29/2023', 'no', '100', '100.00', '24.53', '23.43', '45.00', '5.00', '32.09', 'no', '1');