hey, help me create a mysql database for an organisation, they will have services and products they sell online, services to be booked like lessons.... they will be posting about their events, news announcements, classes, ... they will have teachers, students, ....
dont hold back think of everything this database will need but dont complicate it like using roles and permissions ....,
make the sql and but also laravel migration schemas
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Got it! I'll design a clean, practical MySQL database schema for your organization that covers:
Users (teachers, students)
Services (like lessons) that can be booked
Products for sale
Bookings for services
Posts (events, news, announcements, classes)
Basic relationships without complex roles/permissions
Then, I'll provide Laravel migration schemas for each table.
Database Design Overview
Tables:
users — stores teachers and students (simple user table with a type field)
services — services offered (e.g., lessons)
products — products sold online
bookings — bookings for services by students
posts — events, news, announcements, classes
categories — categories for posts (event, news, announcement, class)
teachers_services — pivot table for many-to-many between teachers and services (a service can have multiple teachers)
orders — orders for products
order_items — items in each order
MySQL Schema
sql
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(150) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
type ENUM('teacher', 'student') NOT NULL,
phone VARCHAR(20),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE TABLE services (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(150) NOT NULL,
description TEXT,
price DECIMAL(10,2) NOT NULL,
duration_minutes INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE TABLE teachers_services (
teacher_id INT NOT NULL,
service_id INT NOT NULL,
PRIMARY KEY (teacher_id, service_id),
FOREIGN KEY (teacher_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (service_id) REFERENCES services(id) ON DELETE CASCADE
);
CREATE TABLE products (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(150) NOT NULL,
description TEXT,
price DECIMAL(10,2) NOT NULL,
stock INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE TABLE bookings (
id INT AUTO_INCREMENT PRIMARY KEY,
student_id INT NOT NULL,
service_id INT NOT NULL,
teacher_id INT NOT NULL,
booking_date DATETIME NOT NULL,
status ENUM('pending', 'confirmed', 'cancelled', 'completed') DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (student_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (service_id) REFERENCES services(id) ON DELETE CASCADE,
FOREIGN KEY (teacher_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE categories (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL UNIQUE
);
CREATE TABLE posts (
id INT AUTO_INCREMENT PRIMARY KEY,
category_id INT NOT NULL,
title VARCHAR(200) NOT NULL,
content TEXT NOT NULL,
published_at DATETIME,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL
);
CREATE TABLE orders (
id INT AUTO_INCREMENT PRIMARY KEY,
student_id INT NOT NULL,
total_price DECIMAL(10,2) NOT NULL,
status ENUM('pending', 'paid', 'shipped', 'cancelled') DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (student_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE order_items (
id INT AUTO_INCREMENT PRIMARY KEY,
order_id INT NOT NULL,
product_id INT NOT NULL,
quantity INT NOT NULL,
price DECIMAL(10,2) NOT NULL,
FOREIGN KEY (order_id) REFERENCES orders(id) ON DELETE CASCADE,
FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE
);