diff --git a/config/migrations/2024/20241024103653-delete-incorrect-links-between-apbs-and-municipalities.sparql b/config/migrations/2024/20241024103653-delete-incorrect-links-between-apbs-and-municipalities.sparql new file mode 100644 index 0000000..1902e4f --- /dev/null +++ b/config/migrations/2024/20241024103653-delete-incorrect-links-between-apbs-and-municipalities.sparql @@ -0,0 +1,36 @@ +PREFIX besluit: +PREFIX org: +PREFIX organisatie: +PREFIX adres: +PREFIX skos: + +DELETE { + GRAPH { + ?municipality org:linkedTo ?apb . + } +} WHERE { + GRAPH { + ?apb a besluit:Bestuurseenheid; + org:classification ; # APB + org:hasPrimarySite/organisatie:bestaatUit/adres:gemeentenaam ?apbMunicipalityName . + ?municipality org:linkedTo ?apb . + # Filter APBs with more than 1 linked municipality, this avoids removing + # triples for APBs created by users. + { + SELECT DISTINCT ?apb + WHERE { + GRAPH { + ?municipality org:linkedTo ?apb . + } + } GROUP BY ?apb HAVING (COUNT(?municipality) > 1) + } + } + # Filter municipalities that are different from the APB's primary site's + # municipality + GRAPH { + ?municipality a besluit:Bestuurseenheid; + org:classification ; # municipality + skos:prefLabel ?municipalityName . + } + FILTER (?apbMunicipalityName != ?municipalityName) +}