diff options
-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 |