aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Houston <robin.houston@gmail.com>2012-08-22 16:01:33 +0100
committerRobin Houston <robin.houston@gmail.com>2012-08-22 16:01:33 +0100
commit1fc5f2fd6208cb8009e46840601798c79aa7d90f (patch)
tree83cc0b395f02ec3683e150901875be439f631a28
parent3247ab6e8b9bacf44383573d6ad064cc8d630001 (diff)
Correct constraint on external requests
-rw-r--r--db/migrate/113_add_external_fields_to_info_requests.rb1
-rw-r--r--db/migrate/20120822145640_correct_external_request_constraint.rb15
2 files changed, 16 insertions, 0 deletions
diff --git a/db/migrate/113_add_external_fields_to_info_requests.rb b/db/migrate/113_add_external_fields_to_info_requests.rb
index 3aea57766..1ad7634ff 100644
--- a/db/migrate/113_add_external_fields_to_info_requests.rb
+++ b/db/migrate/113_add_external_fields_to_info_requests.rb
@@ -4,6 +4,7 @@ class AddExternalFieldsToInfoRequests < ActiveRecord::Migration
add_column :info_requests, :external_user_name, :string, :null => true
add_column :info_requests, :external_url, :string, :null => true
+ # NB This is corrected in 20120822145640
if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
execute "ALTER TABLE info_requests ADD CONSTRAINT info_requests_external_ck CHECK ( (user_id is null) = (external_url is not null) and (external_user_name is not null or external_url is null) )"
end
diff --git a/db/migrate/20120822145640_correct_external_request_constraint.rb b/db/migrate/20120822145640_correct_external_request_constraint.rb
new file mode 100644
index 000000000..6902f3cb2
--- /dev/null
+++ b/db/migrate/20120822145640_correct_external_request_constraint.rb
@@ -0,0 +1,15 @@
+class CorrectExternalRequestConstraint < ActiveRecord::Migration
+ def self.up
+ if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
+ execute "ALTER TABLE info_requests DROP CONSTRAINT info_requests_external_ck"
+ execute "ALTER TABLE info_requests ADD CONSTRAINT info_requests_external_ck CHECK ( (user_id is null) = (external_url is not null) and (external_url is not null or external_user_name is null) )"
+ end
+ end
+
+ def self.down
+ if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
+ execute "ALTER TABLE info_requests DROP CONSTRAINT info_requests_external_ck"
+ execute "ALTER TABLE info_requests ADD CONSTRAINT info_requests_external_ck CHECK ( (user_id is null) = (external_url is not null) and (external_user_name is not null or external_url is null) )"
+ end
+ end
+end