-- ============================================================================
-- PHASE 2: RESILIENCE IMPROVEMENTS - Slug Uniqueness Constraints
-- ============================================================================
-- Add UNIQUE constraints on slug columns for companies and ride_models
-- to prevent duplicate slugs and ensure data integrity

-- Add unique constraint to companies.slug
ALTER TABLE companies 
  ADD CONSTRAINT companies_slug_unique UNIQUE (slug);

-- Add unique constraint to ride_models.slug
ALTER TABLE ride_models 
  ADD CONSTRAINT ride_models_slug_unique UNIQUE (slug);

-- Add indexes for performance (if they don't already exist)
CREATE INDEX IF NOT EXISTS idx_companies_slug ON companies(slug);
CREATE INDEX IF NOT EXISTS idx_ride_models_slug ON ride_models(slug);

COMMENT ON CONSTRAINT companies_slug_unique ON companies IS 
  'Ensures each company has a unique slug for URL routing';
  
COMMENT ON CONSTRAINT ride_models_slug_unique ON ride_models IS 
  'Ensures each ride model has a unique slug for URL routing';