Skip to content

Instantly share code, notes, and snippets.

@weppos
Created July 27, 2008 10:04
Show Gist options
  • Save weppos/2769 to your computer and use it in GitHub Desktop.
Save weppos/2769 to your computer and use it in GitHub Desktop.

Revisions

  1. weppos revised this gist Jul 30, 2010. 1 changed file with 56 additions and 52 deletions.
    108 changes: 56 additions & 52 deletions capistrano_database_yml.rb
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    # Category:: Capistrano
    # Package:: Database
    # Author:: Simone Carletti <[email protected]>
    # Copyright:: 2007-2009 The Authors
    # Copyright:: 2007-2010 The Authors
    # License:: MIT License
    # Link:: http://www.simonecarletti.com/
    # Source:: http://gist.github.com/2769
    @@ -95,60 +95,64 @@

    Capistrano::Configuration.instance.load do

    namespace :db do

    desc <<-DESC
    Creates the database.yml configuration file in shared path.
    By default, this task uses a template unless a template \
    called database.yml.erb is found either is :template_dir \
    or /config/deploy folders. The default template matches \
    the template for config/database.yml file shipped with Rails.
    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

    default_template = <<-EOF
    base: &base
    adapter: sqlite3
    timeout: 5000
    development:
    database: #{shared_path}/db/development.sqlite3
    <<: *base
    test:
    database: #{shared_path}/db/test.sqlite3
    <<: *base
    production:
    database: #{shared_path}/db/production.sqlite3
    <<: *base
    EOF

    location = fetch(:template_dir, "config/deploy") + '/database.yml.erb'
    template = File.file?(location) ? File.read(location) : default_template

    config = ERB.new(template)

    run "mkdir -p #{shared_path}/db"
    run "mkdir -p #{shared_path}/config"
    put config.result(binding), "#{shared_path}/config/database.yml"
    end
    namespace :deploy do

    namespace :db do

    desc <<-DESC
    Creates the database.yml configuration file in shared path.
    By default, this task uses a template unless a template \
    called database.yml.erb is found either is :template_dir \
    or /config/deploy folders. The default template matches \
    the template for config/database.yml file shipped with Rails.
    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

    default_template = <<-EOF
    base: &base
    adapter: sqlite3
    timeout: 5000
    development:
    database: #{shared_path}/db/development.sqlite3
    <<: *base
    test:
    database: #{shared_path}/db/test.sqlite3
    <<: *base
    production:
    database: #{shared_path}/db/production.sqlite3
    <<: *base
    EOF

    location = fetch(:template_dir, "config/deploy") + '/database.yml.erb'
    template = File.file?(location) ? File.read(location) : default_template

    config = ERB.new(template)

    run "mkdir -p #{shared_path}/db"
    run "mkdir -p #{shared_path}/config"
    put config.result(binding), "#{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

    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

    after "deploy:setup", "deploy:db:setup" unless fetch(:skip_db_setup, false)
    after "deploy:finalize_update", "deploy:db:symlink"

    end

    after "deploy:setup", "db:setup" unless fetch(:skip_db_setup, false)
    after "deploy:finalize_update", "db:symlink"

    end
  2. weppos revised this gist Oct 23, 2009. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions capistrano_database_yml.rb
    Original file line number Diff line number Diff line change
    @@ -34,9 +34,9 @@
    # == Usage
    #
    # Include this file in your <tt>deploy.rb</tt> configuration file.
    # Assuming you saved this recipe as capistrano_database.rb:
    # Assuming you saved this recipe as capistrano_database_yml.rb:
    #
    # require "capistrano_database"
    # require "capistrano_database_yml"
    #
    # Now, when <tt>deploy:setup</tt> is called, this script will automatically
    # create the <tt>database.yml</tt> file in the shared folder.
  3. weppos renamed this gist Oct 23, 2009. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. weppos revised this gist Jun 2, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -76,7 +76,7 @@
    # timeout: 5000
    #
    # Because this is an Erb template, you can place variables and Ruby scripts
    # whithin the file.
    # within the file.
    # For instance, the template above takes advantage of Capistrano CLI
    # to ask for a MySQL database password instead of hard coding it into the template.
    #
  5. weppos revised this gist Jun 2, 2009. 1 changed file with 154 additions and 157 deletions.
    311 changes: 154 additions & 157 deletions capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -1,157 +1,154 @@
    #
    # = Capistrano database.yml task
    #
    # Provides a couple of tasks for creating the database.yml
    # configuration file dynamically when deploy:setup is run.
    #
    # Category:: Capistrano
    # Package:: Database
    # Author:: Simone Carletti <[email protected]>
    # Copyright:: 2007-2008 The Authors
    # License:: MIT License
    # Link:: http://www.simonecarletti.com/
    # Source:: http://gist.github.com/2769
    #
    #
    # == Requirements
    #
    # This extension requires the original <tt>config/database.yml</tt> to be excluded
    # from source code checkout. You can easily accomplish this by renaming
    # the file (for example to database.example.yml) and appending <tt>database.yml</tt>
    # value to your SCM ignore list.
    #
    # # Example for Subversion
    #
    # $ svn mv config/database.yml config/database.example.yml
    # $ svn propset svn:ignore 'database.yml' config
    #
    # # Example for Git
    #
    # $ git mv config/database.yml config/database.example.yml
    # $ echo 'config/database.yml' >> .gitignore
    #
    # Additionally, if you want to use a custom template for your <tt>database.yml</tt> file,
    # you must store it into a file called <tt>database.yml.erb</tt>.
    # The default path for this file is <tt>config/deploy</tt> but you can customize it
    # with the variable `template_dir`.
    #
    # == Usage
    #
    # Include this file in your <tt>deploy.rb</tt> configuration file.
    #
    # require 'capistrano_database.yml.rb'
    #
    # Now, when <tt>deploy:setup</tt> is called, this script will automatically
    # create the <tt>database.yml</tt> file in the shared folder.
    # Each time you run a deploy, this script will also create a symlink
    # from your application <tt>config/database.yml</tt> pointing to the shared configuration file.
    #
    # == Custom template
    #
    # By default, this scripts create an exact copy of the default
    # <tt>database.yml</tt> file shipped with any new Rails 2.x application.
    # If you want to overwrite the default template, simply create a custom Erb template
    # called <tt>database.yml.erb</tt> and save it into <tt>config/deploy</tt> folder.
    #
    # Although the name of the file can't be changed, you can customize the directory
    # where it is stored defining a variable called <tt>:template_dir</tt>.
    #
    # # store your custom template at foo/bar/database.yml.erb
    # set :template_dir, "foo/bar"
    #
    # # example of database template
    #
    # base: &base
    # adapter: sqlite3
    # timeout: 5000
    # development:
    # database: #{shared_path}/db/development.sqlite3
    # <<: *base
    # test:
    # database: #{shared_path}/db/test.sqlite3
    # <<: *base
    # production:
    # adapter: mysql
    # database: #{application}_production
    # username: #{user}
    # password: #{Capistrano::CLI.ui.ask("Enter MySQL database password: ")}
    # encoding: utf8
    # timeout: 5000
    #
    # Because this is an Erb template, you can place variables and Ruby scripts
    # whithin the file.
    # For instance, the template above takes advantage of Capistrano CLI
    # to ask for a MySQL database password instead of hard coding it into the template.
    #
    # === Password prompt
    #
    # For security reasons, in the example below the password is not
    # hard coded (or stored in a variable) but asked on setup.
    # I don't like to store passwords in files under version control
    # because they will live forever in your history.
    # This is why I use the Capistrano::CLI utility.
    #

    unless Capistrano::Configuration.respond_to?(:instance)
    abort "This extension requires Capistrano 2"
    end

    Capistrano::Configuration.instance.load do

    namespace :db do

    desc <<-DESC
    Creates the database.yml configuration file in shared path.
    By default, this task uses a template unless a template \
    called database.yml.erb is found either is :template_dir \
    or /config/deploy folders. The default template matches \
    the template for config/database.yml file shipped with Rails.
    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

    default_template = <<-EOF
    base: &base
    adapter: sqlite3
    timeout: 5000
    development:
    database: #{shared_path}/db/development.sqlite3
    <<: *base
    test:
    database: #{shared_path}/db/test.sqlite3
    <<: *base
    production:
    database: #{shared_path}/db/production.sqlite3
    <<: *base
    EOF

    location = fetch(:template_dir, "config/deploy") + '/database.yml.erb'
    template = File.file?(location) ? File.read(location) : default_template

    config = ERB.new(template)

    run "mkdir -p #{shared_path}/db"
    run "mkdir -p #{shared_path}/config"
    put config.result(binding), "#{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"

    end
    #
    # = Capistrano database.yml task
    #
    # Provides a couple of tasks for creating the database.yml
    # configuration file dynamically when deploy:setup is run.
    #
    # Category:: Capistrano
    # Package:: Database
    # Author:: Simone Carletti <[email protected]>
    # Copyright:: 2007-2009 The Authors
    # License:: MIT License
    # Link:: http://www.simonecarletti.com/
    # Source:: http://gist.github.com/2769
    #
    #
    # == Requirements
    #
    # This extension requires the original <tt>config/database.yml</tt> to be excluded
    # from source code checkout. You can easily accomplish this by renaming
    # the file (for example to database.example.yml) and appending <tt>database.yml</tt>
    # value to your SCM ignore list.
    #
    # # Example for Subversion
    #
    # $ svn mv config/database.yml config/database.example.yml
    # $ svn propset svn:ignore 'database.yml' config
    #
    # # Example for Git
    #
    # $ git mv config/database.yml config/database.example.yml
    # $ echo 'config/database.yml' >> .gitignore
    #
    #
    # == Usage
    #
    # Include this file in your <tt>deploy.rb</tt> configuration file.
    # Assuming you saved this recipe as capistrano_database.rb:
    #
    # require "capistrano_database"
    #
    # Now, when <tt>deploy:setup</tt> is called, this script will automatically
    # create the <tt>database.yml</tt> file in the shared folder.
    # Each time you run a deploy, this script will also create a symlink
    # from your application <tt>config/database.yml</tt> pointing to the shared configuration file.
    #
    # == Custom template
    #
    # By default, this script creates an exact copy of the default
    # <tt>database.yml</tt> file shipped with a new Rails 2.x application.
    # If you want to overwrite the default template, simply create a custom Erb template
    # called <tt>database.yml.erb</tt> and save it into <tt>config/deploy</tt> folder.
    #
    # Although the name of the file can't be changed, you can customize the directory
    # where it is stored defining a variable called <tt>:template_dir</tt>.
    #
    # # store your custom template at foo/bar/database.yml.erb
    # set :template_dir, "foo/bar"
    #
    # # example of database template
    #
    # base: &base
    # adapter: sqlite3
    # timeout: 5000
    # development:
    # database: #{shared_path}/db/development.sqlite3
    # <<: *base
    # test:
    # database: #{shared_path}/db/test.sqlite3
    # <<: *base
    # production:
    # adapter: mysql
    # database: #{application}_production
    # username: #{user}
    # password: #{Capistrano::CLI.ui.ask("Enter MySQL database password: ")}
    # encoding: utf8
    # timeout: 5000
    #
    # Because this is an Erb template, you can place variables and Ruby scripts
    # whithin the file.
    # For instance, the template above takes advantage of Capistrano CLI
    # to ask for a MySQL database password instead of hard coding it into the template.
    #
    # === Password prompt
    #
    # For security reasons, in the example below the password is not
    # hard coded (or stored in a variable) but asked on setup.
    # I don't like to store passwords in files under version control
    # because they will live forever in your history.
    # This is why I use the Capistrano::CLI utility.
    #

    unless Capistrano::Configuration.respond_to?(:instance)
    abort "This extension requires Capistrano 2"
    end

    Capistrano::Configuration.instance.load do

    namespace :db do

    desc <<-DESC
    Creates the database.yml configuration file in shared path.
    By default, this task uses a template unless a template \
    called database.yml.erb is found either is :template_dir \
    or /config/deploy folders. The default template matches \
    the template for config/database.yml file shipped with Rails.
    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

    default_template = <<-EOF
    base: &base
    adapter: sqlite3
    timeout: 5000
    development:
    database: #{shared_path}/db/development.sqlite3
    <<: *base
    test:
    database: #{shared_path}/db/test.sqlite3
    <<: *base
    production:
    database: #{shared_path}/db/production.sqlite3
    <<: *base
    EOF

    location = fetch(:template_dir, "config/deploy") + '/database.yml.erb'
    template = File.file?(location) ? File.read(location) : default_template

    config = ERB.new(template)

    run "mkdir -p #{shared_path}/db"
    run "mkdir -p #{shared_path}/config"
    put config.result(binding), "#{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"

    end
  6. weppos revised this gist Dec 24, 2008. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -115,7 +115,7 @@
    capistrano-ext/multistaging to avoid multiple db:setup calls \
    when running deploy:setup for all stages one by one.
    DESC
    task :setup do
    task :setup, :except => { :no_release => true } do

    default_template = <<-EOF
    base: &base
    @@ -145,7 +145,7 @@
    desc <<-DESC
    [internal] Updates the symlink for database.yml file to the just deployed release.
    DESC
    task :symlink do
    task :symlink, :except => { :no_release => true } do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
    end

  7. weppos revised this gist Dec 24, 2008. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -107,6 +107,13 @@
    called database.yml.erb is found either is :template_dir \
    or /config/deploy folders. The default template matches \
    the template for config/database.yml file shipped with Rails.
    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 do

    @@ -144,7 +151,7 @@

    end

    after "deploy:setup", "db:setup"
    after "deploy:setup", "db:setup" unless fetch(:skip_db_setup, false)
    after "deploy:finalize_update", "db:symlink"

    end
  8. weppos revised this gist Dec 23, 2008. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -144,7 +144,7 @@

    end

    after "deploy:setup", "db:setup"
    after "deploy:symlink", "db:symlink"
    after "deploy:setup", "db:setup"
    after "deploy:finalize_update", "db:symlink"

    end
  9. weppos revised this gist Dec 23, 2008. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -144,7 +144,7 @@

    end

    after "deploy:setup", "db:setup"
    after "deploy:update_code", "db:symlink"
    after "deploy:setup", "db:setup"
    after "deploy:symlink", "db:symlink"

    end
  10. weppos revised this gist Dec 23, 2008. 1 changed file with 12 additions and 7 deletions.
    19 changes: 12 additions & 7 deletions capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -100,7 +100,14 @@

    namespace :db do

    desc "Create database.yml in shared path"
    desc <<-DESC
    Creates the database.yml configuration file in shared path.
    By default, this task uses a template unless a template \
    called database.yml.erb is found either is :template_dir \
    or /config/deploy folders. The default template matches \
    the template for config/database.yml file shipped with Rails.
    DESC
    task :setup do

    default_template = <<-EOF
    @@ -119,11 +126,7 @@
    EOF

    location = fetch(:template_dir, "config/deploy") + '/database.yml.erb'
    template = if File.file?(location)
    File.read(location)
    else
    default_template
    end
    template = File.file?(location) ? File.read(location) : default_template

    config = ERB.new(template)

    @@ -132,7 +135,9 @@
    put config.result(binding), "#{shared_path}/config/database.yml"
    end

    desc "Make symlink for database yaml"
    desc <<-DESC
    [internal] Updates the symlink for database.yml file to the just deployed release.
    DESC
    task :symlink do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
    end
  11. weppos revised this gist Dec 23, 2008. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -120,7 +120,7 @@

    location = fetch(:template_dir, "config/deploy") + '/database.yml.erb'
    template = if File.file?(location)
    IO.read(location)
    File.read(location)
    else
    default_template
    end
  12. weppos revised this gist Dec 23, 2008. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -101,7 +101,7 @@
    namespace :db do

    desc "Create database.yml in shared path"
    task :default do
    task :setup do

    default_template = <<-EOF
    base: &base
    @@ -139,7 +139,7 @@

    end

    before "deploy:setup", "db"
    after "deploy:update_code", "db:symlink"
    after "deploy:setup", "db:setup"
    after "deploy:update_code", "db:symlink"

    end
  13. weppos revised this gist Aug 18, 2008. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,13 @@
    # Provides a couple of tasks for creating the database.yml
    # configuration file dynamically when deploy:setup is run.
    #
    # Category:: Capistrano
    # Package:: Database
    # Author:: Simone Carletti <[email protected]>
    # Category:: Capistrano
    # Package:: Database
    # Author:: Simone Carletti <[email protected]>
    # Copyright:: 2007-2008 The Authors
    # License:: MIT License
    # Link:: http://www.simonecarletti.com/
    # Source:: http://gist.github.com/2769
    #
    #
    # == Requirements
  14. weppos revised this gist Aug 4, 2008. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -125,7 +125,7 @@

    run "mkdir -p #{shared_path}/db"
    run "mkdir -p #{shared_path}/config"
    put config.result, "#{shared_path}/config/database.yml"
    put config.result(binding), "#{shared_path}/config/database.yml"
    end

    desc "Make symlink for database yaml"
  15. weppos revised this gist Jul 30, 2008. 1 changed file with 77 additions and 23 deletions.
    100 changes: 77 additions & 23 deletions capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -11,33 +11,82 @@
    #
    # == Requirements
    #
    # This extension requires the original config/database.yml to be excluded
    # This extension requires the original <tt>config/database.yml</tt> to be excluded
    # from source code checkout. You can easily accomplish this by renaming
    # the file (for example to database.example.yml) and appending database.yml
    # the file (for example to database.example.yml) and appending <tt>database.yml</tt>
    # value to your SCM ignore list.
    #
    # === Example for Subversion
    # # Example for Subversion
    #
    # $ svn mv config/database.yml config/database.example.yml
    # $ svn propset svn:ignore 'database.yml' config
    #
    # === Example for Git
    # # Example for Git
    #
    # $ git mv config/database.yml config/database.example.yml
    # $ echo 'config/database.yml' >> .gitignore
    #
    # == Password prompt
    # Additionally, if you want to use a custom template for your <tt>database.yml</tt> file,
    # you must store it into a file called <tt>database.yml.erb</tt>.
    # The default path for this file is <tt>config/deploy</tt> but you can customize it
    # with the variable `template_dir`.
    #
    # == Usage
    #
    # Include this file in your <tt>deploy.rb</tt> configuration file.
    #
    # require 'capistrano_database.yml.rb'
    #
    # Now, when <tt>deploy:setup</tt> is called, this script will automatically
    # create the <tt>database.yml</tt> file in the shared folder.
    # Each time you run a deploy, this script will also create a symlink
    # from your application <tt>config/database.yml</tt> pointing to the shared configuration file.
    #
    # == Custom template
    #
    # By default, this scripts create an exact copy of the default
    # <tt>database.yml</tt> file shipped with any new Rails 2.x application.
    # If you want to overwrite the default template, simply create a custom Erb template
    # called <tt>database.yml.erb</tt> and save it into <tt>config/deploy</tt> folder.
    #
    # Although the name of the file can't be changed, you can customize the directory
    # where it is stored defining a variable called <tt>:template_dir</tt>.
    #
    # # store your custom template at foo/bar/database.yml.erb
    # set :template_dir, "foo/bar"
    #
    # # example of database template
    #
    # base: &base
    # adapter: sqlite3
    # timeout: 5000
    # development:
    # database: #{shared_path}/db/development.sqlite3
    # <<: *base
    # test:
    # database: #{shared_path}/db/test.sqlite3
    # <<: *base
    # production:
    # adapter: mysql
    # database: #{application}_production
    # username: #{user}
    # password: #{Capistrano::CLI.ui.ask("Enter MySQL database password: ")}
    # encoding: utf8
    # timeout: 5000
    #
    # Because this is an Erb template, you can place variables and Ruby scripts
    # whithin the file.
    # For instance, the template above takes advantage of Capistrano CLI
    # to ask for a MySQL database password instead of hard coding it into the template.
    #
    # === Password prompt
    #
    # For security reasons, in the example below the password is not
    # hard coded (or stored in a variable) but asked on setup.
    # I don't like to store passwords in files under version control
    # because they will live forever in your history.
    # This is why I use the Capistrano::CLI utility.
    #
    # The same approach is applied to the host value but just because
    # I don't like to hard code the value for each single Rails app.
    # I prefer to write it once on setup.
    #

    unless Capistrano::Configuration.respond_to?(:instance)
    abort "This extension requires Capistrano 2"
    @@ -49,26 +98,31 @@

    desc "Create database.yml in shared path"
    task :default do
    config = ERB.new <<-EOF
    base: &base

    default_template = <<-EOF
    base: &base
    adapter: sqlite3
    timeout: 5000
    development:
    development:
    database: #{shared_path}/db/development.sqlite3
    <<: *base
    test:
    <<: *base
    test:
    database: #{shared_path}/db/test.sqlite3
    <<: *base
    <<: *base
    production:
    adapter: mysql
    database: #{application}_production
    username: #{user}
    password: #{Capistrano::CLI.ui.ask("Enter MySQL database password: ")}
    host: #{Capistrano::CLI.ui.ask("Enter MySQL database host: ")}
    encoding: utf8
    timeout: 5000
    database: #{shared_path}/db/production.sqlite3
    <<: *base
    EOF


    location = fetch(:template_dir, "config/deploy") + '/database.yml.erb'
    template = if File.file?(location)
    IO.read(location)
    else
    default_template
    end

    config = ERB.new(template)

    run "mkdir -p #{shared_path}/db"
    run "mkdir -p #{shared_path}/config"
    put config.result, "#{shared_path}/config/database.yml"
  16. weppos revised this gist Jul 30, 2008. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    #
    # == Requirements
    #
    # This scenario requires the original config/database.yml to be excluded
    # This extension requires the original config/database.yml to be excluded
    # from source code checkout. You can easily accomplish this by renaming
    # the file (for example to database.example.yml) and appending database.yml
    # value to your SCM ignore list.
    @@ -40,7 +40,7 @@
    #

    unless Capistrano::Configuration.respond_to?(:instance)
    abort "These recipes require Capistrano 2"
    abort "This extension requires Capistrano 2"
    end

    Capistrano::Configuration.instance.load do
  17. weppos revised this gist Jul 29, 2008. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    # configuration file dynamically when deploy:setup is run.
    #
    # Category:: Capistrano
    # Package:: -
    # Package:: Database
    # Author:: Simone Carletti <[email protected]>
    #
    #
  18. weppos renamed this gist Jul 29, 2008. 1 changed file with 41 additions and 33 deletions.
    74 changes: 41 additions & 33 deletions capistrano_database.yml_task.rb → capistrano_database.yml.rb
    Original file line number Diff line number Diff line change
    @@ -39,41 +39,49 @@
    # I prefer to write it once on setup.
    #

    namespace :db do

    desc "Create database.yml in shared path"
    task :default do
    config = ERB.new <<-EOF
    base: &base
    adapter: sqlite3
    timeout: 5000
    development:
    database: #{shared_path}/db/development.sqlite3
    <<: *base
    test:
    database: #{shared_path}/db/test.sqlite3
    <<: *base
    production:
    adapter: mysql
    database: #{application}_production
    username: #{user}
    password: #{Capistrano::CLI.ui.ask("Enter MySQL database password: ")}
    host: #{Capistrano::CLI.ui.ask("Enter MySQL database host: ")}
    encoding: utf8
    timeout: 5000
    EOF
    unless Capistrano::Configuration.respond_to?(:instance)
    abort "These recipes require Capistrano 2"
    end

    run "mkdir -p #{shared_path}/db"
    run "mkdir -p #{shared_path}/config"
    put config.result, "#{shared_path}/config/database.yml"
    end
    Capistrano::Configuration.instance.load do

    namespace :db do

    desc "Create database.yml in shared path"
    task :default do
    config = ERB.new <<-EOF
    base: &base
    adapter: sqlite3
    timeout: 5000
    development:
    database: #{shared_path}/db/development.sqlite3
    <<: *base
    test:
    database: #{shared_path}/db/test.sqlite3
    <<: *base
    production:
    adapter: mysql
    database: #{application}_production
    username: #{user}
    password: #{Capistrano::CLI.ui.ask("Enter MySQL database password: ")}
    host: #{Capistrano::CLI.ui.ask("Enter MySQL database host: ")}
    encoding: utf8
    timeout: 5000
    EOF

    run "mkdir -p #{shared_path}/db"
    run "mkdir -p #{shared_path}/config"
    put config.result, "#{shared_path}/config/database.yml"
    end

    desc "Make symlink for database yaml"
    task :symlink do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
    end

    desc "Make symlink for database yaml"
    task :symlink do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
    end

    before "deploy:setup", "db"
    after "deploy:update_code", "db:symlink"

    end

    before "deploy:setup", "db"
    after "deploy:update_code", "db:symlink"
  19. weppos renamed this gist Jul 27, 2008. 1 changed file with 0 additions and 0 deletions.
  20. weppos renamed this gist Jul 27, 2008. 1 changed file with 1 addition and 1 deletion.
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #
    # = Capistrano database.yml tasks
    # = Capistrano database.yml task
    #
    # Provides a couple of tasks for creating the database.yml
    # configuration file dynamically when deploy:setup is run.
  21. weppos created this gist Jul 27, 2008.
    79 changes: 79 additions & 0 deletions capistrano_database_tasks.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    #
    # = Capistrano database.yml tasks
    #
    # Provides a couple of tasks for creating the database.yml
    # configuration file dynamically when deploy:setup is run.
    #
    # Category:: Capistrano
    # Package:: -
    # Author:: Simone Carletti <[email protected]>
    #
    #
    # == Requirements
    #
    # This scenario requires the original config/database.yml to be excluded
    # from source code checkout. You can easily accomplish this by renaming
    # the file (for example to database.example.yml) and appending database.yml
    # value to your SCM ignore list.
    #
    # === Example for Subversion
    #
    # $ svn mv config/database.yml config/database.example.yml
    # $ svn propset svn:ignore 'database.yml' config
    #
    # === Example for Git
    #
    # $ git mv config/database.yml config/database.example.yml
    # $ echo 'config/database.yml' >> .gitignore
    #
    # == Password prompt
    #
    # For security reasons, in the example below the password is not
    # hard coded (or stored in a variable) but asked on setup.
    # I don't like to store passwords in files under version control
    # because they will live forever in your history.
    # This is why I use the Capistrano::CLI utility.
    #
    # The same approach is applied to the host value but just because
    # I don't like to hard code the value for each single Rails app.
    # I prefer to write it once on setup.
    #

    namespace :db do

    desc "Create database.yml in shared path"
    task :default do
    config = ERB.new <<-EOF
    base: &base
    adapter: sqlite3
    timeout: 5000
    development:
    database: #{shared_path}/db/development.sqlite3
    <<: *base
    test:
    database: #{shared_path}/db/test.sqlite3
    <<: *base
    production:
    adapter: mysql
    database: #{application}_production
    username: #{user}
    password: #{Capistrano::CLI.ui.ask("Enter MySQL database password: ")}
    host: #{Capistrano::CLI.ui.ask("Enter MySQL database host: ")}
    encoding: utf8
    timeout: 5000
    EOF

    run "mkdir -p #{shared_path}/db"
    run "mkdir -p #{shared_path}/config"
    put config.result, "#{shared_path}/config/database.yml"
    end

    desc "Make symlink for database yaml"
    task :symlink do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
    end

    end

    before "deploy:setup", "db"
    after "deploy:update_code", "db:symlink"