aboutsummaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2019-02-12 14:01:38 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2019-02-14 16:55:24 +0000
commitc2089e945132d36468f1d9a3bf08ae4d661cf44a (patch)
tree755780edf643ebd8babb910632eb259623fd8a24 /db
parent1825a09bbdfee97928a251a84534d859b1a43387 (diff)
Allow user to be associated with multiple areas.
Update database to store an array of IDs rather than only one; consequential changes to the admin and the dashboard to allow selection.
Diffstat (limited to 'db')
-rw-r--r--db/downgrade_0066---0065.sql8
-rw-r--r--db/schema.sql2
-rw-r--r--db/schema_0066-user-area-ids.sql7
3 files changed, 16 insertions, 1 deletions
diff --git a/db/downgrade_0066---0065.sql b/db/downgrade_0066---0065.sql
new file mode 100644
index 000000000..7c2b14660
--- /dev/null
+++ b/db/downgrade_0066---0065.sql
@@ -0,0 +1,8 @@
+BEGIN;
+
+ALTER TABLE users ADD COLUMN area_id integer;
+UPDATE users SET area_id = area_ids[1];
+ALTER TABLE users DROP COLUMN area_ids;
+
+COMMIT;
+
diff --git a/db/schema.sql b/db/schema.sql
index c97e8d585..98005028c 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -35,7 +35,7 @@ create table users (
title text,
twitter_id bigint unique,
facebook_id bigint unique,
- area_id integer,
+ area_ids integer ARRAY,
extra text
);
CREATE UNIQUE INDEX users_email_verified_unique ON users (email) WHERE email_verified;
diff --git a/db/schema_0066-user-area-ids.sql b/db/schema_0066-user-area-ids.sql
new file mode 100644
index 000000000..53ffc31f0
--- /dev/null
+++ b/db/schema_0066-user-area-ids.sql
@@ -0,0 +1,7 @@
+BEGIN;
+
+ALTER TABLE users ADD COLUMN area_ids integer ARRAY;
+UPDATE users SET area_ids = ARRAY[area_id] WHERE area_id IS NOT NULL;
+ALTER TABLE users DROP COLUMN area_id;
+
+COMMIT;