class Wukong::Migrate::MigrateRunner

Public Class Methods

configure(env, prog) click to toggle source
# File lib/wukong-migrate/migrate_runner.rb, line 29
def configure(env, prog)
  env.define :debug, type: :boolean, default: false, description: 'Run in debug mode'
  env.define :db,    required: true,                 description: 'The database to apply the migration to'
  env.define :force, type: :boolean, default: false, description: 'Continue migrating through errors'
end

Public Instance Methods

command() click to toggle source
# File lib/wukong-migrate/migrate_runner.rb, line 36
def command
  args.first
end
database_options() click to toggle source
# File lib/wukong-migrate/migrate_runner.rb, line 48
def database_options
  opts = settings.to_hash
  opts.merge(opts.delete(settings.db.to_sym) || {})
end
generate_migration_file(name, database) click to toggle source
# File lib/wukong-migrate/migrate_runner.rb, line 53
def generate_migration_file(name, database)
  m_file = migration_file_dir.join(name + '.rb').to_s
  log.info "Creating migration: #{m_file}"
  case database
  when 'elasticsearch'
    File.open(m_file, 'w'){ |f| f.puts EsMigration.template(name) }
  when 'hbase'
    File.open(m_file, 'w'){ |f| f.puts HbaseMigration.template(name) }
  end
end
load_all_migration_files!() click to toggle source
# File lib/wukong-migrate/migrate_runner.rb, line 64
def load_all_migration_files!
  migration_file_dir.children.each do |m_file|
    Kernel.load m_file.to_s if m_file.extname == '.rb'
  end
end
migration_file_dir() click to toggle source
# File lib/wukong-migrate/migrate_runner.rb, line 44
def migration_file_dir
  Wukong::Deploy.root.join('db/migrate')
end
perform_migration(*names, options) click to toggle source
# File lib/wukong-migrate/migrate_runner.rb, line 70
def perform_migration(*names, options)
  names.each do |name|
    migration = Wukong::Migration.retrieve(name)
    migration.write_attribute(:log, self.log)
    migration.perform(options)
  end
end
run() click to toggle source
# File lib/wukong-migrate/migrate_runner.rb, line 78
def run
  case command
  when 'generate'
    generate_migration_file(specified_migration, settings.db)
  when 'perform'
    load_all_migration_files!
    perform_migration(specified_migration, database_options)
  when 'all'
    load_all_migration_files!
    perform_migration(*Wukong::Migration.all_migrations, database_options)
  else
    log.error "Please specify a valid command"
    dump_help_and_exit!
  end
end
specified_migration() click to toggle source
# File lib/wukong-migrate/migrate_runner.rb, line 40
def specified_migration
  args[1] or die('Must specify a migration when using this command', 1)
end