Skip to content
Browse files

Added optional SQL file upload when creating database. Script will as…

…k user if they want to upload a file (y/n), and if not will skip any remaining commands concerning that upload.
  • Loading branch information...
1 parent 6ea92b5 commit d678ac5f0799f23524abb501c27d0850b48275e2 @ahume committed Jan 31, 2009
Showing with 8 additions and 5 deletions.
  1. +8 −5 lib/capistrano/ext/ubuntu-machine/mysql.rb
View
13 lib/capistrano/ext/ubuntu-machine/mysql.rb
@@ -39,14 +39,17 @@
db_name = Capistrano::CLI.ui.ask("Which database should we create: ")
db_username = Capistrano::CLI.ui.ask("Which database username should we create: ")
db_user_password = Capistrano::CLI.ui.ask("Choose a password for the new database username: ")
- file = Capistrano::CLI.ui.ask("Which database file should we import (it must be located in #{default_local_files_path}): ")
- upload "#{default_local_files_path}/#{file}", "#{file}"
-
+ file_to_upload = Capistrano::CLI.ui.ask("Do you want to import a database file? (y/n) : ")
+ if file_to_upload == "y"
+ file = Capistrano::CLI.ui.ask("Which database file should we import (it must be located in #{default_local_files_path}): ")
+ upload "#{default_local_files_path}/#{file}", "#{file}"
+ end
create_db_tmp_file = "create_#{db_name}.sql"
put render("new_db", binding), create_db_tmp_file
run "mysql -u root -p#{db_root_password} < #{create_db_tmp_file}"
-
- run "mysql -u root -p#{db_root_password} #{db_name} < #{file}"
+ if file_to_upload == "y"
+ run "mysql -u root -p#{db_root_password} #{db_name} < #{file}"
+ end
run "rm #{file} #{create_db_tmp_file}"
end

0 comments on commit d678ac5

Please sign in to comment.
Something went wrong with that request. Please try again.