aboutsummaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/migrate/112_add_api_key_to_public_bodies.rb18
-rw-r--r--db/migrate/113_add_external_fields_to_info_requests.rb22
-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