delay the removal of auth token column from user table

This commit is contained in:
Sam 2017-02-07 09:39:41 -05:00
parent 634755113a
commit 4d57c95e9b
2 changed files with 5 additions and 7 deletions

View File

@ -32,9 +32,10 @@ duration = Rails.env.production? ? 60 : 0
if User.exec_sql("SELECT 1 FROM schema_migration_details if User.exec_sql("SELECT 1 FROM schema_migration_details
WHERE EXISTS( WHERE EXISTS(
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = 'public' AND table_name = 'users' AND column_name = 'last_redirected_to_top_at' WHERE table_schema = 'public' AND table_name = 'users'
AND column_name = 'auth_token'
) AND ) AND
name = 'MoveTrackingOptionsToUserOptions' AND name = 'AddUserAuthTokens' AND
created_at < (current_timestamp at time zone 'UTC' - interval '#{duration} minutes') created_at < (current_timestamp at time zone 'UTC' - interval '#{duration} minutes')
").to_a.length > 0 ").to_a.length > 0
@ -57,6 +58,8 @@ if User.exec_sql("SELECT 1 FROM schema_migration_details
auto_track_topics_after_msecs auto_track_topics_after_msecs
new_topic_duration_minutes new_topic_duration_minutes
last_redirected_to_top_at last_redirected_to_top_at
auth_token
auth_token_updated_at
].each do |column| ].each do |column|
User.exec_sql("ALTER TABLE users DROP column IF EXISTS #{column}") User.exec_sql("ALTER TABLE users DROP column IF EXISTS #{column}")
end end

View File

@ -1,7 +1,5 @@
class AddUserAuthTokens < ActiveRecord::Migration class AddUserAuthTokens < ActiveRecord::Migration
def down def down
add_column :users, :auth_token, :string
add_column :users, :auth_token_updated_at, :datetime
execute <<SQL execute <<SQL
UPDATE users UPDATE users
SET auth_token = user_auth_tokens.auth_token, SET auth_token = user_auth_tokens.auth_token,
@ -36,8 +34,5 @@ SQL
FROM users FROM users
WHERE auth_token_updated_at IS NOT NULL AND auth_token IS NOT NULL WHERE auth_token_updated_at IS NOT NULL AND auth_token IS NOT NULL
SQL SQL
remove_column :users, :auth_token
remove_column :users, :auth_token_updated_at
end end
end end