-- V031 Advanced Data Quality & MDM
-- SQLAlchemy creates the portable schema. PostgreSQL production hardening:
ALTER TABLE IF EXISTS quality_rule_packs_v031 ENABLE ROW LEVEL SECURITY;
ALTER TABLE IF EXISTS quality_rule_packs_v031 FORCE ROW LEVEL SECURITY;
CREATE POLICY quality_rule_packs_tenant_v031 ON quality_rule_packs_v031 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 data_correction_policies_v031 ENABLE ROW LEVEL SECURITY;
ALTER TABLE IF EXISTS data_correction_policies_v031 FORCE ROW LEVEL SECURITY;
CREATE POLICY correction_policies_tenant_v031 ON data_correction_policies_v031 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 quality_correction_runs_v031 ENABLE ROW LEVEL SECURITY;
ALTER TABLE IF EXISTS quality_correction_runs_v031 FORCE ROW LEVEL SECURITY;
CREATE POLICY correction_runs_tenant_v031 ON quality_correction_runs_v031 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 master_merge_proposals_v031 ENABLE ROW LEVEL SECURITY;
ALTER TABLE IF EXISTS master_merge_proposals_v031 FORCE ROW LEVEL SECURITY;
CREATE POLICY merge_proposals_tenant_v031 ON master_merge_proposals_v031 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 data_quality_scorecards_v031 ENABLE ROW LEVEL SECURITY;
ALTER TABLE IF EXISTS data_quality_scorecards_v031 FORCE ROW LEVEL SECURITY;
CREATE POLICY quality_scorecards_tenant_v031 ON data_quality_scorecards_v031 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 advanced_quarantine_records_v031 ENABLE ROW LEVEL SECURITY;
ALTER TABLE IF EXISTS advanced_quarantine_records_v031 FORCE ROW LEVEL SECURITY;
CREATE POLICY advanced_quarantine_tenant_v031 ON advanced_quarantine_records_v031 USING (tenant_id::text=current_setting('app.current_tenant_id',true)) WITH CHECK (tenant_id::text=current_setting('app.current_tenant_id',true));
