-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbooking.sql
More file actions
76 lines (63 loc) · 2.38 KB
/
booking.sql
File metadata and controls
76 lines (63 loc) · 2.38 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
CREATE TABLE users (
id BIGSERIAL PRIMARY KEY,
full_name VARCHAR(120) NOT NULL,
email VARCHAR(120) UNIQUE NOT NULL,
phone VARCHAR(30),
password_hash TEXT NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
-- Category for resources (ex: Meeting Room, VIP Room, Massage Service, etc)
CREATE TABLE resource_types (
id BIGSERIAL PRIMARY KEY,
name VARCHAR(120) NOT NULL
);
-- Bookable resources (ex: Room A, Room B, Haircut Service)
CREATE TABLE resources (
id BIGSERIAL PRIMARY KEY,
type_id BIGINT REFERENCES resource_types(id),
name VARCHAR(160) NOT NULL,
description TEXT,
price_per_unit DECIMAL(10,2) NOT NULL, -- price per hour/day/service
unit VARCHAR(30) DEFAULT 'hour', -- hour/day/session
is_active BOOLEAN DEFAULT TRUE
);
-- User creates a booking
CREATE TABLE bookings (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT REFERENCES users(id),
status VARCHAR(50) DEFAULT 'pending', -- pending, confirmed, cancelled, completed
total_amount DECIMAL(10,2) NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
-- Resources inside the booking with date/time range
CREATE TABLE booking_items (
id BIGSERIAL PRIMARY KEY,
booking_id BIGINT REFERENCES bookings(id),
resource_id BIGINT REFERENCES resources(id),
start_time TIMESTAMP NOT NULL,
end_time TIMESTAMP NOT NULL,
price DECIMAL(10,2) NOT NULL,
quantity INT DEFAULT 1
);
-- Payment record
CREATE TABLE payments (
id BIGSERIAL PRIMARY KEY,
booking_id BIGINT REFERENCES bookings(id),
amount DECIMAL(10,2) NOT NULL,
provider VARCHAR(50), -- ABA, Wing, Stripe, PayPal
status VARCHAR(50) DEFAULT 'pending',
paid_at TIMESTAMP
);
-- 🎯 Core Requirements of a Booking System
-- Users can register + login
-- There are resources that can be booked (rooms / services / items)
-- Bookings have date/time and status
-- One booking may include payments
-- Support for availability checking
-- | Feature | Description |
-- | --------------------------- | ------------------------------ |
-- | Staff Accounts | Admin & employee roles |
-- | Cancellation & Refund rules | Flexible booking policy |
-- | Calendar View API | For showing availability in UI |
-- | Notifications | Telegram/Email/WhatsApp alerts |
-- | Price rules | Weekend / seasonal pricing |