Skip to content
Snippets Groups Projects
Commit 85aabdcc authored by duyanhehe's avatar duyanhehe
Browse files

fix docker using schema

parent 69602d92
No related branches found
No related tags found
No related merge requests found
DROP TABLE IF EXISTS reports, discounts, inventory, reservations, payments, order_items, orders, menu, users, restaurants;
CREATE TABLE restaurants (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
city VARCHAR(100) NOT NULL,
address VARCHAR(255) NOT NULL,
phone VARCHAR(20),
email VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
restaurant_id INT,
full_name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
phone VARCHAR(20),
password_hash VARCHAR(255) NOT NULL,
role ENUM('admin', 'manager', 'staff', 'customer') NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (restaurant_id) REFERENCES restaurants(id) ON DELETE SET NULL
);
CREATE TABLE menu (
id INT AUTO_INCREMENT PRIMARY KEY,
restaurant_id INT,
name VARCHAR(255) NOT NULL,
description TEXT,
price DECIMAL(10,2) NOT NULL,
category VARCHAR(100),
available BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (restaurant_id) REFERENCES restaurants(id) ON DELETE CASCADE
);
CREATE TABLE discounts (
id INT AUTO_INCREMENT PRIMARY KEY,
restaurant_id INT,
code VARCHAR(50) UNIQUE NOT NULL,
description TEXT,
discount_percent DECIMAL(5,2),
valid_from DATE NOT NULL,
valid_to DATE NOT NULL,
status ENUM('active', 'expired') DEFAULT 'active',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (restaurant_id) REFERENCES restaurants(id) ON DELETE CASCADE
);
CREATE TABLE orders (
id INT AUTO_INCREMENT PRIMARY KEY,
restaurant_id INT,
user_id INT NULL,
table_number INT,
total_amount DECIMAL(10,2),
discount_id INT,
discount_amount DECIMAL(10,2),
service_fee DECIMAL(10,2),
vat DECIMAL(10,2),
grand_total DECIMAL(10,2),
order_status ENUM('pending', 'preparing', 'ready', 'completed', 'cancelled') DEFAULT 'pending',
payment_status ENUM('pending', 'paid', 'failed') DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (restaurant_id) REFERENCES restaurants(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL,
FOREIGN KEY (discount_id) REFERENCES discounts(id) ON DELETE SET NULL
);
CREATE TABLE order_items (
id INT AUTO_INCREMENT PRIMARY KEY,
order_id INT,
menu_id INT,
quantity INT NOT NULL,
subtotal DECIMAL(10,2) NOT NULL,
FOREIGN KEY (order_id) REFERENCES orders(id) ON DELETE CASCADE,
FOREIGN KEY (menu_id) REFERENCES menu(id) ON DELETE CASCADE
);
CREATE TABLE payments (
id INT AUTO_INCREMENT PRIMARY KEY,
order_id INT,
user_id INT,
amount DECIMAL(10,2) NOT NULL,
payment_method ENUM('cash', 'credit_card', 'paypal') NOT NULL,
transaction_id VARCHAR(100) UNIQUE,
status ENUM('success', 'failed', 'pending') DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (order_id) REFERENCES orders(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
);
CREATE TABLE reservations (
id INT AUTO_INCREMENT PRIMARY KEY,
restaurant_id INT,
user_id INT,
table_number INT,
reservation_time DATETIME NOT NULL,
status ENUM('pending', 'confirmed', 'cancelled') DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (restaurant_id) REFERENCES restaurants(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
);
CREATE TABLE inventory (
id INT AUTO_INCREMENT PRIMARY KEY,
restaurant_id INT,
item_name VARCHAR(255) NOT NULL,
quantity INT NOT NULL,
unit VARCHAR(50),
last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (restaurant_id) REFERENCES restaurants(id) ON DELETE CASCADE
);
CREATE TABLE reports (
id INT AUTO_INCREMENT PRIMARY KEY,
restaurant_id INT,
report_type ENUM('sales', 'inventory', 'customer_feedback') NOT NULL,
generated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
data JSON NOT NULL,
FOREIGN KEY (restaurant_id) REFERENCES restaurants(id) ON DELETE CASCADE
);
...@@ -34,7 +34,7 @@ services: ...@@ -34,7 +34,7 @@ services:
- "3306:3306" - "3306:3306"
volumes: volumes:
- mysql_data:/var/lib/mysql - mysql_data:/var/lib/mysql
- ./app/schema.sql:/docker-entrypoint-initdb.d/schema.sql
networks: networks:
- app-network - app-network
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment