refactor(db): drop end_time DEFAULT and add booking/payment indexes
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -380,7 +380,7 @@ CREATE TABLE bookings (
|
||||
-- Computed fields (maintained by trigger on booking_services/booking_custom_services)
|
||||
total_duration_minutes INT NOT NULL DEFAULT 60,
|
||||
total_amount NUMERIC(10,2) NOT NULL DEFAULT 0,
|
||||
end_time TIMESTAMPTZ NOT NULL DEFAULT NOW(), -- Set by BEFORE INSERT trigger; recalculated by booking_services trigger
|
||||
end_time TIMESTAMPTZ NOT NULL, -- Set by BEFORE INSERT trigger; recalculated by booking_services trigger
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
created_by CHAR(12),
|
||||
@@ -392,6 +392,7 @@ CREATE INDEX idx_bookings_userid_starttime ON bookings(user_id, start_time);
|
||||
CREATE INDEX idx_bookings_end_time ON bookings(end_time);
|
||||
CREATE INDEX idx_bookings_status_end_time ON bookings(status, end_time);
|
||||
CREATE INDEX IF NOT EXISTS idx_bookings_notes_trgm ON bookings USING GIN (notes gin_trgm_ops);
|
||||
CREATE INDEX IF NOT EXISTS idx_bookings_start_time ON bookings(start_time);
|
||||
|
||||
ALTER TABLE name_history ADD CONSTRAINT fk_name_history_booking_id
|
||||
FOREIGN KEY (booking_id) REFERENCES bookings(id) ON DELETE SET NULL;
|
||||
@@ -601,7 +602,6 @@ CREATE TABLE time_blockers (
|
||||
-- Indexes for efficient overlap queries
|
||||
CREATE INDEX idx_time_blockers_start_time ON time_blockers(start_time);
|
||||
CREATE INDEX idx_time_blockers_cron ON time_blockers(cron_expression) WHERE cron_expression IS NOT NULL;
|
||||
CREATE INDEX idx_time_blockers_description ON time_blockers(description);
|
||||
CREATE INDEX idx_time_blockers_created_by ON time_blockers(created_by);
|
||||
CREATE INDEX IF NOT EXISTS idx_time_blockers_desc_trgm ON time_blockers USING GIN (description gin_trgm_ops);
|
||||
|
||||
@@ -660,6 +660,7 @@ CREATE INDEX idx_payments_bookingid ON payments(booking_id);
|
||||
CREATE INDEX idx_payments_status ON payments(status);
|
||||
CREATE INDEX idx_payments_createdat ON payments(created_at);
|
||||
CREATE INDEX idx_payments_booking_id_status ON payments(booking_id, status);
|
||||
CREATE INDEX IF NOT EXISTS idx_payments_booking_status_created ON payments(booking_id, status, created_at);
|
||||
CREATE INDEX idx_payments_created_at_status ON payments(created_at, status);
|
||||
CREATE INDEX idx_payments_payment_method ON payments(payment_method);
|
||||
CREATE INDEX idx_payments_payment_method_created_at ON payments(payment_method, created_at);
|
||||
|
||||
Reference in New Issue
Block a user