├── lib ├── capistrano-rails-db.rb └── capistrano │ ├── rails │ └── db.rb │ └── tasks │ └── db.rake ├── Rakefile ├── Gemfile ├── .gitignore ├── capistrano-rails-db.gemspec ├── LICENSE.txt └── README.md /lib/capistrano-rails-db.rb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /lib/capistrano/rails/db.rb: -------------------------------------------------------------------------------- 1 | load File.expand_path('../../tasks/db.rake', __FILE__) 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in capistrano-rails.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | *.bundle 11 | *.so 12 | *.o 13 | *.a 14 | mkmf.log 15 | -------------------------------------------------------------------------------- /capistrano-rails-db.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | 5 | Gem::Specification.new do |gem| 6 | gem.name = "capistrano-rails-db" 7 | gem.version = '0.0.2' 8 | gem.authors = ["Kentaro Imai"] 9 | gem.email = ["kentaroi@gmail.com"] 10 | gem.description = %q{Rails migration tasks for Capistrano v3} 11 | gem.summary = %q{Rails migration tasks for Capistrano v3} 12 | gem.homepage = "https://github.com/kentaroi/capistrano-rails-db" 13 | 14 | gem.files = `git ls-files`.split($/) 15 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) 16 | gem.require_paths = ["lib"] 17 | 18 | gem.add_dependency 'capistrano-rails', '~> 1.1' 19 | 20 | end 21 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Kentaro Imai 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Capistrano::Rails::Db 2 | 3 | Rails migration tasks for Capistrano v3: 4 | 5 | Run `cap -T deploy:db` in the terminal to get a full list of the migration tasks: 6 | 7 | ``` bash 8 | cap deploy:db:abort_if_pending_migrations # Run rake db:abort_if_pending_migrations 9 | cap deploy:db:create # Run rake db:create 10 | cap deploy:db:drop # Run rake db:drop 11 | cap deploy:db:migrate # Run rake db:migrate Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog) 12 | cap deploy:db:migrate:down # Run rake db:migrate:down Run the "down" for a given migration VERSION 13 | cap deploy:db:migrate:redo # Run rake db:migrate:redo Rollback the database one migration and re migrate up (options: STEP=x, VERSION=x) 14 | cap deploy:db:migrate:reset # Run rake db:migrate:reset Reset your database using your migrations 15 | cap deploy:db:migrate:status # Run rake db:migrate:status Display status of migrations 16 | cap deploy:db:migrate:up # Run rake db:migrate:up Run the "up" for a given migration VERSION 17 | cap deploy:db:reset # Run rake db:reset Drop and recreate the database from db/schema.rb and load the seeds 18 | cap deploy:db:rollback # Run rake db:rollback Roll the schema back to the previous version (specify steps w/ STEP=n) 19 | cap deploy:db:seed # Run rake db:seed Load the seed data from db/seed.rb 20 | cap deploy:db:setup # Run rake db:setup Create the database, load the schema, and initialize with the seed data 21 | cap deploy:db:version # Run rake db:version Retrieve the current schema version number 22 | ``` 23 | 24 | ## Installation 25 | 26 | Add this line to your application's Gemfile: 27 | 28 | gem 'capistrano', '~> 3.1' 29 | gem 'capistrano-rails', '~> 1.1' 30 | gem 'capistrano-rails-db' 31 | 32 | ## Usage 33 | 34 | # Capfile 35 | require 'capistrano/rails' 36 | require 'capistrano/rails/db' 37 | 38 | Please note that any `require` should be placed in `Capfile`, not `config/deploy.rb`. 39 | 40 | ## Contributing 41 | 42 | 1. Fork it 43 | 2. Create your feature branch (`git checkout -b my-new-feature`) 44 | 3. Commit your changes (`git commit -am 'Add some feature'`) 45 | 4. Push to the branch (`git push origin my-new-feature`) 46 | 5. Create new Pull Request 47 | -------------------------------------------------------------------------------- /lib/capistrano/tasks/db.rake: -------------------------------------------------------------------------------- 1 | namespace :deploy do 2 | namespace :db do 3 | task :set_rails_db_options do 4 | set :rails_db_options, [ ENV['VERSION'] ? "VERSION=#{ENV['VERSION']}" : nil, 5 | ENV['VERBOSE'] ? "VERBOSE=#{ENV['VERBOSE']}" : nil, 6 | ENV['SCOPE'] ? "SCOPE=#{ENV['SCOPE']}" : nil, 7 | ENV['STEP'] ? "STEP=#{ENV['STEP']}" : nil, 8 | ENV['DISABLE_DATABASE_ENVIRONMENT_CHECK'] ? 9 | "DISABLE_DATABASE_ENVIRONMENT_CHECK=#{ENV['DISABLE_DATABASE_ENVIRONMENT_CHECK']}" : 10 | nil].compact 11 | end 12 | 13 | { abort_if_pending_migrations: '', 14 | create: '', 15 | drop: '', 16 | migrate: 'Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog).', 17 | rollback: 'Roll the schema back to the previous version (specify steps w/ STEP=n).', 18 | seed: 'Load the seed data from db/seed.rb', 19 | setup: 'Create the database, load the schema, and initialize with the seed data', 20 | reset: 'Drop and recreate the database from db/schema.rb and load the seeds', 21 | version: 'Retrieve the current schema version number' 22 | }.each do |task_name, task_desc| 23 | desc "Run rake db:#{task_name}".ljust(28) + task_desc 24 | task task_name => [:set_rails_env, :set_rails_db_options] do 25 | on primary fetch(:migration_role) do 26 | info "[deploy:db:#{task_name}] Run `rake db:#{task_name}`" 27 | within release_path do 28 | with rails_env: fetch(:rails_env) do 29 | execute :rake, "db:#{task_name}", *fetch(:rails_db_options) 30 | end 31 | end 32 | end 33 | end 34 | end 35 | 36 | namespace :migrate do 37 | { status: 'Display status of migrations', 38 | up: 'Run the "up" for a given migration VERSION.', 39 | down: 'Run the "down" for a given migration VERSION.', 40 | redo: 'Rollback the database one migration and re migrate up (options: STEP=x, VERSION=x).', 41 | reset: 'Reset your database using your migrations' 42 | }.each do |task_name, task_desc| 43 | desc "Run rake db:migrate:#{task_name}".ljust(28) + task_desc 44 | task task_name => [:set_rails_env, :set_rails_db_options] do 45 | on primary fetch(:migration_role) do 46 | info "[deploy:db:migrate:#{task_name}] Run `rake db:migrate:#{task_name}`" 47 | within release_path do 48 | with rails_env: fetch(:rails_env) do 49 | execute :rake, "db:migrate:#{task_name}", *fetch(:rails_db_options) 50 | end 51 | end 52 | end 53 | end 54 | end 55 | end 56 | end 57 | end 58 | --------------------------------------------------------------------------------