Class: GaleraClusterMigrations::Capistrano

Inherits:
Object
  • Object
show all
Defined in:
lib/galera_cluster_migrations/capistrano.rb

Constant Summary collapse

TASKS =
[
  'galera:migrate'
]

Class Method Summary collapse

Class Method Details

.load_into(capistrano_config) ⇒ Object



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
# File 'lib/galera_cluster_migrations/capistrano.rb', line 9

def self.load_into(capistrano_config)
  capistrano_config.load do

    namespace :galera do
      desc <<-DESC
        Run the migrate rake task. By default, it runs this in most recently \
        deployed version of the app. However, you can specify a different release \
        via the migrate_target variable, which must be one of :latest (for the \
        default behavior), or :current (for the release indicated by the \
        `current' symlink). Strings will work for those values instead of symbols, \
        too. You can also specify additional environment variables to pass to rake \
        via the migrate_env variable. Finally, you can specify the full path to the \
        rake executable by setting the rake variable. The defaults are:

          set :rake,           "rake"
          set :rails_env,      "production"
          set :migrate_env,    ""
          set :migrate_target, :latest
      DESC
      task :migrate, :roles => :db do
        rake = fetch(:rake, "rake")
        rails_env = fetch(:rails_env, "production")
        migrate_env = fetch(:migrate_env, "")
        migrate_target = fetch(:migrate_target, :latest)

        directory = case migrate_target.to_sym
          when :current then current_path
          when :latest  then latest_release
          else raise ArgumentError, "unknown migration target #{migrate_target.inspect}"
          end

        run "cd #{directory} && #{rake} RAILS_ENV=#{rails_env} #{migrate_env} galera:db:alter[db:migrate]"
      end
    end
  end
end