Skip altering foreign key restrictions
This commit is contained in:
parent
4c62da548b
commit
20e4a73e73
@ -12,53 +12,7 @@ boundary_file=$1
|
|||||||
psql -c "DROP TABLE IF EXISTS boundary"
|
psql -c "DROP TABLE IF EXISTS boundary"
|
||||||
shp2pgsql -s 3857 $boundary_file boundary | psql
|
shp2pgsql -s 3857 $boundary_file boundary | psql
|
||||||
|
|
||||||
# Remove restrictions on deleting linked geometries
|
|
||||||
psql -c "ALTER TABLE ONLY buildings
|
|
||||||
DROP CONSTRAINT buildings_geometry_id_fkey;
|
|
||||||
|
|
||||||
ALTER TABLE ONLY buildings
|
|
||||||
ADD CONSTRAINT buildings_geometry_id_fkey
|
|
||||||
FOREIGN KEY (geometry_id) REFERENCES geometries(geometry_id) ON DELETE CASCADE;
|
|
||||||
|
|
||||||
ALTER TABLE ONLY building_properties
|
|
||||||
DROP CONSTRAINT building_properties_building_id_fkey;
|
|
||||||
|
|
||||||
ALTER TABLE ONLY building_properties
|
|
||||||
ADD CONSTRAINT building_properties_building_id_fkey
|
|
||||||
FOREIGN KEY (building_id) REFERENCES buildings(building_id) ON DELETE CASCADE;
|
|
||||||
|
|
||||||
ALTER TABLE ONLY logs
|
|
||||||
DROP CONSTRAINT logs_building_id_fkey;
|
|
||||||
|
|
||||||
ALTER TABLE ONLY logs
|
|
||||||
ADD CONSTRAINT logs_building_id_fkey
|
|
||||||
FOREIGN KEY (building_id) REFERENCES buildings(building_id) ON DELETE CASCADE;
|
|
||||||
"
|
|
||||||
|
|
||||||
# Delete geometries (hence buildings, building_properties)
|
# Delete geometries (hence buildings, building_properties)
|
||||||
psql -c "DELETE FROM geometries as g
|
psql -c "DELETE FROM geometries as g
|
||||||
USING boundary as b
|
USING boundary as b
|
||||||
WHERE b.gid = 1 AND NOT ST_ContainsProperly(b.geom, g.geometry_geom);"
|
WHERE b.gid = 1 AND NOT ST_ContainsProperly(b.geom, g.geometry_geom);"
|
||||||
|
|
||||||
# Put restrictions back
|
|
||||||
psql -c "ALTER TABLE ONLY buildings
|
|
||||||
DROP CONSTRAINT buildings_geometry_id_fkey;
|
|
||||||
|
|
||||||
ALTER TABLE ONLY buildings
|
|
||||||
ADD CONSTRAINT buildings_geometry_id_fkey
|
|
||||||
FOREIGN KEY (geometry_id) REFERENCES geometries(geometry_id) ON DELETE RESTRICT;
|
|
||||||
|
|
||||||
ALTER TABLE ONLY building_properties
|
|
||||||
DROP CONSTRAINT building_properties_building_id_fkey;
|
|
||||||
|
|
||||||
ALTER TABLE ONLY building_properties
|
|
||||||
ADD CONSTRAINT building_properties_building_id_fkey
|
|
||||||
FOREIGN KEY (building_id) REFERENCES buildings(building_id) ON DELETE RESTRICT;
|
|
||||||
|
|
||||||
ALTER TABLE ONLY logs
|
|
||||||
DROP CONSTRAINT logs_building_id_fkey;
|
|
||||||
|
|
||||||
ALTER TABLE ONLY logs
|
|
||||||
ADD CONSTRAINT logs_building_id_fkey
|
|
||||||
FOREIGN KEY (building_id) REFERENCES buildings(building_id) ON DELETE RESTRICT;
|
|
||||||
"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user