This commit is contained in:
2026-06-25 00:38:34 +04:30
parent 00f990c653
commit 976b779736
22 changed files with 637 additions and 128 deletions
+32 -117
View File
@@ -8,125 +8,40 @@
-- 5. Insert at least 3 menu items.
-- 6. The script should be executable from start to finish without errors.
CREATE TABLE users (
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
username VARCHAR(50) UNIQUE,
password_hash VARCHAR(50) NOT NULL,
email VARCHAR(150)
);
CREATE TABLE menu_items (
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name_ VARCHAR(70) NOT NULL,
description_ TEXT,
price NUMERIC(7, 2) NOT NULL CHECK(price > 0),
category VARCHAR(50)
);
CREATE TABLE orders (
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
user_id INT NOT NULL REFERENCES users(id),
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
total_price NUMERIC(7, 2) NOT NULL DEFAULT 0
);
CREATE TABLE order_details (
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
order_id INT NOT NULL REFERENCES orders(id),
menu_item_id INT NOT NULL REFERENCES menu_items(id),
quantity SMALLINT NOT NULL CHECK(quantity > 0),
unit_price NUMERIC(7, 2) NOT NULL CHECK(unit_price > 0)
);
-- =======================================================
-- USER TABLE
-- =======================================================
--
-- Represents customers using the system.
--
-- Required information:
-- - Unique identifier
-- - Username
-- - Password
-- - Email (optional)
--
-- Requirements:
-- - Each user must have a unique identifier.
-- - Usernames must be unique.
-- - Username and password are required.
-- - Passwords should not be stored in plain text.
--
-- CREATE TABLE ...
-- =======================================================
-- MENU ITEM TABLE
-- =======================================================
--
-- Represents available food and drink items.
--
-- Required information:
-- - Unique identifier
-- - Name
-- - Description (optional)
-- - Price
-- - Category (optional)
--
-- Requirements:
-- - Each menu item must have a unique identifier.
-- - Name is required.
-- - Price must always be positive.
--
-- CREATE TABLE ...
-- =======================================================
-- ORDER TABLE
-- =======================================================
--
-- Represents orders placed by customers.
--
-- Required information:
-- - Unique identifier
-- - Reference to customer
-- - Creation date and time
-- - Total price
--
-- Requirements:
-- - Each order must belong to exactly one user.
-- - A user can have multiple orders.
-- - The relationship between User and Order must be implemented.
--
-- Note:
-- Avoid using reserved SQL keywords as table names.
-- Consider using a name such as "orders" or "customer_orders".
--
-- CREATE TABLE ...
-- =======================================================
-- ORDER DETAIL TABLE
-- =======================================================
--
-- Represents items inside an order.
--
-- Required information:
-- - Unique identifier
-- - Reference to an order
-- - Reference to a menu item
-- - Quantity
-- - Item price at purchase time
--
-- Requirements:
-- - Each detail record must belong to one order.
-- - Each detail record must reference one menu item.
-- - Quantity must always be greater than zero.
-- - Store the item's price at the moment of purchase.
--
-- CREATE TABLE ...
-- =======================================================
-- INITIAL MENU DATA
-- =======================================================
--
-- Insert at least 3 food or drink items.
--
-- Example categories:
-- - Pizza
-- - Burger
-- - Pasta
-- - Drink
--
-- INSERT INTO ...
-- =======================================================
-- OPTIONAL TEST DATA
-- =======================================================
--
-- You may insert sample users and orders for testing.
-- This section is optional.
--
-- INSERT INTO ...
INSERT INTO menu_items(name_, description_, price, category) VALUES ('Bacon Pizza', 'Medium', 15.99, 'Pizza');
INSERT INTO menu_items(name_, description_, price, category) VALUES ('Vegan Pizza', 'Small', 10.99, 'Pizza');
INSERT INTO menu_items(name_, description_, price, category) VALUES ('Coke', 'Mini Can', 2.99, 'Drink');
-- =======================================================