diff options
author | Dave Arter <davea@mysociety.org> | 2016-07-15 17:02:56 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-08-09 14:44:07 +0100 |
commit | 0c31945416238d7eb06543c107214adfd4b83734 (patch) | |
tree | 1365a012bb5e2bd19e84d827afd2878ae16f7433 | |
parent | 0cecc6857351bfe9a80240a8c0910debd9f8dbe9 (diff) |
Remove check constraint on user body permissions.
We'll soon be adding more new permission types.
-rwxr-xr-x | bin/update-schema | 1 | ||||
-rw-r--r-- | db/downgrade_0041---0040.sql | 9 | ||||
-rw-r--r-- | db/schema.sql | 6 | ||||
-rw-r--r-- | db/schema_0041-remove-permission-types-check.sql | 4 |
4 files changed, 15 insertions, 5 deletions
diff --git a/bin/update-schema b/bin/update-schema index 8f74f34f1..99071f3ea 100755 --- a/bin/update-schema +++ b/bin/update-schema @@ -194,6 +194,7 @@ else { # By querying the database schema, we can see where we're currently at # (assuming schema change files are never half-applied, which should be the case) sub get_db_version { + return '0041' if column_exists('users', 'is_superuser') && ! constraint_exists('user_body_permissions_permission_type_check'); return '0040' if column_exists('users', 'is_superuser'); return '0039' if column_exists('users', 'facebook_id'); return '0038' if column_exists('admin_log', 'time_spent'); diff --git a/db/downgrade_0041---0040.sql b/db/downgrade_0041---0040.sql new file mode 100644 index 000000000..13bf083e8 --- /dev/null +++ b/db/downgrade_0041---0040.sql @@ -0,0 +1,9 @@ +begin; +ALTER TABLE user_body_permissions +ADD CONSTRAINT user_body_permissions_permission_type_check +CHECK ( + permission_type='moderate' or + -- for future expansion -- + permission_type='admin' +); +commit; diff --git a/db/schema.sql b/db/schema.sql index 3f73d2325..f285922ac 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -454,11 +454,7 @@ create table user_body_permissions ( id serial not null primary key, user_id int references users(id) not null, body_id int references body(id) not null, - permission_type text not null check( - permission_type='moderate' or - -- for future expansion -- - permission_type='admin' - ), + permission_type text not null, unique(user_id, body_id, permission_type) ); diff --git a/db/schema_0041-remove-permission-types-check.sql b/db/schema_0041-remove-permission-types-check.sql new file mode 100644 index 000000000..2e4c21050 --- /dev/null +++ b/db/schema_0041-remove-permission-types-check.sql @@ -0,0 +1,4 @@ +BEGIN; +ALTER TABLE user_body_permissions +DROP CONSTRAINT user_body_permissions_permission_type_check; +COMMIT; |