-- Migration 006 — Perfil público (slug/QR) + auth_provider.
-- Aplica sobre 005.

ALTER TABLE tenants
    ADD COLUMN public_slug VARCHAR(80) NULL,
    ADD UNIQUE KEY uq_tenants_public_slug (public_slug);

ALTER TABLE users
    ADD COLUMN auth_provider ENUM('google','password') NULL AFTER role;

-- Backfill: slug simple y único para negocios existentes (los nuevos lo arman desde el nombre real).
UPDATE tenants SET public_slug = CONCAT('negocio-', id) WHERE public_slug IS NULL;

-- Backfill: proveedor de auth según si ya tienen google_sub.
UPDATE users SET auth_provider = 'google' WHERE google_sub IS NOT NULL AND auth_provider IS NULL;
UPDATE users SET auth_provider = 'password' WHERE auth_provider IS NULL;
