Voucher-Generator / supabase_migration.sql
Sidd-mukho77
Claude Sonnet 4.5
feat: Add Supabase integration for voucher logging and storage
bf26a87
Raw History Blame Contribute Delete
4.35 kB
-- Supabase Database Migration for Voucher Generator
-- This migration restructures the 'generations' table to support comprehensive voucher logging
-- Safe to run - preserves existing data
-- ==============================================================================
-- STEP 1: Rename existing columns to follow snake_case convention (removes spaces)
-- ==============================================================================
-- Rename columns with spaces to clean snake_case format
ALTER TABLE public.generations
RENAME COLUMN "Hotel Name" TO hotel_name;
ALTER TABLE public.generations
RENAME COLUMN "Guest Name" TO primary_guest_name;
ALTER TABLE public.generations
RENAME COLUMN "Check-in" TO checkin_date;
ALTER TABLE public.generations
RENAME COLUMN "Check-out" TO checkout_date;
ALTER TABLE public.generations
RENAME COLUMN "City" TO city;
ALTER TABLE public.generations
RENAME COLUMN "Address" TO address_line1;
ALTER TABLE public.generations
RENAME COLUMN "Cancellation_Days" TO cancellation_days;
ALTER TABLE public.generations
RENAME COLUMN "Refundable" TO is_refundable;
-- ==============================================================================
-- STEP 2: Add new columns for complete voucher tracking
-- ==============================================================================
-- Add all new columns needed for comprehensive voucher logging
ALTER TABLE public.generations
ADD COLUMN IF NOT EXISTS address_line2 text,
ADD COLUMN IF NOT EXISTS phone text,
ADD COLUMN IF NOT EXISTS num_nights integer NOT NULL DEFAULT 1,
ADD COLUMN IF NOT EXISTS num_guests integer NOT NULL DEFAULT 1,
ADD COLUMN IF NOT EXISTS num_rooms integer NOT NULL DEFAULT 1,
ADD COLUMN IF NOT EXISTS room_type text,
ADD COLUMN IF NOT EXISTS room_size text,
ADD COLUMN IF NOT EXISTS meal_plan text DEFAULT 'Breakfast Only',
ADD COLUMN IF NOT EXISTS policy text DEFAULT 'Non-Refundable',
ADD COLUMN IF NOT EXISTS remarks text,
ADD COLUMN IF NOT EXISTS pdf_filename text NOT NULL DEFAULT 'voucher.pdf',
ADD COLUMN IF NOT EXISTS pdf_url text,
ADD COLUMN IF NOT EXISTS pdf_storage_path text,
ADD COLUMN IF NOT EXISTS tab_source text NOT NULL DEFAULT 'Search Hotel',
ADD COLUMN IF NOT EXISTS is_bulk boolean DEFAULT false,
ADD COLUMN IF NOT EXISTS guest_details jsonb;
-- ==============================================================================
-- STEP 3: Update data type for cancellation_days (optional)
-- ==============================================================================
-- Convert cancellation_days from numeric to integer for consistency
ALTER TABLE public.generations
ALTER COLUMN cancellation_days TYPE integer USING cancellation_days::integer;
-- ==============================================================================
-- VERIFICATION QUERY
-- ==============================================================================
-- Run this query after migration to verify all columns are present
-- SELECT column_name, data_type, is_nullable
-- FROM information_schema.columns
-- WHERE table_name = 'generations'
-- ORDER BY ordinal_position;
-- ==============================================================================
-- FINAL SCHEMA
-- ==============================================================================
-- After running this migration, the 'generations' table will have:
-- - id bigint (primary key, auto-increment)
-- - created_at timestamptz
-- - hotel_name text
-- - primary_guest_name text
-- - checkin_date date
-- - checkout_date date
-- - city text
-- - address_line1 text
-- - address_line2 text (NEW)
-- - phone text (NEW)
-- - num_nights integer (NEW)
-- - num_guests integer (NEW)
-- - num_rooms integer (NEW)
-- - room_type text (NEW)
-- - room_size text (NEW)
-- - meal_plan text (NEW)
-- - policy text (NEW)
-- - is_refundable boolean
-- - cancellation_days integer
-- - remarks text (NEW)
-- - pdf_filename text (NEW)
-- - pdf_url text (NEW)
-- - pdf_storage_path text (NEW)
-- - tab_source text (NEW)
-- - is_bulk boolean (NEW)
-- - guest_details jsonb (NEW)