0.0
No commit activity in last 3 years
No release in over 3 years
Wukong-migrate, inspired by rails, makes updating database schemas and settings painless and straightforward. Utilizing your app's models and the settings discovered by Wukong-deploy, only a simple migrate script is required to be able to make changes to databases. Keep your databases in sync with your app code more cleanly and with less effort.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.5
~> 0.11
>= 0.8.7
 Project Readme

Wukong Migrate

A Wukong plugin that allows you to update database schema using predefined models from your deploy pack and a migration DSL.

Commands

The following commands are available

Generate

Creates a new migration file templated to match the chosen database. This command will create a new ruby file in db/migrate named after the argument supplied to generate. The only currently supported database is Elasticsearch, with future plans to support Hbase and others.

$ bundle exec wu-migrate generate change_schema --db=elasticsearch
# INFO 2013-07-29 14:14:51 [MigrateRunner       ] -- Creating migration: db/migrate/change_schema.rb

Perform

Performs the specified migration. This will talk to the database directly and apply the changes found in the migration. The tool will only perform migrations found in db/migrate, and specifying the .rb extension is not necessary. Currently, this is NOT an idempotent operation, and makes no guarantee of data safety on multiple invocations. Configuration is derived from command line parameters and through Wukong::Deploy settings.

$ bundle exec wu-migrate perform change_schema --db=elasticsearch
# INFO 2013-07-29 14:18:20 [MigrateRunner       ] -- Creating index jedi
# INFO 2013-07-29 14:18:21 [MigrateRunner       ] -- Operation complete
# INFO 2013-07-29 14:18:21 [MigrateRunner       ] -- Add alias :light_side for index jedi
# INFO 2013-07-29 14:18:21 [MigrateRunner       ] -- Operation complete

All

Performs all available migrations in db/migrate. This is useful when setting up mirrored or development databases from existing migrations.

Syntax

The following syntax is used to define migrations.

Elasticsearch

All definitions take place inside of a .define block.

EsMigration.define 'name_of_migration' do
...
end

Top-level methods are create_index, update_index, and delete_index. They can be used with or without block syntax.

EsMigration.define 'name_of_migration' do
  create_index(:index_name) do
  ...
  end
  delete_index(:old_index)		   
end

Inside of an index block, you have access to mappings, aliases and index-level settings. Aliases are created/deleted one at a time and optionally accept filters. Mapping methods accept blocks for object-level settings.

EsMigration.define 'name_of_migration' do
  create_index(:index_name) do
    number_of_replicas 4
    ...
    alias_to           :other_name, filter: { range: { date: { gt: '2013-05-05' } } }
    remove_alias       :prior_name
    create_mapping(:obj_type) do
      dynamic true
      source  false
      ...
    end			      
  end
  delete_index(:old_index)		   
end