-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabase_schema.sql
More file actions
112 lines (94 loc) · 4.24 KB
/
database_schema.sql
File metadata and controls
112 lines (94 loc) · 4.24 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
-- Cleaned Database Schema for ImpactOne Booking System
-- This schema removes unused columns and keeps only what's actively used
-- ============================================
-- TABLE: bookings
-- ============================================
CREATE TABLE public.bookings (
-- Primary Key
id uuid NOT NULL DEFAULT gen_random_uuid(),
-- Resource Information
resource_type text NOT NULL CHECK (resource_type = ANY (ARRAY['venue'::text, 'bus'::text, 'turf'::text])),
resource_id text NOT NULL,
resource_name text NOT NULL,
sub_area text, -- Optional sub-area (e.g., specific court in turf)
facility text, -- Not used in current implementation, consider removing if not needed
-- Booking Date & Time
booking_date timestamp with time zone NOT NULL,
start_time text, -- For custom time bookings
end_time text, -- For custom time bookings
selected_slots text[], -- Array of time slots (e.g., ['09:00', '09:30', '10:00'])
duration_type text CHECK (duration_type = ANY (ARRAY['custom'::text, 'full-day'::text])),
-- Event Details
event_title text NOT NULL,
event_description text NOT NULL,
attendees integer NOT NULL CHECK (attendees >= 0),
-- Department & Category
department text NOT NULL,
department_category text,
-- Requester Information
requester_id text NOT NULL,
requester_name text NOT NULL,
requester_email text,
-- Faculty Information
faculty_incharge text,
contact_email text,
contact_number text,
-- Booking Status & Review
status text NOT NULL CHECK (status = ANY (ARRAY['Pending'::text, 'Approved'::text, 'Rejected'::text, 'Cancelled'::text])),
reviewed_at timestamp with time zone,
reviewed_by text,
cancellation_reason text, -- Reason for cancellation (if cancelled)
-- Timestamps
created_at timestamp with time zone DEFAULT now(),
updated_at timestamp with time zone DEFAULT now(),
-- Primary Key Constraint
CONSTRAINT bookings_pkey PRIMARY KEY (id)
);
-- ============================================
-- TABLE: notifications
-- ============================================
CREATE TABLE public.notifications (
id uuid NOT NULL DEFAULT gen_random_uuid(),
user_id text NOT NULL,
title text NOT NULL,
message text NOT NULL,
type text DEFAULT 'info'::text CHECK (type = ANY (ARRAY['info'::text, 'success'::text, 'warning'::text, 'error'::text])),
read boolean DEFAULT false,
created_at timestamp with time zone DEFAULT now(),
booking_id uuid,
CONSTRAINT notifications_pkey PRIMARY KEY (id),
CONSTRAINT notifications_booking_id_fkey FOREIGN KEY (booking_id) REFERENCES public.bookings(id) ON DELETE CASCADE
);
-- ============================================
-- INDEXES for Performance
-- ============================================
-- Index for faster booking queries by date
CREATE INDEX idx_bookings_booking_date ON public.bookings(booking_date);
-- Index for faster status queries
CREATE INDEX idx_bookings_status ON public.bookings(status);
-- Index for requester queries
CREATE INDEX idx_bookings_requester_id ON public.bookings(requester_id);
CREATE INDEX idx_bookings_requester_email ON public.bookings(requester_email);
-- Index for notifications by user
CREATE INDEX idx_notifications_user_id ON public.notifications(user_id);
CREATE INDEX idx_notifications_read ON public.notifications(read);
-- ============================================
-- NOTES
-- ============================================
--
-- Columns in Use:
-- - All resource fields (resource_type, resource_id, resource_name, sub_area)
-- - All date/time fields (booking_date, start_time, end_time, selected_slots, duration_type)
-- - All event fields (event_title, event_description, attendees)
-- - All requester fields (requester_id, requester_name, requester_email)
-- - All faculty fields (faculty_incharge, contact_email, contact_number)
-- - All status fields (status, reviewed_at, reviewed_by, cancellation_reason)
-- - All department fields (department, department_category)
--
-- Potentially Unused:
-- - facility: Not seen in current UI, verify before removing
--
-- Recommendations:
-- 1. If 'facility' is not used, remove it
-- 2. Consider adding ON DELETE CASCADE to notification foreign key (already added above)
-- 3. Add indexes for frequently queried columns (already added above)