From 6394d924c8b8c82a1660146eb277a3ee8fe5c636 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 22 Oct 2013 17:51:04 -0400 Subject: [PATCH] Change migration to prevent down --- app/models/api_key.rb | 2 +- db/migrate/20131022151218_create_api_keys.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/api_key.rb b/app/models/api_key.rb index 98eadd5c0..475ccbe91 100644 --- a/app/models/api_key.rb +++ b/app/models/api_key.rb @@ -12,7 +12,7 @@ class ApiKey < ActiveRecord::Base end 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? api_key = ApiKey.create(key: SecureRandom.hex(32), created_by: Discourse.system_user) end diff --git a/db/migrate/20131022151218_create_api_keys.rb b/db/migrate/20131022151218_create_api_keys.rb index 684eb65c3..a9f938b83 100644 --- a/db/migrate/20131022151218_create_api_keys.rb +++ b/db/migrate/20131022151218_create_api_keys.rb @@ -1,5 +1,6 @@ class CreateApiKeys < ActiveRecord::Migration - def change + + def up create_table :api_keys do |t| t.string :key, limit: 64, null: false 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 "DELETE FROM site_settings WHERE name = 'api_key'" end + + def down + raise ActiveRecord::IrreversibleMigration.new + end + end