diff options
author | Robin Houston <robin.houston@gmail.com> | 2012-06-20 13:58:05 +0100 |
---|---|---|
committer | Robin Houston <robin.houston@gmail.com> | 2012-06-20 13:58:05 +0100 |
commit | a7cc84b9b2b430644fe23e6328d7ab289e7abf0a (patch) | |
tree | f327332c83d35741405be98641fa5b474db2179f /db | |
parent | 6ef57090e436e01bc5de801bc7acb6bfadb5c490 (diff) | |
parent | 89459d3902583fa3d6dad78462d2bf2fa6f94db6 (diff) |
Merge branch 'feature/public-body-api' into develop
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/112_add_api_key_to_public_bodies.rb | 18 | ||||
-rw-r--r-- | db/migrate/113_add_external_fields_to_info_requests.rb | 22 | ||||
-rw-r--r-- | db/migrate/115_add_receive_email_alerts_to_user.rb (renamed from db/migrate/112_add_receive_email_alerts_to_user.rb) | 0 |
3 files changed, 40 insertions, 0 deletions
diff --git a/db/migrate/112_add_api_key_to_public_bodies.rb b/db/migrate/112_add_api_key_to_public_bodies.rb new file mode 100644 index 000000000..24961612d --- /dev/null +++ b/db/migrate/112_add_api_key_to_public_bodies.rb @@ -0,0 +1,18 @@ +require "securerandom" + +class AddApiKeyToPublicBodies < ActiveRecord::Migration + def self.up + add_column :public_bodies, :api_key, :string + + PublicBody.find_each do |pb| + pb.api_key = SecureRandom.base64(32) + pb.save! + end + + change_column_null :public_bodies, :api_key, false + end + + def self.down + remove_column :public_bodies, :api_key + end +end diff --git a/db/migrate/113_add_external_fields_to_info_requests.rb b/db/migrate/113_add_external_fields_to_info_requests.rb new file mode 100644 index 000000000..3aea57766 --- /dev/null +++ b/db/migrate/113_add_external_fields_to_info_requests.rb @@ -0,0 +1,22 @@ +class AddExternalFieldsToInfoRequests < ActiveRecord::Migration + def self.up + change_column_null :info_requests, :user_id, true + add_column :info_requests, :external_user_name, :string, :null => true + add_column :info_requests, :external_url, :string, :null => true + + 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 + end + + def self.down + if ActiveRecord::Base.connection.adapter_name == "PostgreSQL" + execute "ALTER TABLE info_requests DROP CONSTRAINT info_requests_external_ck" + end + + remove_column :info_requests, :external_url + remove_column :info_requests, :external_user_name + + change_column_null :info_requests, :user_id, false + end +end diff --git a/db/migrate/112_add_receive_email_alerts_to_user.rb b/db/migrate/115_add_receive_email_alerts_to_user.rb index 7e06dd275..7e06dd275 100644 --- a/db/migrate/112_add_receive_email_alerts_to_user.rb +++ b/db/migrate/115_add_receive_email_alerts_to_user.rb |