Implement Todos for database and management service
This commit is contained in:
+39
-17
@@ -8,7 +8,10 @@
|
||||
-- 5. Insert at least 3 menu items.
|
||||
-- 6. The script should be executable from start to finish without errors.
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS order_details CASCADE;
|
||||
DROP TABLE IF EXISTS orders CASCADE;
|
||||
DROP TABLE IF EXISTS menu_items CASCADE;
|
||||
DROP TABLE IF EXISTS users CASCADE;
|
||||
|
||||
-- =======================================================
|
||||
-- USER TABLE
|
||||
@@ -28,8 +31,12 @@
|
||||
-- - Username and password are required.
|
||||
-- - Passwords should not be stored in plain text.
|
||||
--
|
||||
-- CREATE TABLE ...
|
||||
|
||||
CREATE TABLE users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
username VARCHAR(50) UNIQUE NOT NULL,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
email VARCHAR(100)
|
||||
);
|
||||
|
||||
|
||||
-- =======================================================
|
||||
@@ -50,8 +57,13 @@
|
||||
-- - Name is required.
|
||||
-- - Price must always be positive.
|
||||
--
|
||||
-- CREATE TABLE ...
|
||||
|
||||
CREATE TABLE menu_items (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
description TEXT,
|
||||
price NUMERIC(10, 2) NOT NULL CHECK (price > 0),
|
||||
category VARCHAR(50)
|
||||
);
|
||||
|
||||
|
||||
-- =======================================================
|
||||
@@ -75,8 +87,12 @@
|
||||
-- Avoid using reserved SQL keywords as table names.
|
||||
-- Consider using a name such as "orders" or "customer_orders".
|
||||
--
|
||||
-- CREATE TABLE ...
|
||||
|
||||
CREATE TABLE orders (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
total_price NUMERIC(10, 2) NOT NULL DEFAULT 0.00
|
||||
);
|
||||
|
||||
|
||||
-- =======================================================
|
||||
@@ -98,8 +114,13 @@
|
||||
-- - Quantity must always be greater than zero.
|
||||
-- - Store the item's price at the moment of purchase.
|
||||
--
|
||||
-- CREATE TABLE ...
|
||||
|
||||
CREATE TABLE order_details (
|
||||
id SERIAL PRIMARY KEY,
|
||||
order_id INT NOT NULL REFERENCES orders(id) ON DELETE CASCADE,
|
||||
menu_item_id INT NOT NULL REFERENCES menu_items(id),
|
||||
quantity INT NOT NULL CHECK (quantity > 0),
|
||||
price NUMERIC(10, 2) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
-- =======================================================
|
||||
@@ -114,8 +135,11 @@
|
||||
-- - Pasta
|
||||
-- - Drink
|
||||
--
|
||||
-- INSERT INTO ...
|
||||
|
||||
INSERT INTO menu_items (name, description, price, category) VALUES
|
||||
('Pizza', 'Delicious cheese pizza with tomato sauce', 10.00, 'Pizza'),
|
||||
('Burger', 'Juicy beef burger with lettuce and tomato', 8.00, 'Burger'),
|
||||
('Pasta', 'Rich creamy Alfredo pasta', 12.00, 'Pasta'),
|
||||
('Soda', 'Cold carbonated drink', 2.50, 'Drink');
|
||||
|
||||
|
||||
-- =======================================================
|
||||
@@ -125,8 +149,6 @@
|
||||
-- You may insert sample users and orders for testing.
|
||||
-- This section is optional.
|
||||
--
|
||||
-- INSERT INTO ...
|
||||
|
||||
|
||||
|
||||
-- =======================================================
|
||||
@@ -135,7 +157,7 @@
|
||||
--
|
||||
-- Uncomment these queries to verify your database.
|
||||
--
|
||||
-- SELECT * FROM ...;
|
||||
-- SELECT * FROM ...;
|
||||
-- SELECT * FROM ...;
|
||||
-- SELECT * FROM ...;
|
||||
SELECT * FROM users;
|
||||
SELECT * FROM menu_items;
|
||||
SELECT * FROM orders;
|
||||
SELECT * FROM order_details;
|
||||
Reference in New Issue
Block a user