Skip to content

Commit

Permalink
MR changes part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
brunosedler committed Dec 18, 2023
1 parent 0564780 commit 5391274
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions lib/geordi/db_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(extra_flags, sudo: false)
@sudo = sudo

if @sudo
puts '> Please enter your sudo password if asked, for db operations as system users'
Interaction.note 'Please enter your sudo password when asked.'
puts "We're going to run `sudo -u postgres psql` for PostgreSQL"
puts ' and `sudo mysql` for MariaDB (which uses PAM auth)'
`sudo true`
Expand Down Expand Up @@ -132,7 +132,7 @@ def decide_mysql_command(extra_flags)
cmd = 'mysql -uroot'
cmd << " #{extra_flags}" unless extra_flags.nil?
unless File.exist? File.join(Dir.home, '.my.cnf')
puts "> Please enter your MySQL/MariaDB password for account 'root'."
Interaction.note "Please enter your MySQL/MariaDB password for account 'root'."
Interaction.warn "You should create a ~/.my.cnf file instead, or you'll need to enter your MySQL root password for each db."
Interaction.note 'See https://makandracards.com/makandra/50813-store-mysql-passwords-for-development for more information.'
cmd << ' -p' # need to ask for password now
Expand Down Expand Up @@ -172,24 +172,24 @@ def list_all_dbs(dbtype)
list_all_mysql_dbs
end
rescue DatabaseError
Interaction.fail 'Connection to database could not be established. Try running the command again with --sudo'
Interaction.fail 'Connection to database could not be established. Try running again with --sudo.'
end

def list_all_postgres_dbs
output, error, _status = Open3.capture3("#{@postgres_command} -t -A -c 'SELECT DATNAME FROM pg_database WHERE datistemplate = false'")
output, _error, status = Open3.capture3("#{@postgres_command} -t -A -c 'SELECT DATNAME FROM pg_database WHERE datistemplate = false'")

raise DatabaseError unless error.empty?
raise DatabaseError unless status.success?

output.split
end

def list_all_mysql_dbs
if @mysql_command.include? '-p'
puts "> Please enter your MySQL/MariaDB account 'root' for: list all databases"
Interaction.note "Please enter your MySQL/MariaDB account 'root' for: list all databases"
end
output, error, _status = Open3.capture3("#{@mysql_command} -B -N -e 'show databases'")
output, _error, status = Open3.capture3("#{@mysql_command} -B -N -e 'show databases'")

raise DatabaseError unless error.empty?
raise DatabaseError unless status.success?

output.split
end
Expand All @@ -202,7 +202,7 @@ def clean_mysql
return if deletable_dbs.nil?
deletable_dbs.each do |db|
if @mysql_command.include? '-p'
puts "> Please enter your MySQL/MariaDB account 'root' for: DROP DATABASE #{db}"
Interaction.note "Please enter your MySQL/MariaDB account 'root' for: DROP DATABASE #{db}"
else
puts "Dropping MySQL/MariaDB database #{db}"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/db_cleaner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe Geordi::DBCleaner do
describe '#new' do
let(:dir) { File.join(Dir.pwd, 'spec') }
let(:dir) { File.join(Dir.pwd, 'tmp') }

before do
stub_const('ENV', ENV.to_hash.merge('XDG_CONFIG_HOME' => dir))
Expand Down

0 comments on commit 5391274

Please sign in to comment.