Sha256: 1adcff95759565e81b74aa3dda01da53c59e680eae6da787aa0cf3eb1b2d4d87

Contents?: true

Size: 1.16 KB

Versions: 7

Compression:

Stored size: 1.16 KB

Contents

namespace :db do
  desc "Reset DataBase for environment and test"
  task :reset do
    Rake::Task['db:drop'].invoke
    Rake::Task['db:create'].invoke
    Rake::Task['db:migrate'].invoke
    Rake::Task['db:seed'].invoke
    sh "rake db:test:prepare"
  end

  desc "Backup the database tp tmp/db.sql file"
  task backup: :get_db_config do
    sh "export PGPASSWORD=#{@password} && pg_dump #{@database} --host #{@host} --port #{@port} -U #{@username} -f #{@default_filename}"
  end

  desc "Restore the database from tmp/db.sql file if no one is passed"
  task restore: [:drop, :create, :get_db_config] do
    sh "export PGPASSWORD=#{@password} && psql -d #{@database} -U #{@username} -h #{@host} --port #{@port} < #{filename}"
  end
end

task :get_db_config do
  config   = Rails.configuration.database_configuration
  @host = config[Rails.env]["host"]
  @port = config[Rails.env]["port"]
  @database = config[Rails.env]["database"]
  @username = config[Rails.env]["username"]
  @password = config[Rails.env]["password"]

  @default_filename = "tmp/db.sql"
end

def filename
  name = ARGV[1]
  task name.to_sym do ; end unless name.nil?
  return name ? name : @default_filename
end



Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
prun-ops-0.3.4 lib/tasks/db.rake
prun-ops-0.3.3 lib/tasks/db.rake
prun-ops-0.3.2 lib/tasks/db.rake
prun-ops-0.3.1 lib/tasks/db.rake
prun-ops-0.3.0 lib/tasks/db.rake
prun-ops-0.2.18 lib/tasks/db.rake
prun-ops-0.2.17 lib/tasks/db.rake