Sha256: 4c00687c9ec95f56891e49d2efdc4dd490954fd19fd8b29efed0063bd25a3fa0

Contents?: true

Size: 1.03 KB

Versions: 23

Compression:

Stored size: 1.03 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} -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} < #{filename}"
  end
end

task :get_db_config do
  config   = Rails.configuration.database_configuration
  @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

23 entries across 23 versions & 1 rubygems

Version Path
prun-ops-0.1.1 lib/tasks/db.rake
prun-ops-0.1.0 lib/tasks/db.rake
prun-ops-0.0.22 lib/tasks/db.rake
prun-ops-0.0.21 lib/tasks/db.rake
prun-ops-0.0.20 lib/tasks/db.rake
prun-ops-0.0.19 lib/tasks/db.rake
prun-ops-0.0.18 lib/tasks/db.rake
prun-ops-0.0.17 lib/tasks/db.rake
prun-ops-0.0.16 lib/tasks/db.rake
prun-ops-0.0.15 lib/tasks/db.rake
prun-ops-0.0.14 lib/tasks/db.rake
prun-ops-0.0.13 lib/tasks/db.rake
prun-ops-0.0.12 lib/tasks/db.rake
prun-ops-0.0.11 lib/tasks/db.rake
prun-ops-0.0.10 lib/tasks/db.rake
prun-ops-0.0.9 lib/tasks/db.rake
prun-ops-0.0.8 lib/tasks/db.rake
prun-ops-0.0.7 lib/tasks/db.rake
prun-ops-0.0.6 lib/tasks/db.rake
prun-ops-0.0.5 lib/tasks/db.rake