-- ═══════════════════════════════════════════════════════════════════════
-- Marketplace — per-tenant employees table migration
-- Apply to: tenant_template, tenant_refaccionaria_demo, tenant_acct_test,
-- and any future tenant DB.
-- ═══════════════════════════════════════════════════════════════════════

ALTER TABLE employees
    ADD COLUMN IF NOT EXISTS marketplace_role VARCHAR(20) NOT NULL DEFAULT 'buyer',
    ADD COLUMN IF NOT EXISTS bodega_id INTEGER;

-- Valid values: 'buyer' (refaccionaria/taller) | 'seller' (bodega) | 'admin'
-- bodega_id references master.bodegas(id_bodega). No FK because that table
-- lives in a different database — the app enforces referential integrity.

CREATE INDEX IF NOT EXISTS idx_employees_marketplace_role ON employees (marketplace_role);
CREATE INDEX IF NOT EXISTS idx_employees_bodega ON employees (bodega_id) WHERE bodega_id IS NOT NULL;
