Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- desc 'Configure Subversion for Rails'
- task 'configure_for_svn' do
- system("svn remove log/*")
- system("svn commit -m 'removing all log files from subversion'")
- system("svn propset svn:ignore \"*.log\" log/")
- system("svn update log/")
- system("svn commit -m 'Ignoring all files in /log/ ending in .log'")
- system("svn propset svn:ignore \"*.db\" db/")
- system("svn update db/")
- system("svn commit -m 'Ignoring all files in /db/ ending in .db'")
- system("svn move config/database.yml config/database.example")
- system("svn commit -m 'Moving database.yml to database.example to provide a template for anyone who checks out the code'")
- system("svn propset svn:ignore \"database.yml\" config/")
- system("svn update config/")
- system("svn commit -m 'Ignoring database.yml'")
- system("svn remove tmp/*")
- system("svn commit -m 'Removing /tmp/ folder'")
- system("svn propset svn:ignore \"*\" tmp/")
- end
- desc 'Add new files to subversion'
- task 'add_new_files' do
- system("svn status | grep '^?' | sed -e 's/? *//' | sed -e 's/ / /g' | xargs svn add")
- end
- desc 'shortcut for adding new files'
- task 'add' => [ 'add_new_files' ] do
- # do nothing
- end
- desc 'Creates the databases defined in your config/database.yml (unless they already exist)'
- task 'db:create' => [ 'environment' ] do
- ActiveRecord::Base.configurations.each_value do |config|
- begin
- ActiveRecord::Base.establish_connection(config)
- ActiveRecord::Base.connection
- rescue
- case config["adapter"]
- when "mysql" then
- ActiveRecord::Base.establish_connection(config.merge({ "database" => nil }))
- ActiveRecord::Base.connection.create_database(config["database"])
- ActiveRecord::Base.establish_connection(config)
- when "postgresql" then
- `createdb \"#{config["database"]}\" -E utf8`
- else
- # do nothing
- end
- end
- end
- ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[(RAILS_ENV or "development")])
- end
- desc 'Drops the database for your currenet RAILS_ENV as defined in config/database.yml'
- task 'db:drop' => [ 'environment' ] do
- config = ActiveRecord::Base.configurations[(RAILS_ENV or "development")]
- case config["adapter"]
- when "mysql" then
- begin
- ActiveRecord::Base.establish_connection(config)
- ActiveRecord::Base.connection.current_database
- ActiveRecord::Base.connection.drop_database(config["database"])
- rescue
- # do nothing
- end
- when "sqlite3" then
- FileUtils.rm_f(File.join(RAILS_ROOT, config["database"]))
- when "postgresql" then
- `dropdb \"#{config["database"]}\"`
- else
- # do nothing
- end
- end
- desc 'Drops, creates and then migrates the database for your current RAILS_ENV. Target specific version with VERSION=x'
- task 'db:reset' => [ 'db:drop', 'db:create', 'db:migrate' ] do
- # do nothing
- end
- desc 'Launches the database shell using the values defined in config/database.yml'
- task 'db:shell' => [ 'environment' ] do
- config = ActiveRecord::Base.configurations[(RAILS_ENV or "development")]
- command = ""
- case config["adapter"]
- when "mysql" then
- (command << "mysql ")
- (command << "--host=#{(config["host"] or "localhost")} ")
- (command << "--port=#{(config["port"] or 3306)} ")
- (command << "--user=#{(config["username"] or "root")} ")
- (command << "--password=#{(config["password"] or "")} ")
- (command << config["database"])
- when "postgresql" then
- puts("You should consider switching to MySQL or get off your butt and submit a patch")
- else
- (command << "echo Unsupported database adapter: #{config["adapter"]}")
- end
- system(command)
- end
Add Comment
Please, Sign In to add comment