konceptualenDizajnLogickiFizicki: kreiranje.sql

File kreiranje.sql, 2.8 KB (added by 213209, 8 weeks ago)
Line 
1drop table if exists item_reservtion_junction;
2drop table if exists Reservations;
3drop type if exists status_enum;
4drop table if exists Restaurant_Tables;
5drop table if exists Items;
6drop table if exists Menus;
7drop table if exists Restaurants;
8drop table if exists Payments;
9drop table if exists Customers;
10drop type if exists customer_type;
11
12create type customer_type as enum('premium', 'gold', 'standard', 'platinum');
13CREATE TYPE status_enum AS ENUM ('reserved', 'canceled', 'pending');
14
15CREATE TABLE users (
16 id SERIAL PRIMARY KEY,
17 first_name VARCHAR(50),
18 last_name VARCHAR(50),
19 email VARCHAR(100) NOT NULL,
20 password VARCHAR(100) NOT NULL,
21 role VARCHAR(20),
22 phone VARCHAR(20),
23 address TEXT,
24 membership_level VARCHAR(20),
25 registration_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
26);
27
28CREATE TABLE restaurants (
29 restaurant_id SERIAL PRIMARY KEY,
30 name VARCHAR(100),
31 address VARCHAR(255),
32 cuisine_type VARCHAR(50),
33 phone VARCHAR(20),
34 operating_hours VARCHAR(100),
35 website VARCHAR(100),
36 social_media_links TEXT,
37 rating NUMERIC(3, 2)
38);
39
40CREATE TABLE tables (
41 table_id SERIAL PRIMARY KEY,
42 restaurant_id INT REFERENCES restaurants(restaurant_id),
43 capacity INT,
44 location VARCHAR(100),
45 is_smoking_area BOOLEAN,
46 description TEXT,
47 reservation_duration_hours INT DEFAULT 2
48);
49
50CREATE TABLE menus (
51 menu_id SERIAL PRIMARY KEY,
52 restaurant_id INT REFERENCES restaurants(restaurant_id),
53 item_name VARCHAR(100),
54 category VARCHAR(50),
55 price NUMERIC(8, 2),
56 description TEXT
57);
58
59CREATE TABLE menu_tags (
60 id SERIAL PRIMARY KEY,
61 menu_id INT REFERENCES menus(menu_id),
62 tag_name VARCHAR(50),
63 tag_value VARCHAR(50)
64);
65
66CREATE TABLE reservations (
67 reservation_id SERIAL PRIMARY KEY,
68 user_id INT REFERENCES users(id),
69 table_id INT REFERENCES tables(table_id),
70 restaurant_id INT REFERENCES restaurants(restaurant_id),
71 reservation_date_time TIMESTAMP NOT NULL,
72 party_size INT,
73 special_requests TEXT,
74 status VARCHAR(20),
75 check_in_time TIMESTAMP,
76 check_out_time TIMESTAMP,
77 payment_status VARCHAR(20) DEFAULT 'Unpaid'
78);
79
80CREATE TABLE reservation_preordered_items (
81 id SERIAL PRIMARY KEY,
82 reservation_id INT REFERENCES reservations(reservation_id),
83 name VARCHAR(100),
84 quantity INT,
85 price NUMERIC(8, 2)
86);
87
88CREATE TABLE reservation_history (
89 id SERIAL PRIMARY KEY,
90 customer_id INT REFERENCES users(id),
91 table_id INT REFERENCES tables(table_id),
92 restaurant_id INT REFERENCES restaurants(restaurant_id),
93 reservation_datetime TIMESTAMP,
94 party_size INT,
95 special_requests TEXT,
96 status VARCHAR(20),
97 cancellation_reason TEXT,
98 check_in_date TIMESTAMP
99);