Skip to content

Commit

Permalink
Merge pull request #1067 from postmodern/mysql_command
Browse files Browse the repository at this point in the history
Execute the mysql command with separate arguments.
  • Loading branch information
nesquena committed Feb 21, 2013
2 parents deb5ef7 + 6196080 commit a9fdf35
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions padrino-gen/lib/padrino-gen/padrino-tasks/datamapper.rb
Expand Up @@ -53,11 +53,17 @@
system("createdb", "-E", charset, "-h", host, "-U", user, database)
puts "<= dm:create executed"
when 'mysql'
query = [
"mysql", "--user=#{user}", (password.blank? ? '' : "--password=#{password}"), (%w[127.0.0.1 localhost].include?(host) ? '-e' : "--host=#{host} -e"),
"CREATE DATABASE #{database} DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}".inspect
]
system(query.compact.join(" "))
arguments = ["--user=#{user}"]
arguments << "--password=#{password}" unless password.blank?

unless %w[127.0.0.1 localhost].include?(host)
arguments << "--host=#{host}"
end

arguments << '-e'
arguments << "CREATE DATABASE #{database} DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}"

system('mysql',*arguments)
puts "<= dm:create executed"
when 'sqlite3'
DataMapper.setup(DataMapper.repository.name, config)
Expand All @@ -77,11 +83,17 @@
system("dropdb", "-h", host, "-U", user, database)
puts "<= dm:drop executed"
when 'mysql'
query = [
"mysql", "--user=#{user}", (password.blank? ? '' : "--password=#{password}"), (%w[127.0.0.1 localhost].include?(host) ? '-e' : "--host=#{host} -e"),
"DROP DATABASE IF EXISTS #{database}".inspect
]
system(query.compact.join(" "))
arguments = ["--user=#{user}"]
arguments << "--password=#{password}" unless password.blank?

unless %w[127.0.0.1 localhost].include?(host)
arguments << "--host=#{host}"
end

arguments << '-e'
arguments << "DROP DATABASE IF EXISTS #{database}"

system('mysql',*arguments)
puts "<= dm:drop executed"
when 'sqlite3'
File.delete(config[:path]) if File.exist?(config[:path])
Expand Down

0 comments on commit a9fdf35

Please sign in to comment.