-
Notifications
You must be signed in to change notification settings - Fork 1
/
datbase-recipe.rb
50 lines (35 loc) · 1.76 KB
/
datbase-recipe.rb
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
namespace :db do
desc <<-DESC
Creates the database.yml configuration file in shared path.
It uses a reference file config/database.yml.example file present on your code.
When this recipe is loaded, db:setup is automatically configured
to be invoked after deploy:setup. You can skip this task setting
the variable :skip_db_setup to true. This is especially useful
if you are using this recipe in combination with
capistrano-ext/multistaging to avoid multiple db:setup calls
when running deploy:setup for all stages one by one.
DESC
task :setup, :except => { :no_release => true } do
require 'yaml'
database_config = YAML::load_file("config/database.yml.example")
set(:db_user, Capistrano::CLI.ui.ask("Database user: ") )
set(:db_password, Capistrano::CLI.password_prompt("Database Password: ") )
set(:db_name, Capistrano::CLI.ui.ask("Database name: ") )
environment_database_config = {}
environment_database_config[rails_env] = database_config[rails_env]
environment_database_config[rails_env]['username'] = db_user.to_s
environment_database_config[rails_env]['password'] = db_password.to_s
environment_database_config[rails_env]['database'] = db_name.to_s
run "mkdir -p #{shared_path}/config"
database_yaml = environment_database_config.to_yaml
put database_yaml, "#{shared_path}/config/database.yml"
end
desc <<-DESC
[internal] Updates the symlink for database.yml file to the just deployed release.
DESC
task :symlink, :except => { :no_release => true } do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
end
after "deploy:setup", "db:setup" unless fetch(:skip_db_setup, false)
after "deploy:finalize_update", "db:symlink"