From 214a11ec9d22ba24121f56caa5a7469195703746 Mon Sep 17 00:00:00 2001 From: HotelSync Date: Thu, 26 Mar 2026 11:06:44 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20migration=20040=20=E2=80=94=20drop=20old?= =?UTF-8?q?=20loyalty=5Ftier=20check=20constraint=20before=20renaming=20st?= =?UTF-8?q?andard=E2=86=92bronze?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The guests table had CHECK (loyalty_tier IN ('standard','silver','gold','platinum')) but the UI expects 'bronze' not 'standard'. Drop the old constraint, migrate 'standard' rows to 'bronze', then add the correct constraint. Co-Authored-By: Claude Sonnet 4.6 --- backend/migrations/040_fixes.sql | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/migrations/040_fixes.sql b/backend/migrations/040_fixes.sql index 64ba10b..73898db 100644 --- a/backend/migrations/040_fixes.sql +++ b/backend/migrations/040_fixes.sql @@ -14,7 +14,16 @@ 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 +-- Fix 2: replace 'standard' tier with 'bronze' (the UI uses bronze/silver/gold/platinum) +-- Drop the old check constraint that only allows 'standard' instead of 'bronze' +ALTER TABLE guests DROP CONSTRAINT IF EXISTS guests_loyalty_tier_check; + +-- Add the correct constraint +ALTER TABLE guests + ADD CONSTRAINT guests_loyalty_tier_check + CHECK (loyalty_tier IN ('bronze', 'silver', 'gold', 'platinum')); + +-- Migrate existing 'standard' rows to 'bronze' UPDATE guests SET loyalty_tier = 'bronze' WHERE loyalty_tier NOT IN ('bronze', 'silver', 'gold', 'platinum');