konceptualenDizajnLogickiFizicki: kreiranje.sql

File kreiranje.sql, 2.8 KB (added by 213209, 3 weeks ago)
Line 
1drop table if exists item_reservtion_junction;
2drop table if exists Reservation;
3drop type if exists status_enum;
4drop table if exists Restaurant_Table;
5drop table if exists Item;
6drop table if exists Menu;
7drop table if exists Restaurant;
8drop table if exists Payment;
9drop table if exists Customer;
10drop type if exists customer_type;
11
12create type customer_type as enum('premium', 'gold', 'standard', 'platinum');
13
14CREATE TABLE Customer(
15 customerId SERIAL PRIMARY KEY ,
16 registrationDate DATE,
17 firstName TEXT,
18 lastName TEXT,
19 email TEXT,
20 pass TEXT,
21 customer_role customer_type,
22 phone TEXT,
23 address TEXT,
24 membershipLevel INT
25);
26
27CREATE TABLE Payment(
28 paymentId SERIAL PRIMARY KEY,
29 customerId INT DEFAULT -1 REFERENCES Customer(customerId) ON DELETE SET DEFAULT ON UPDATE CASCADE,
30 totalPrice INT NOT NULL,
31 dateCreation DATE,
32 reservationNumber INT
33);
34
35CREATE TABLE Restaurant(
36 restaurantId SERIAL PRIMARY KEY,
37 restaurantName TEXT NOT NULL,
38 address TEXT NOT NULL,
39 cuisineType TEXT,
40 phone TEXT,
41 operatingHours TEXT,
42 website TEXT,
43 deposit FLOAT default 0.0,
44 socialMediaLinks TEXT,
45 rating FLOAT DEFAULT 0.0
46);
47
48CREATE TABLE Menu (
49 menuId INT PRIMARY KEY,
50 restaurantId INT REFERENCES Restaurant(restaurantId) ON DELETE CASCADE ON UPDATE CASCADE,
51 category TEXT not NULL
52);
53
54create table Item(
55 itemId SERIAL primary key,
56 menuId INT REFERENCES Menu(menuId) ON DELETE CASCADE ON UPDATE CASCADE,
57 itemName TEXT,
58 price FLOAT default 0.0,
59 description TEXT,
60 dietaryInformation TEXT
61);
62
63CREATE TABLE Restaurant_Table(
64 tableId SERIAL PRIMARY KEY,
65 restaurantId INT REFERENCES Restaurant(restaurantId) ON DELETE CASCADE ON UPDATE CASCADE,
66 capacity INT NOT NULL,
67 table_location TEXT NOT NULL,
68 isSmokingArea BOOL DEFAULT false,
69 description TEXT
70);
71
72CREATE TYPE status_enum AS ENUM ('reserved', 'canceled', 'pending');
73
74CREATE TABLE Reservation (
75 reservationId SERIAL PRIMARY KEY,
76 customerId INT DEFAULT -1 REFERENCES Customer(customerId) ON DELETE SET DEFAULT ON UPDATE CASCADE,
77 restaurantId INT DEFAULT -1 REFERENCES Restaurant(restaurantId) ON DELETE SET DEFAULT ON UPDATE CASCADE,
78 tableId INT default -1 references Restaurant_Table(tableId) on delete set default on update cascade,
79 paymentStatus bool not null default false,
80 partySize int not null,
81 reservationDateTime Date default (now() at time zone 'utc'),
82 specialRequests text,
83 status status_enum,
84 checkInTime timestamp not null,
85 checkOutTime timestamp not null,
86 totalPrice float default 0.0 not null
87);
88
89CREATE TABLE item_reservation_junction (
90 reservationId INT,
91 itemId INT,
92 PRIMARY KEY(reservationId, itemId),
93 CONSTRAINT fk_reservations FOREIGN KEY(reservationId) REFERENCES Reservation(reservationId),
94 CONSTRAINT fk_item FOREIGN KEY(itemId) REFERENCES Item(itemId)
95);