aboutsummaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-12-14 19:07:08 +0000
committerMatthew Somerville <matthew@mysociety.org>2012-12-19 14:43:26 +0000
commitddf9dbdbf6486c781ca4a5822614b0b7cee2c062 (patch)
tree09c12affc3390138b03292d3f90810287b4941d0 /db
parentda29e8a75eaa92e98807ad89d29d3d1f3c01bc14 (diff)
Allow bodies to span multiple area IDs, and areas can be covered by more than one body.
Diffstat (limited to 'db')
-rw-r--r--db/schema.sql7
-rw-r--r--db/schema_0033-body-areas-many-many.sql15
2 files changed, 21 insertions, 1 deletions
diff --git a/db/schema.sql b/db/schema.sql
index 8045ca6c4..fd0a3abd4 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -420,7 +420,6 @@ create table admin_log (
create table body (
id serial primary key,
name text not null,
- area_id integer not null unique,
endpoint text,
jurisdiction text,
api_key text,
@@ -430,3 +429,9 @@ create table body (
suppress_alerts boolean not null default 'f',
can_be_devolved boolean not null default 'f'
);
+
+create table body_areas (
+ body_id integer not null references body(id),
+ area_id integer not null
+);
+create unique index body_areas_body_id_area_id_idx on body_areas(body_id, area_id);
diff --git a/db/schema_0033-body-areas-many-many.sql b/db/schema_0033-body-areas-many-many.sql
new file mode 100644
index 000000000..e03f3fa44
--- /dev/null
+++ b/db/schema_0033-body-areas-many-many.sql
@@ -0,0 +1,15 @@
+begin;
+
+create table body_areas (
+ body_id integer not null references body(id),
+ area_id integer not null
+);
+create unique index body_areas_body_id_area_id_idx on body_areas(body_id, area_id);
+
+INSERT INTO body_areas (body_id, area_id)
+ SELECT id, area_id FROM body;
+
+ALTER TABLE body DROP COLUMN area_id;
+
+commit;
+