-- V030 Marketplace & Partner Ecosystem
-- As tabelas são também criadas pelo SQLAlchemy no modo nativo.
-- Em PostgreSQL, habilitar RLS nas tabelas vinculadas ao tenant.
ALTER TABLE IF EXISTS tenant_marketplace_installations_v030 ENABLE ROW LEVEL SECURITY;
ALTER TABLE IF EXISTS tenant_marketplace_installations_v030 FORCE ROW LEVEL SECURITY;
DROP POLICY IF EXISTS tenant_marketplace_installations_v030_policy ON tenant_marketplace_installations_v030;
CREATE POLICY tenant_marketplace_installations_v030_policy ON tenant_marketplace_installations_v030
USING (tenant_id::text=current_setting('app.current_tenant_id',true))
WITH CHECK (tenant_id::text=current_setting('app.current_tenant_id',true));
ALTER TABLE IF EXISTS marketplace_licenses_v030 ENABLE ROW LEVEL SECURITY;
ALTER TABLE IF EXISTS marketplace_licenses_v030 FORCE ROW LEVEL SECURITY;
DROP POLICY IF EXISTS marketplace_licenses_v030_policy ON marketplace_licenses_v030;
CREATE POLICY marketplace_licenses_v030_policy ON marketplace_licenses_v030
USING (tenant_id::text=current_setting('app.current_tenant_id',true))
WITH CHECK (tenant_id::text=current_setting('app.current_tenant_id',true));
