diff flys-backend/doc/schema/postgresql-spatial.sql @ 4991:b79eb203032d dami

SCHEMA CHANGE: added 'ON DELETE CASCADE' where necessary to delete complete rivers (only in Postgres-Schema so far)
author Tom Gottfried <tom.gottfried@intevation.de>
date Thu, 14 Feb 2013 17:36:10 +0100
parents a72e90fc45ed
children ecc6fd57b630
line wrap: on
line diff
--- a/flys-backend/doc/schema/postgresql-spatial.sql	Thu Feb 14 10:54:02 2013 +0100
+++ b/flys-backend/doc/schema/postgresql-spatial.sql	Thu Feb 14 17:36:10 2013 +0100
@@ -4,7 +4,7 @@
 CREATE SEQUENCE RIVER_AXES_ID_SEQ;
 CREATE TABLE river_axes (
     id       int PRIMARY KEY NOT NULL,
-    river_id int REFERENCES rivers(id),
+    river_id int REFERENCES rivers(id) ON DELETE CASCADE,
     kind     int             NOT NULL DEFAULT 0,
     name     VARCHAR(64),
     path     VARCHAR(256)
@@ -18,7 +18,7 @@
 CREATE SEQUENCE RIVER_AXES_KM_ID_SEQ;
 CREATE TABLE river_axes_km (
     id       int PRIMARY KEY NOT NULL,
-    river_id int REFERENCES rivers(id),
+    river_id int REFERENCES rivers(id) ON DELETE CASCADE,
     km       FLOAT8 NOT NULL,
     name     VARCHAR(64),
     path     VARCHAR(256)
@@ -31,7 +31,7 @@
 CREATE SEQUENCE CROSS_SECTION_TRACKS_ID_SEQ;
 CREATE TABLE cross_section_tracks (
     id       int PRIMARY KEY NOT NULL,
-    river_id int REFERENCES rivers(id),
+    river_id int REFERENCES rivers(id) ON DELETE CASCADE,
     km       FLOAT8 NOT NULL,
     z        FLOAT8 NOT NULL DEFAULT 0,
     name     VARCHAR(64),
@@ -45,7 +45,7 @@
 CREATE SEQUENCE LINES_ID_SEQ;
 CREATE TABLE lines (
     id       int PRIMARY KEY NOT NULL,
-    river_id int REFERENCES rivers(id),
+    river_id int REFERENCES rivers(id) ON DELETE CASCADE,
     kind     VARCHAR(16) NOT NULL,
     z        FLOAT8 DEFAULT 0,
     name     VARCHAR(64),
@@ -62,7 +62,7 @@
 CREATE SEQUENCE BUILDINGS_ID_SEQ;
 CREATE TABLE buildings (
     id       int PRIMARY KEY NOT NULL,
-    river_id int REFERENCES rivers(id),
+    river_id int REFERENCES rivers(id) ON DELETE CASCADE,
     name     VARCHAR(256),
     path     VARCHAR(256)
 );
@@ -74,7 +74,7 @@
 CREATE SEQUENCE FIXPOINTS_ID_SEQ;
 CREATE TABLE fixpoints (
     id       int PRIMARY KEY NOT NULL,
-    river_id int REFERENCES rivers(id),
+    river_id int REFERENCES rivers(id) ON DELETE CASCADE,
     x        FLOAT8,
     y        FLOAT8,
     km       FLOAT8 NOT NULL,
@@ -90,7 +90,7 @@
 CREATE SEQUENCE FLOODPLAIN_ID_SEQ;
 CREATE TABLE floodplain (
     id       int PRIMARY KEY NOT NULL,
-    river_id int REFERENCES rivers(id),
+    river_id int REFERENCES rivers(id) ON DELETE CASCADE,
     name     VARCHAR(64),
     path     VARCHAR(256)
 );
@@ -102,7 +102,7 @@
 CREATE SEQUENCE DEM_ID_SEQ;
 CREATE TABLE dem (
     id       int PRIMARY KEY NOT NULL,
-    river_id int REFERENCES rivers(id),
+    river_id int REFERENCES rivers(id) ON DELETE CASCADE,
     -- XXX Should we use the ranges table instead?
     name            VARCHAR(64),
     lower           FLOAT8,
@@ -124,7 +124,7 @@
 CREATE SEQUENCE CATCHMENT_ID_SEQ;
 CREATE TABLE catchment (
     id int PRIMARY KEY NOT NULL,
-    river_id int REFERENCES rivers(id),
+    river_id int REFERENCES rivers(id) ON DELETE CASCADE,
     area FLOAT8,
     name VARCHAR(256),
     path     VARCHAR(256)
@@ -169,7 +169,7 @@
     ogr_fid int,
     kind_id int REFERENCES hws_kinds(id) DEFAULT 2,
     fed_state_id int REFERENCES fed_states(id),
-    river_id int REFERENCES rivers(id),
+    river_id int REFERENCES rivers(id) ON DELETE CASCADE,
     name VARCHAR(256),
     path VARCHAR(256),
     offical INT DEFAULT 0,
@@ -194,7 +194,7 @@
     ogr_fid int,
     kind_id int REFERENCES hws_kinds(id) DEFAULT 2,
     fed_state_id int REFERENCES fed_states(id),
-    river_id int REFERENCES rivers(id),
+    river_id int REFERENCES rivers(id) ON DELETE CASCADE,
     name VARCHAR,
     path VARCHAR,
     offical INT DEFAULT 0,
@@ -227,7 +227,7 @@
 CREATE SEQUENCE FLOODMAPS_ID_SEQ;
 CREATE TABLE floodmaps (
     id         int PRIMARY KEY NOT NULL,
-    river_id   int REFERENCES rivers(id),
+    river_id   int REFERENCES rivers(id) ON DELETE CASCADE,
     name       varchar(64) NOT NULL,
     kind       int NOT NULL,
     diff       FLOAT8,
@@ -244,7 +244,7 @@
 CREATE SEQUENCE HYDR_BOUNDARIES_ID_SEQ;
 CREATE TABLE hydr_boundaries (
     id         int PRIMARY KEY NOT NULL,
-    river_id   int REFERENCES rivers(id),
+    river_id   int REFERENCES rivers(id) ON DELETE CASCADE,
     name       VARCHAR(255),
     kind       int, -- 1 BfG / 2 Land / 3 Sonstige
     sectie     int, -- 1 stromführend / 2 stromspeichernd
@@ -258,7 +258,7 @@
 CREATE SEQUENCE HYDR_BOUNDARIES_POLY_ID_SEQ;
 CREATE TABLE hydr_boundaries_poly (
     id         int PRIMARY KEY NOT NULL,
-    river_id   int REFERENCES rivers(id),
+    river_id   int REFERENCES rivers(id) ON DELETE CASCADE,
     name       VARCHAR(255),
     kind       int, -- 1 BfG / 2 Land / 3 Sonstige
     sectie     int, -- 1 Flussschlauch / 2 Uferbank / 3 Überflutungsbereich
@@ -272,7 +272,7 @@
 CREATE SEQUENCE GAUGE_LOCATION_ID_SEQ;
 CREATE TABLE gauge_location (
     id         int PRIMARY KEY NOT NULL,
-    river_id   int REFERENCES rivers(id),
+    river_id   int REFERENCES rivers(id) ON DELETE CASCADE,
     name       VARCHAR(255),
     path       VARCHAR(256)
 );

http://dive4elements.wald.intevation.org