Change migration to prevent down

This commit is contained in:
Robin Ward 2013-10-22 17:51:04 -04:00
parent e94a8cf62e
commit 6394d924c8
2 changed files with 8 additions and 2 deletions

View file

@ -12,7 +12,7 @@ class ApiKey < ActiveRecord::Base
end end
def self.create_master_key def self.create_master_key
api_key = ApiKey.where('user_id IS NULL').first api_key = ApiKey.where(user_id: nil).first
if api_key.blank? if api_key.blank?
api_key = ApiKey.create(key: SecureRandom.hex(32), created_by: Discourse.system_user) api_key = ApiKey.create(key: SecureRandom.hex(32), created_by: Discourse.system_user)
end end

View file

@ -1,5 +1,6 @@
class CreateApiKeys < ActiveRecord::Migration class CreateApiKeys < ActiveRecord::Migration
def change
def up
create_table :api_keys do |t| create_table :api_keys do |t|
t.string :key, limit: 64, null: false t.string :key, limit: 64, null: false
t.integer :user_id, null: true t.integer :user_id, null: true
@ -13,4 +14,9 @@ class CreateApiKeys < ActiveRecord::Migration
execute "INSERT INTO api_keys (key, created_at, updated_at) SELECT value, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP FROM site_settings WHERE name = 'api_key'" execute "INSERT INTO api_keys (key, created_at, updated_at) SELECT value, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP FROM site_settings WHERE name = 'api_key'"
execute "DELETE FROM site_settings WHERE name = 'api_key'" execute "DELETE FROM site_settings WHERE name = 'api_key'"
end end
def down
raise ActiveRecord::IrreversibleMigration.new
end
end end