class ActiveGroonga::Migrator
Public Class Methods
new(direction, migrations_path)
click to toggle source
# 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
Public Instance Methods
current_version()
click to toggle source
# File lib/active_groonga/migrator.rb, line 130 def current_version management_table.current_version end
down?()
click to toggle source
# File lib/active_groonga/migrator.rb, line 126 def down? @direction == :down end
management_table()
click to toggle source
# File lib/active_groonga/migrator.rb, line 138 def management_table @management_table ||= SchemaManagementTable.new end
migrate(target_version=nil)
click to toggle source
# 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()
click to toggle source
# File lib/active_groonga/migrator.rb, line 134 def migrated_versions management_table.migrated_versions end
up?()
click to toggle source
# File lib/active_groonga/migrator.rb, line 122 def up? @direction == :up end
Private Instance Methods
collect_migration_entries()
click to toggle source
# File lib/active_groonga/migrator.rb, line 147 def collect_migration_entries migration_entries = [] Pathname.glob(@migrations_path + "[0-9]*_[a-z]*.rb").each do |path| if /\A([0-9]+)_([_a-z0-9]+)\.rb\z/ =~ path.basename.to_s version = $1.to_i else next end if migration_entries.find {|entry| entry.version == version} raise DuplicateMigrationVersionError.new(version, path) end migrations_before = Migration.migrations.dup load(path, true) defined_migrations = Migration.migrations - migrations_before defined_migrations.each do |migration| migration_entries << MigrationEntry.new(migration, version, path) end end migration_entries = migration_entries.sort_by(&:version) down? ? migration_entries.reverse : migration_entries end
migration_entries()
click to toggle source
# File lib/active_groonga/migrator.rb, line 143 def migration_entries @migration_entries ||= collect_migration_entries end