database.sql completed.
This commit is contained in:
Generated
+10
@@ -0,0 +1,10 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Ignored default folder with query files
|
||||||
|
/queries/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
Generated
+13
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="WS-10-Database" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+12
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
|
<data-source source="LOCAL" name="postgres@localhost" uuid="7eaa055b-aec6-4a3e-a6f8-6ca90a4ee622">
|
||||||
|
<driver-ref>postgresql</driver-ref>
|
||||||
|
<synchronize>true</synchronize>
|
||||||
|
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
|
||||||
|
<jdbc-url>jdbc:postgresql://localhost:5432/postgres</jdbc-url>
|
||||||
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
</data-source>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+20
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://maven.myket.ir" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+12
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="25" project-jdk-type="JavaSDK" />
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="SqlDialectMappings">
|
||||||
|
<file url="file://$PROJECT_DIR$/database.sql" dialect="GenericSQL" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
+64
-125
@@ -1,141 +1,80 @@
|
|||||||
-- Restaurant Database Management System
|
|
||||||
--
|
|
||||||
-- Instructions:
|
|
||||||
-- 1. Create all required tables.
|
|
||||||
-- 2. Design appropriate PRIMARY KEY and FOREIGN KEY relationships.
|
|
||||||
-- 3. Add suitable constraints based on the requirements.
|
|
||||||
-- 4. Insert initial mock data.
|
|
||||||
-- 5. Insert at least 3 menu items.
|
|
||||||
-- 6. The script should be executable from start to finish without errors.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- =======================================================
|
|
||||||
-- USER TABLE
|
-- USER TABLE
|
||||||
-- =======================================================
|
CREATE TABLE users (
|
||||||
--
|
id SERIAL PRIMARY KEY,
|
||||||
-- Represents customers using the system.
|
username VARCHAR(50) UNIQUE NOT NULL,
|
||||||
--
|
password VARCHAR(255) NOT NULL,
|
||||||
-- Required information:
|
email VARCHAR(100)
|
||||||
-- - 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
|
-- MENU ITEM TABLE
|
||||||
-- =======================================================
|
CREATE TABLE menu_items (
|
||||||
--
|
id SERIAL PRIMARY KEY,
|
||||||
-- Represents available food and drink items.
|
name VARCHAR(100) NOT NULL,
|
||||||
--
|
description TEXT,
|
||||||
-- Required information:
|
price DECIMAL(10,2) NOT NULL CHECK (price > 0),
|
||||||
-- - Unique identifier
|
category VARCHAR(50)
|
||||||
-- - 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
|
-- ORDER TABLE
|
||||||
-- =======================================================
|
CREATE TABLE orders (
|
||||||
--
|
id SERIAL PRIMARY KEY,
|
||||||
-- Represents orders placed by customers.
|
user_id INT NOT NULL,
|
||||||
--
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
-- Required information:
|
total_price DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||||
-- - Unique identifier
|
CONSTRAINT fk_user_order FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
-- - 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
|
-- ORDER DETAIL TABLE
|
||||||
-- =======================================================
|
CREATE TABLE order_details (
|
||||||
--
|
id SERIAL PRIMARY KEY,
|
||||||
-- Represents items inside an order.
|
order_id INT NOT NULL,
|
||||||
--
|
menu_item_id INT NOT NULL,
|
||||||
-- Required information:
|
quantity INT NOT NULL CHECK (quantity>0),
|
||||||
-- - Unique identifier
|
price_at_purchase DECIMAL(10,2) NOT NULL,
|
||||||
-- - Reference to an order
|
CONSTRAINT fk_detail_order FOREIGN KEY (order_id) REFERENCES orders(id) ON DELETE CASCADE,
|
||||||
-- - Reference to a menu item
|
CONSTRAINT fk_detail_menu FOREIGN KEY (menu_item_id) REFERENCES menu_items(id)
|
||||||
-- - 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
|
-- INITIAL MENU DATA
|
||||||
-- =======================================================
|
INSERT INTO menu_items (name, description, price, category) VALUES
|
||||||
--
|
('Cheeseburger', 'Juicy beef patty with cheddar cheese', 8.99, 'Food'),
|
||||||
-- Insert at least 3 food or drink items.
|
('Pepperoni Pizza', 'Classic pizza with pepperoni and mozzarella', 12.50, 'Food'),
|
||||||
--
|
('Iced Latte', 'Espresso with cold milk and ice', 4.25, 'Drink');
|
||||||
-- Example categories:
|
|
||||||
-- - Pizza
|
|
||||||
-- - Burger
|
|
||||||
-- - Pasta
|
|
||||||
-- - Drink
|
|
||||||
--
|
|
||||||
-- INSERT INTO ...
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- =======================================================
|
|
||||||
-- OPTIONAL TEST DATA
|
-- OPTIONAL TEST DATA
|
||||||
-- =======================================================
|
INSERT INTO users (username, password, email) VALUES
|
||||||
--
|
('mardin_dev', 'hashed_pass_123', 'mardin@example.com'),
|
||||||
-- You may insert sample users and orders for testing.
|
('sara_kh', 'hashed_pass_456', 'sara@example.com');
|
||||||
-- This section is optional.
|
|
||||||
--
|
INSERT INTO orders (user_id, total_price) VALUES
|
||||||
-- INSERT INTO ...
|
(1, 21.49),
|
||||||
|
(2, 4.25);
|
||||||
|
|
||||||
|
INSERT INTO order_details (order_id, menu_item_id, quantity, price_at_purchase) VALUES
|
||||||
|
(1, 1, 1, 8.99),
|
||||||
|
(1, 2, 1, 12.50);
|
||||||
|
|
||||||
|
INSERT INTO order_details (order_id, menu_item_id, quantity, price_at_purchase) VALUES
|
||||||
|
(2, 3, 1, 4.25);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- =======================================================
|
|
||||||
-- VERIFICATION QUERIES
|
-- VERIFICATION QUERIES
|
||||||
-- =======================================================
|
SELECT * FROM users;
|
||||||
--
|
SELECT * FROM menu_items;
|
||||||
-- Uncomment these queries to verify your database.
|
SELECT * FROM orders;
|
||||||
--
|
SELECT * FROM order_details;
|
||||||
-- SELECT * FROM ...;
|
|
||||||
-- SELECT * FROM ...;
|
SELECT
|
||||||
-- SELECT * FROM ...;
|
o.id AS order_number,
|
||||||
-- SELECT * FROM ...;
|
u.username AS customer,
|
||||||
|
m.name AS food_item,
|
||||||
|
od.quantity,
|
||||||
|
od.price_at_purchase,
|
||||||
|
(od.quantity * od.price_at_purchase) AS subtotal,
|
||||||
|
o.created_at
|
||||||
|
FROM orders o
|
||||||
|
JOIN users u ON o.user_id = u.id
|
||||||
|
JOIN order_details od ON od.order_id = o.id
|
||||||
|
JOIN menu_items m ON od.menu_item_id = m.id;
|
||||||
Reference in New Issue
Block a user