Skip to content

Commit

Permalink
Merge pull request #17410 from jrafanie/warn_when_fix_auth_is_in_dry_run
Browse files Browse the repository at this point in the history
Warn when we're running fix_auth in dry run mode
  • Loading branch information
kbrock committed Jun 5, 2018
2 parents c6a6bed + 8935d78 commit 7dc93cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/fix_auth/auth_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def run(options = {})
puts "fixing #{table_name}.#{available_columns.join(", ")}" unless options[:silent]
processed = 0
errors = 0
would_make_changes = false
contenders.each do |r|
begin
fix_passwords(r, options)
Expand All @@ -96,6 +97,7 @@ def run(options = {})
display_column(r, column, options)
end
end
would_make_changes ||= r.changed?
r.save! if !options[:dry_run] && r.changed?
processed += 1
rescue ArgumentError # undefined class/module
Expand All @@ -111,6 +113,7 @@ def run(options = {})
end
puts "#{options[:dry_run] ? "viewed" : "processed"} #{processed} records" unless options[:silent]
puts "found #{errors} errors" if errors > 0 && !options[:silent]
puts "** This was executed in dry-run, and no actual changes will be made to #{table_name} **" if would_make_changes && options[:dry_run]
end

def clean_up
Expand Down
9 changes: 9 additions & 0 deletions tools/fix_auth/fix_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ def generate_password
raise Errno::EEXIST, e.message
end

def print_dry_run_warning
method = caller_locations.first.label
# Move this message up to `run` if the other methods add dry-run support
puts "** #{method} is executing in dry-run mode, and no actual changes will be made **" if options[:dry_run]
end

def fix_database_passwords
print_dry_run_warning

begin
# in specs, this is already setup
ActiveRecord::Base.connection_config
Expand All @@ -65,6 +73,7 @@ def fix_database_passwords
end

def fix_database_yml
print_dry_run_warning
FixDatabaseYml.file_name = "#{options[:root]}/config/database.yml"
FixDatabaseYml.run({:hardcode => options[:password]}.merge(run_options))
end
Expand Down

0 comments on commit 7dc93cd

Please sign in to comment.