jbarnette (owner)

Revisions

gist: 184805 Download_button fork
public
Public Clone URL: git://gist.github.com/184805.git
Embed All Files: show embed
db.rake #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# e.g.,
# rake db:pg test
# ...swaps database.yml, runs the tests, and swaps back to the default.
#
# I have:
# config/database.yml
# config/database.pg.yml
# config/database.sqlite.yml
 
def temporarily_swap_db_to engine
  active = "config/database.yml"
  backup = "config/database.yml.backup"
  temp = "config/database.#{engine}.yml"
 
  cp active, backup
  cp temp, active
  at_exit { cp backup, active ; rm backup }
end
 
Dir["config/database.*.yml"].each do |f|
  next unless /database\.(\w+)\.yml$/ =~ f
 
  desc "DB prefix."
  task("db:#{$1}") { temporarily_swap_db_to $1 }
end