- LoyaltyPage: levelBadge() now falls back to bronze for unknown tiers (DB had loyalty_tier='standard' from old seed data) - migration 040: deduplicate general chat rooms + add unique index, normalize loyalty_tier to bronze for non-standard values - chat.ts: ON CONFLICT clause now targets the new partial unique index - Sidebar: DEFAULT_GROUPS only opens 'basics' by default; bump localStorage key to sidebarGroups_v2 to clear stale stored state Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
21 lines
682 B
SQL
21 lines
682 B
SQL
-- Fix 1: unique general chat room per hotel (prevent duplicates on every open)
|
|
-- First deduplicate: keep the oldest general room per hotel, delete the rest
|
|
DELETE FROM chat_rooms
|
|
WHERE type = 'general'
|
|
AND id NOT IN (
|
|
SELECT DISTINCT ON (hotel_id) id
|
|
FROM chat_rooms
|
|
WHERE type = 'general'
|
|
ORDER BY hotel_id, created_at ASC
|
|
);
|
|
|
|
-- Now add the unique constraint
|
|
CREATE UNIQUE INDEX IF NOT EXISTS uq_chat_rooms_general_per_hotel
|
|
ON chat_rooms (hotel_id)
|
|
WHERE type = 'general';
|
|
|
|
-- Fix 2: normalize loyalty_tier values that don't match our 4 tiers
|
|
UPDATE guests
|
|
SET loyalty_tier = 'bronze'
|
|
WHERE loyalty_tier NOT IN ('bronze', 'silver', 'gold', 'platinum');
|