Class: ActiveGroonga::Migrator
- Inherits:
-
Object
- Object
- ActiveGroonga::Migrator
- Defined in:
- lib/active_groonga/migrator.rb
Instance Method Summary collapse
- #current_version ⇒ Object
- #down? ⇒ Boolean
-
#initialize(direction, migrations_path) ⇒ Migrator
constructor
A new instance of Migrator.
- #management_table ⇒ Object
- #migrate(target_version = nil) ⇒ Object
- #migrated_versions ⇒ Object
- #up? ⇒ Boolean
Constructor Details
#initialize(direction, migrations_path) ⇒ Migrator
Returns a new instance of Migrator.
92 93 94 95 96 97 98 |
# File 'lib/active_groonga/migrator.rb', line 92 def initialize(direction, migrations_path) @direction = direction @migrations_path = migrations_path unless @migrations_path.is_a?(Pathname) @migrations_path = Pathanme(@migrations_path) end end |
Instance Method Details
#current_version ⇒ Object
130 131 132 |
# File 'lib/active_groonga/migrator.rb', line 130 def current_version management_table.current_version end |
#down? ⇒ Boolean
126 127 128 |
# File 'lib/active_groonga/migrator.rb', line 126 def down? @direction == :down end |
#management_table ⇒ Object
138 139 140 |
# File 'lib/active_groonga/migrator.rb', line 138 def management_table @management_table ||= SchemaManagementTable.new end |
#migrate(target_version = nil) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/active_groonga/migrator.rb', line 100 def migrate(target_version=nil) _current_version = current_version migration_entries.each do |entry| if up? next if entry.version <= _current_version else next if entry.version > _current_version end Base.logger.info("Migrating to #{entry.name} (#{entry.version})") active_groonga_schema = Schema.new(:context => Base.context) active_groonga_schema.define do |schema| entry.migrate(@direction, schema) end if up? management_table.update_version(entry.version) else management_table.remove_version(entry.version) end break if entry.version == target_version end end |
#migrated_versions ⇒ Object
134 135 136 |
# File 'lib/active_groonga/migrator.rb', line 134 def migrated_versions management_table.migrated_versions end |
#up? ⇒ Boolean
122 123 124 |
# File 'lib/active_groonga/migrator.rb', line 122 def up? @direction == :up end |