-- Create a function to sync site_name to seo_settings
CREATE OR REPLACE FUNCTION sync_site_name_to_seo()
RETURNS TRIGGER AS $$
BEGIN
  IF NEW.key = 'site_name' AND (OLD.value IS NULL OR NEW.value IS DISTINCT FROM OLD.value) THEN
    UPDATE seo_settings SET site_name = NEW.value, updated_at = NOW();
  END IF;
  RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
