diff options
author | Robin Houston <robin.houston@gmail.com> | 2012-05-24 10:45:45 +0100 |
---|---|---|
committer | Robin Houston <robin.houston@gmail.com> | 2012-06-06 19:33:22 +0100 |
commit | 4dec55f3f3672e806b24aef99f6211034c49e9d6 (patch) | |
tree | a5d677ad13ed8ffd1352ae1be62fa51805f05d3b /db | |
parent | 4b312989bb02110fd2402cb4bc7c11656550fe2a (diff) |
Generate an API key for each public body
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/112_add_api_key_to_public_bodies.rb | 18 |
1 files changed, 18 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..92a10bda7 --- /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 :public_bodies, :api_key, :string, :null => false + end + + def self.down + remove_column :public_bodies, :api_key + end +end |