39 lines
2.1 KiB
SQL
39 lines
2.1 KiB
SQL
CREATE TABLE users (
|
|
id SERIAL PRIMARY KEY,
|
|
username VARCHAR(50) NOT NULL UNIQUE,
|
|
password VARCHAR(255) NOT NULL,
|
|
email VARCHAR(100)
|
|
);
|
|
|
|
CREATE TABLE menu_items (
|
|
id SERIAL PRIMARY KEY,
|
|
name VARCHAR(100) NOT NULL,
|
|
description TEXT,
|
|
price DECIMAL(10,2) NOT NULL CHECK (price > 0),
|
|
category VARCHAR(50)
|
|
);
|
|
|
|
CREATE TABLE customer_orders (
|
|
id SERIAL PRIMARY KEY,
|
|
user_id INTEGER NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
total_price DECIMAL(10,2) NOT NULL,
|
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
);
|
|
|
|
CREATE TABLE order_details (
|
|
id SERIAL PRIMARY KEY,
|
|
order_id INTEGER NOT NULL,
|
|
menu_item_id INTEGER NOT NULL,
|
|
quantity INTEGER NOT NULL CHECK (quantity > 0),
|
|
price DECIMAL(10,2) NOT NULL,
|
|
FOREIGN KEY (order_id) REFERENCES customer_orders(id),
|
|
FOREIGN KEY (menu_item_id) REFERENCES menu_items(id)
|
|
);
|
|
|
|
INSERT INTO menu_items (name, description, price, category) VALUES
|
|
('Margherita Pizza', 'Classic tomato and mozzarella', 10.00, 'Pizza'),
|
|
('Cheeseburger', 'Beef patty with cheddar cheese', 8.00, 'Burger'),
|
|
('Spaghetti Carbonara', 'Pasta with egg, cheese, pancetta', 12.00, 'Pasta'),
|
|
('Caesar Salad', 'Romaine lettuce with Caesar dressing', 7.00, 'Salad'),
|
|
('Cola', 'Refreshing carbonated drink', 2.50, 'Drink'); |