Add migration 002: missing updated_at columns + auto-update triggers + indexes
Tables fixed: - rooms → added updated_at - housekeeping_tasks → added updated_at - channels → added created_at + updated_at Trigger function set_updated_at() attached to all 6 tables (hotels, users, rooms, bookings, housekeeping_tasks, channels) — updated_at now auto-sets on every UPDATE via BEFORE UPDATE trigger. Indexes added for archiving / range queries: - bookings(hotel_id, created_at), bookings(hotel_id, updated_at) - housekeeping_tasks(hotel_id, created_at) - rooms(hotel_id, updated_at) - channels(hotel_id, updated_at) Also patched 001_schema.sql so fresh installs start correct. Migration runner is idempotent — skips already applied files. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -43,6 +43,7 @@ CREATE TABLE IF NOT EXISTS rooms (
|
||||
amenities TEXT[] NOT NULL DEFAULT '{}',
|
||||
notes TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE(hotel_id, number)
|
||||
);
|
||||
|
||||
@@ -84,7 +85,8 @@ CREATE TABLE IF NOT EXISTS housekeeping_tasks (
|
||||
notes TEXT,
|
||||
due_date DATE,
|
||||
completed_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- ── Channels ───────────────────────────────────────────────────────────────
|
||||
@@ -97,6 +99,8 @@ CREATE TABLE IF NOT EXISTS channels (
|
||||
api_key_encrypted TEXT,
|
||||
hotel_external_id VARCHAR(255),
|
||||
last_synced_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE(hotel_id, name)
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user