diff options
-rw-r--r-- | db/migrate/113_add_external_fields_to_info_requests.rb | 1 | ||||
-rw-r--r-- | db/migrate/20120822145640_correct_external_request_constraint.rb | 15 |
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 |