[TASK-2026-02-03] feat: Add RLS policies to 19-product-attributes.sql
- Added Row Level Security for product_attributes, product_variants - Added tenant isolation policies for related tables - Prepared for execution in WSL Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
b682fdaaf3
commit
c9ddeb8b5a
@ -144,3 +144,41 @@ COMMENT ON COLUMN products.product_variants.price_extra IS 'Ajuste de precio sob
|
||||
COMMENT ON COLUMN products.product_variants.cost_extra IS 'Ajuste de costo sobre el costo base del producto';
|
||||
|
||||
COMMENT ON TABLE products.product_variant_attributes IS 'Tabla de union entre variantes y valores de atributos';
|
||||
|
||||
-- =====================
|
||||
-- RLS (Row Level Security)
|
||||
-- =====================
|
||||
ALTER TABLE products.product_attributes ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE products.product_attribute_values ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE products.product_variants ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE products.product_variant_attributes ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- Politicas RLS para product_attributes
|
||||
DROP POLICY IF EXISTS product_attributes_tenant_isolation ON products.product_attributes;
|
||||
CREATE POLICY product_attributes_tenant_isolation ON products.product_attributes
|
||||
FOR ALL USING (tenant_id = current_setting('app.current_tenant_id', true)::uuid);
|
||||
|
||||
-- Politicas RLS para product_variants
|
||||
DROP POLICY IF EXISTS product_variants_tenant_isolation ON products.product_variants;
|
||||
CREATE POLICY product_variants_tenant_isolation ON products.product_variants
|
||||
FOR ALL USING (tenant_id = current_setting('app.current_tenant_id', true)::uuid);
|
||||
|
||||
-- Politicas RLS para product_attribute_values (via JOIN con attribute)
|
||||
DROP POLICY IF EXISTS product_attribute_values_tenant_isolation ON products.product_attribute_values;
|
||||
CREATE POLICY product_attribute_values_tenant_isolation ON products.product_attribute_values
|
||||
FOR ALL USING (
|
||||
attribute_id IN (
|
||||
SELECT id FROM products.product_attributes
|
||||
WHERE tenant_id = current_setting('app.current_tenant_id', true)::uuid
|
||||
)
|
||||
);
|
||||
|
||||
-- Politicas RLS para product_variant_attributes (via JOIN con variant)
|
||||
DROP POLICY IF EXISTS product_variant_attributes_tenant_isolation ON products.product_variant_attributes;
|
||||
CREATE POLICY product_variant_attributes_tenant_isolation ON products.product_variant_attributes
|
||||
FOR ALL USING (
|
||||
variant_id IN (
|
||||
SELECT id FROM products.product_variants
|
||||
WHERE tenant_id = current_setting('app.current_tenant_id', true)::uuid
|
||||
)
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user