This gem will add some convenience rake tasks that will help you manage database dumps and imports. At the moment only the mysql adapter is available.
The gems works both on rails 2.x and 3.x applications, but due to rails 2.x limitations you have to run a generator, see the usage section
Add the gem to your gemfile:
gem 'dbmanager'
If you're on a rails 2.x application you also need to run:
script/generate dbmanager
that will copy the gem rake tasks file into the lib/tasks directory.
rake db:dump
This rake task will dump the requested db to a file on the local machine.
You will be prompted to choose the target dir (defaults to tmp) and the sql file name (sql extension will be added automatically). If the file already exists, it will be overwritten.
rake db:import
This task will import a source db to a destination db. Tipical use is to import the production db into your development one.
You will be prompted to choose the source and the target environment db, and the source db will be imported into the target db. All environments containing the string 'production' in their name are protected by default, which means you cannot overwrite them unless you explicitly override this setting in the override file (see next section for more info).
import process is destructive, be careful on what environment you choose to overwite. I take no responsibility for misuse or bugs in the code ;-)
Since some settings may be specific to the server environment (ie. host could be a private ip not reachable from anywhere) you can overwrite the settings in database.yml by adding a dbmanager_override.yml file in your rails config dir.
You can also use this file to tell the dumper to ignore certain tables with the ignoretables directive:
beta:
ignoretables:
- users
- prods_view
Another use is to set some environments as protected, or vice versa allow to overwrite production env. For example if we want to override the following setting, and make the database protected from overwriting:
beta:
host: 192.168.0.1
we should put in dbmanager_override.yml this:
beta:
host: 234.234.234.234
protected: true
Instead, if we want to make the production env writable we should add this:
production:
protected: false
### TODO
- Add more db adapters