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 | |
parent | 4b312989bb02110fd2402cb4bc7c11656550fe2a (diff) |
Generate an API key for each public body
-rw-r--r-- | app/models/public_body.rb | 3 | ||||
-rw-r--r-- | db/migrate/112_add_api_key_to_public_bodies.rb | 18 |
2 files changed, 20 insertions, 1 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 267b5d60c..5f89878ef 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -17,6 +17,7 @@ # notes :text default(""), not null # first_letter :string(255) not null # publication_scheme :text default(""), not null +# api_key :string(255) not null # # models/public_body.rb: @@ -178,7 +179,7 @@ class PublicBody < ActiveRecord::Base end acts_as_versioned - self.non_versioned_columns << 'created_at' << 'updated_at' << 'first_letter' + self.non_versioned_columns << 'created_at' << 'updated_at' << 'first_letter' << 'api_key' class Version attr_accessor :created_at 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 |