A platform for community discussion. Free, open, simple.
DEV: Drop 'key' column from user_api_keys (#9388)
Dan Ungureanu4e5f9d4cd19f
diff --git a/app/models/user_api_key.rb b/app/models/user_api_key.rbindex 4fac1230bc9..c705541a73d 100644--- a/app/models/user_api_key.rb+++ b/app/models/user_api_key.rb@@ -28,7 +28,6 @@ class UserApiKey < ActiveRecord::Basedef generate_keyif !self.key_hash@key ||= SecureRandom.hex- self.key = @keyself.key_hash = ApiKey.hash_key(@key)endend@@ -102,7 +101,6 @@ end# id :integer not null, primary key# user_id :integer not null# client_id :string not null-# key :string not null# application_name :string not null# push_url :string# created_at :datetime not null@@ -115,7 +113,6 @@ end# Indexes## index_user_api_keys_on_client_id (client_id) UNIQUE-# index_user_api_keys_on_key (key) UNIQUE# index_user_api_keys_on_key_hash (key_hash) UNIQUE# index_user_api_keys_on_user_id (user_id)#diff --git a/db/post_migrate/20200408121312_remove_key_from_user_api_key.rb b/db/post_migrate/20200408121312_remove_key_from_user_api_key.rbnew file mode 100644index 00000000000..a6147e5d584--- /dev/null+++ b/db/post_migrate/20200408121312_remove_key_from_user_api_key.rb@@ -0,0 +1,17 @@+# frozen_string_literal: true++class RemoveKeyFromUserApiKey < ActiveRecord::Migration[6.0]+ DROPPED_COLUMNS ||= {+ user_api_keys: %i{key}+ }++ def up+ DROPPED_COLUMNS.each do |table, columns|+ Migration::ColumnDropper.execute_drop(table, columns)+ end+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/spec/components/auth/default_current_user_provider_spec.rb b/spec/components/auth/default_current_user_provider_spec.rbindex ab4fa863691..e5ce0ced7bf 100644--- a/spec/components/auth/default_current_user_provider_spec.rb+++ b/spec/components/auth/default_current_user_provider_spec.rb@@ -769,7 +769,6 @@ describe Auth::DefaultCurrentUserProvider doapplication_name: 'my app',client_id: '1234',scopes: ['read'],- key: SecureRandom.hex,user_id: user.id)end@@ -779,7 +778,6 @@ describe Auth::DefaultCurrentUserProvider doapplication_name: 'my app',client_id: '12345',scopes: ['read'],- key: SecureRandom.hex,user_id: user.id)diff --git a/spec/fabricators/user_api_key_fabricator.rb b/spec/fabricators/user_api_key_fabricator.rbindex e513ac05de8..5c4ce63d4d7 100644--- a/spec/fabricators/user_api_key_fabricator.rb+++ b/spec/fabricators/user_api_key_fabricator.rb@@ -4,6 +4,5 @@ Fabricator(:readonly_user_api_key, from: :user_api_key) douserscopes ['read']client_id { SecureRandom.hex }- key { SecureRandom.hex }application_name 'some app'enddiff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rbindex 4a73313c7b1..973f31c6638 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -681,7 +681,6 @@ describe PostAlerter do2.times do |i|UserApiKey.create!(user_id: evil_trout.id,client_id: "xxx#{i}",- key: "yyy#{i}",application_name: "iPhone#{i}",scopes: ['notifications'],push_url: "https://site2.com/push")@@ -697,7 +696,6 @@ describe PostAlerter do2.times do |i|UserApiKey.create!(user_id: evil_trout.id,client_id: "xxx#{i}",- key: "yyy#{i}",application_name: "iPhone#{i}",scopes: ['notifications'],push_url: "https://site2.com/push")