Giter Club home page Giter Club logo

capistrano-database-yml's Introduction

Capistrano::DatabaseYml

Capistrano tasks for handling database.yml when deploying Rails 4+ apps. This is a slightly modified clone of capistrano-secrets-yml.

Install

Add this to Gemfile:

group :development do
  gem 'capistrano', '~> 3.2.1'
  gem 'capistrano-database-yml', '~> 1.0.0'
end

And then:

$ bundle install

Setup and usage

  • make sure your local config/database.yml is not git tracked. It should be on the disk, but gitignored.

  • populate production database in local config/database.yml:

      production:
        adapter: mysql2
    
  • add to Capfile:

      require 'capistrano/database_yml'
    
  • create database.yml file on the remote server by executing this task:

      $ bundle exec cap production setup
    

You can now proceed with other deployment tasks.

What if a new config is added to database file?

  • add it to local config/database.yml:

      production:
        adapter: mysql2
        foobar: some_other_config
    
  • if you're working in a team where other people have the deploy rights, compare you local database.yml with the one on the server. This is to ensure you didn't miss an update.

  • copy to the server:

      $ bundle exec cap production setup
    
  • notify your colleagues that have the deploy rights that the remote database.yml has been updated so they can change their copy.

How it works

When you execute $ bundle exec production setup:

  • database from your local database.yml are copied to the server.
  • only "stage" database are copied: if you are deploying to production, only production database are copied there
  • on the server database file is located in #{shared_path}/config/database.yml

On deployment:

  • database file is automatically symlinked to #{current_path}/config/database.yml

Configuration

None.

More Capistrano automation?

Check out capistrano-plugins github org.

FAQ

  • shouldn't we be keeping configuration in environment variables as per 12 factor app rules?

    On Heroku, yes.
    With Capistrano, those env vars still have to be written somewhere on the disk and used with a tool like dotenv.

    Since we have to keep configuration on the disk anyway, it probably makes sense to use Rails 4 built-in database.yml mechanism.

License

MIT

capistrano-database-yml's People

Contributors

pirj avatar potsbo avatar westonganger avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.