Guest User

Untitled

a guest
Apr 10th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. desc 'Configure Subversion for Rails'
  2. task 'configure_for_svn' do
  3. system("svn remove log/*")
  4. system("svn commit -m 'removing all log files from subversion'")
  5. system("svn propset svn:ignore \"*.log\" log/")
  6. system("svn update log/")
  7. system("svn commit -m 'Ignoring all files in /log/ ending in .log'")
  8. system("svn propset svn:ignore \"*.db\" db/")
  9. system("svn update db/")
  10. system("svn commit -m 'Ignoring all files in /db/ ending in .db'")
  11. system("svn move config/database.yml config/database.example")
  12. system("svn commit -m 'Moving database.yml to database.example to provide a template for anyone who checks out the code'")
  13. system("svn propset svn:ignore \"database.yml\" config/")
  14. system("svn update config/")
  15. system("svn commit -m 'Ignoring database.yml'")
  16. system("svn remove tmp/*")
  17. system("svn commit -m 'Removing /tmp/ folder'")
  18. system("svn propset svn:ignore \"*\" tmp/")
  19. end
  20.  
  21. desc 'Add new files to subversion'
  22. task 'add_new_files' do
  23. system("svn status | grep '^?' | sed -e 's/? *//' | sed -e 's/ / /g' | xargs svn add")
  24. end
  25.  
  26. desc 'shortcut for adding new files'
  27. task 'add' => [ 'add_new_files' ] do
  28. # do nothing
  29. end
  30.  
  31. desc 'Creates the databases defined in your config/database.yml (unless they already exist)'
  32. task 'db:create' => [ 'environment' ] do
  33. ActiveRecord::Base.configurations.each_value do |config|
  34. begin
  35. ActiveRecord::Base.establish_connection(config)
  36. ActiveRecord::Base.connection
  37. rescue
  38. case config["adapter"]
  39. when "mysql" then
  40. ActiveRecord::Base.establish_connection(config.merge({ "database" => nil }))
  41. ActiveRecord::Base.connection.create_database(config["database"])
  42. ActiveRecord::Base.establish_connection(config)
  43. when "postgresql" then
  44. `createdb \"#{config["database"]}\" -E utf8`
  45. else
  46. # do nothing
  47. end
  48. end
  49. end
  50. ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[(RAILS_ENV or "development")])
  51. end
  52.  
  53. desc 'Drops the database for your currenet RAILS_ENV as defined in config/database.yml'
  54. task 'db:drop' => [ 'environment' ] do
  55. config = ActiveRecord::Base.configurations[(RAILS_ENV or "development")]
  56. case config["adapter"]
  57. when "mysql" then
  58. begin
  59. ActiveRecord::Base.establish_connection(config)
  60. ActiveRecord::Base.connection.current_database
  61. ActiveRecord::Base.connection.drop_database(config["database"])
  62. rescue
  63. # do nothing
  64. end
  65. when "sqlite3" then
  66. FileUtils.rm_f(File.join(RAILS_ROOT, config["database"]))
  67. when "postgresql" then
  68. `dropdb \"#{config["database"]}\"`
  69. else
  70. # do nothing
  71. end
  72. end
  73.  
  74. desc 'Drops, creates and then migrates the database for your current RAILS_ENV. Target specific version with VERSION=x'
  75. task 'db:reset' => [ 'db:drop', 'db:create', 'db:migrate' ] do
  76. # do nothing
  77. end
  78.  
  79. desc 'Launches the database shell using the values defined in config/database.yml'
  80. task 'db:shell' => [ 'environment' ] do
  81. config = ActiveRecord::Base.configurations[(RAILS_ENV or "development")]
  82. command = ""
  83. case config["adapter"]
  84. when "mysql" then
  85. (command << "mysql ")
  86. (command << "--host=#{(config["host"] or "localhost")} ")
  87. (command << "--port=#{(config["port"] or 3306)} ")
  88. (command << "--user=#{(config["username"] or "root")} ")
  89. (command << "--password=#{(config["password"] or "")} ")
  90. (command << config["database"])
  91. when "postgresql" then
  92. puts("You should consider switching to MySQL or get off your butt and submit a patch")
  93. else
  94. (command << "echo Unsupported database adapter: #{config["adapter"]}")
  95. end
  96. system(command)
  97. end
Add Comment
Please, Sign In to add comment