-- Add is_test_data flag to all entity tables for test data identification
-- This allows safe cleanup and filtering of test data from production queries

-- Add is_test_data column to parks
ALTER TABLE public.parks 
ADD COLUMN IF NOT EXISTS is_test_data BOOLEAN DEFAULT false;

CREATE INDEX IF NOT EXISTS idx_parks_is_test_data ON public.parks(is_test_data) WHERE is_test_data = true;

-- Add is_test_data column to rides
ALTER TABLE public.rides 
ADD COLUMN IF NOT EXISTS is_test_data BOOLEAN DEFAULT false;

CREATE INDEX IF NOT EXISTS idx_rides_is_test_data ON public.rides(is_test_data) WHERE is_test_data = true;

-- Add is_test_data column to companies
ALTER TABLE public.companies 
ADD COLUMN IF NOT EXISTS is_test_data BOOLEAN DEFAULT false;

CREATE INDEX IF NOT EXISTS idx_companies_is_test_data ON public.companies(is_test_data) WHERE is_test_data = true;

-- Add is_test_data column to ride_models
ALTER TABLE public.ride_models 
ADD COLUMN IF NOT EXISTS is_test_data BOOLEAN DEFAULT false;

CREATE INDEX IF NOT EXISTS idx_ride_models_is_test_data ON public.ride_models(is_test_data) WHERE is_test_data = true;

-- Add is_test_data column to content_submissions
ALTER TABLE public.content_submissions 
ADD COLUMN IF NOT EXISTS is_test_data BOOLEAN DEFAULT false;

CREATE INDEX IF NOT EXISTS idx_content_submissions_is_test_data ON public.content_submissions(is_test_data) WHERE is_test_data = true;

-- Add is_test_data column to submission_items
ALTER TABLE public.submission_items 
ADD COLUMN IF NOT EXISTS is_test_data BOOLEAN DEFAULT false;

CREATE INDEX IF NOT EXISTS idx_submission_items_is_test_data ON public.submission_items(is_test_data) WHERE is_test_data = true;

-- Add is_test_data column to version tables
ALTER TABLE public.park_versions 
ADD COLUMN IF NOT EXISTS is_test_data BOOLEAN DEFAULT false;

ALTER TABLE public.ride_versions 
ADD COLUMN IF NOT EXISTS is_test_data BOOLEAN DEFAULT false;

ALTER TABLE public.company_versions 
ADD COLUMN IF NOT EXISTS is_test_data BOOLEAN DEFAULT false;

ALTER TABLE public.ride_model_versions 
ADD COLUMN IF NOT EXISTS is_test_data BOOLEAN DEFAULT false;

-- Add is_test_data column to photos
ALTER TABLE public.photos 
ADD COLUMN IF NOT EXISTS is_test_data BOOLEAN DEFAULT false;

CREATE INDEX IF NOT EXISTS idx_photos_is_test_data ON public.photos(is_test_data) WHERE is_test_data = true;

-- Add is_test_data column to reviews
ALTER TABLE public.reviews 
ADD COLUMN IF NOT EXISTS is_test_data BOOLEAN DEFAULT false;

CREATE INDEX IF NOT EXISTS idx_reviews_is_test_data ON public.reviews(is_test_data) WHERE is_test_data = true;

-- Add is_test_data column to test_data_registry
ALTER TABLE public.test_data_registry 
ADD COLUMN IF NOT EXISTS is_test_data BOOLEAN DEFAULT true;

COMMENT ON COLUMN public.parks.is_test_data IS 'Flag to identify test data for safe cleanup and filtering';
COMMENT ON COLUMN public.rides.is_test_data IS 'Flag to identify test data for safe cleanup and filtering';
COMMENT ON COLUMN public.companies.is_test_data IS 'Flag to identify test data for safe cleanup and filtering';
COMMENT ON COLUMN public.ride_models.is_test_data IS 'Flag to identify test data for safe cleanup and filtering';
COMMENT ON COLUMN public.content_submissions.is_test_data IS 'Flag to identify test data for safe cleanup and filtering';
COMMENT ON COLUMN public.submission_items.is_test_data IS 'Flag to identify test data for safe cleanup and filtering';