-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_setup.sql
More file actions
50 lines (45 loc) · 2.21 KB
/
database_setup.sql
File metadata and controls
50 lines (45 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
CREATE DATABASE bus_reservation_db;
USE bus_reservation_db;
CREATE TABLE buses (
bus_id INT AUTO_INCREMENT PRIMARY KEY,
bus_name VARCHAR(100) NOT NULL,
bus_type ENUM('AC Sleeper', 'Non-AC Sleeper', 'AC Seater', 'Non-AC Seater') NOT NULL,
total_seats INT NOT NULL
);
CREATE TABLE routes (
route_id INT AUTO_INCREMENT PRIMARY KEY,
source_city VARCHAR(50) NOT NULL,
destination_city VARCHAR(50) NOT NULL,
distance_km INT,
UNIQUE(source_city, destination_city)
);
CREATE TABLE schedules (
schedule_id INT AUTO_INCREMENT PRIMARY KEY,
bus_id INT,
route_id INT,
departure_time DATETIME NOT NULL,
arrival_time DATETIME NOT NULL,
ticket_price DECIMAL(10, 2) NOT NULL,
FOREIGN KEY (bus_id) REFERENCES buses(bus_id),
FOREIGN KEY (route_id) REFERENCES routes(route_id)
);
CREATE TABLE users (
user_id INT AUTO_INCREMENT PRIMARY KEY,
full_name VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
phone VARCHAR(15),
role ENUM('CUSTOMER', 'ADMIN') DEFAULT 'CUSTOMER',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE bookings (
booking_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
schedule_id INT,
seat_number VARCHAR(10) NOT NULL,
booking_status ENUM('CONFIRMED', 'CANCELLED') DEFAULT 'CONFIRMED',
booking_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(user_id),
FOREIGN KEY (schedule_id) REFERENCES schedules(schedule_id),
UNIQUE(schedule_id, seat_number)
);