Class: ActiveGroonga::Migrator
- Inherits:
-
Object
- Object
- ActiveGroonga::Migrator
- Defined in:
- lib/active_groonga/migrator.rb
Instance Method Summary (collapse)
- - (Object) current_version
- - (Boolean) down?
-
- (Migrator) initialize(direction, migrations_path)
constructor
A new instance of Migrator.
- - (Object) management_table
- - (Object) migrate(target_version = nil)
- - (Object) migrated_versions
- - (Boolean) up?
Constructor Details
- (Migrator) initialize(direction, migrations_path)
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
- (Object) current_version
130 131 132 |
# File 'lib/active_groonga/migrator.rb', line 130 def current_version management_table.current_version end |
- (Boolean) down?
126 127 128 |
# File 'lib/active_groonga/migrator.rb', line 126 def down? @direction == :down end |
- (Object) management_table
138 139 140 |
# File 'lib/active_groonga/migrator.rb', line 138 def management_table @management_table ||= SchemaManagementTable.new end |
- (Object) migrate(target_version = nil)
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 |
- (Object) migrated_versions
134 135 136 |
# File 'lib/active_groonga/migrator.rb', line 134 def migrated_versions management_table.migrated_versions end |
- (Boolean) up?
122 123 124 |
# File 'lib/active_groonga/migrator.rb', line 122 def up? @direction == :up end |