-- Add end_date column to events table to support multi-day events
ALTER TABLE events
ADD COLUMN end_date TIMESTAMP WITH TIME ZONE;

-- Add a check constraint to ensure end_date is after event_date if both are set
ALTER TABLE events
ADD CONSTRAINT check_end_date_after_start_date
CHECK (end_date IS NULL OR event_date IS NULL OR end_date >= event_date);

-- Add index for querying events by end_date
CREATE INDEX idx_events_end_date ON events(end_date);

-- Add comment explaining the column
COMMENT ON COLUMN events.end_date IS 'End date and time of the event. Supports multi-day events (e.g., party starts 8pm and ends 2am next day)';
