From 4e5f9d4cd19f2d5ad5f43264f30bfe9db26988b0 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Wed, 22 Apr 2020 12:13:19 +0300 Subject: [PATCH] DEV: Drop 'key' column from user_api_keys (#9388) --- app/models/user_api_key.rb | 3 --- ...200408121312_remove_key_from_user_api_key.rb | 17 +++++++++++++++++ .../auth/default_current_user_provider_spec.rb | 2 -- spec/fabricators/user_api_key_fabricator.rb | 1 - spec/services/post_alerter_spec.rb | 2 -- 5 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 db/post_migrate/20200408121312_remove_key_from_user_api_key.rb diff --git a/app/models/user_api_key.rb b/app/models/user_api_key.rb index 4fac1230bc9..c705541a73d 100644 --- a/app/models/user_api_key.rb +++ b/app/models/user_api_key.rb @@ -28,7 +28,6 @@ class UserApiKey < ActiveRecord::Base def generate_key if !self.key_hash @key ||= SecureRandom.hex - self.key = @key self.key_hash = ApiKey.hash_key(@key) end end @@ -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.rb new file mode 100644 index 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 +end diff --git a/spec/components/auth/default_current_user_provider_spec.rb b/spec/components/auth/default_current_user_provider_spec.rb index 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 do application_name: 'my app', client_id: '1234', scopes: ['read'], - key: SecureRandom.hex, user_id: user.id ) end @@ -779,7 +778,6 @@ describe Auth::DefaultCurrentUserProvider do application_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.rb index 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) do user scopes ['read'] client_id { SecureRandom.hex } - key { SecureRandom.hex } application_name 'some app' end diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb index 4a73313c7b1..973f31c6638 100644 --- a/spec/services/post_alerter_spec.rb +++ b/spec/services/post_alerter_spec.rb @@ -681,7 +681,6 @@ describe PostAlerter do 2.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 do 2.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")