Added updated_at information to more tables

This commit is contained in:
Soham Chari 2025-12-14 20:15:01 +05:30
parent 3245d83aed
commit 49721086f3
1 changed files with 13 additions and 5 deletions

View File

@ -123,7 +123,7 @@ CREATE TABLE users (
deleted BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
last_login_at TIMESTAMPTZ
last_login_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE TRIGGER trg_users_updated_at BEFORE UPDATE ON users FOR EACH ROW EXECUTE FUNCTION set_updated_at();
@ -271,7 +271,7 @@ CREATE TABLE listings (
-- DENORMALIZED COLUMNS (Auto-filled by Trigger)
-- These exist so the Home Feed doesn't need to join 4 tables
filter_species_id UUID,
filter_species_id UUID,
filter_breed_id UUID,
filter_sex sex_enum,
filter_age_months INT,
@ -345,8 +345,10 @@ CREATE TABLE custom_requirements (
requirement_text TEXT NOT NULL,
status requirement_status_enum NOT NULL DEFAULT 'open',
deleted BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE TRIGGER trg_custom_requirements_updated_at BEFORE UPDATE ON custom_requirements FOR EACH ROW EXECUTE FUNCTION set_updated_at();
-- New: High-speed analytics buffer
CREATE TABLE listing_analytics_events (
@ -382,6 +384,7 @@ CREATE TABLE reviews (
updated_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(listing_id, reviewer_id)
);
CREATE TRIGGER trg_reviews_updated_at BEFORE UPDATE ON reviews FOR EACH ROW EXECUTE FUNCTION set_updated_at();
-- 10. CHAT & COMMUNICATIONS
-- ======================================================
@ -417,8 +420,11 @@ CREATE TABLE messages (
is_read BOOLEAN NOT NULL DEFAULT FALSE,
read_at TIMESTAMPTZ,
deleted BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE TRIGGER trg_messages_updated_at BEFORE UPDATE ON messages FOR EACH ROW EXECUTE FUNCTION set_updated_at();
-- Efficient Index for Cursor Pagination: (conversation as filter, id as cursor)
CREATE INDEX idx_messages_pagination ON messages(conversation_id, id DESC) WHERE deleted = FALSE;
@ -431,8 +437,10 @@ CREATE TABLE communication_records (
call_status call_status_enum NOT NULL,
duration_seconds INT DEFAULT 0,
call_recording_url TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE TRIGGER trg_communication_records_updated_at BEFORE UPDATE ON communication_records FOR EACH ROW EXECUTE FUNCTION set_updated_at();
-- 11. AUTOMATION TRIGGERS
-- ======================================================