Class: ActiveGroonga::SchemaManagementTable

Inherits:
Object
  • Object
show all
Defined in:
lib/active_groonga/migrator.rb

Constant Summary collapse

TABLE_NAME =
"schema_migrations"

Instance Method Summary collapse

Constructor Details

#initializeSchemaManagementTable

Returns a new instance of SchemaManagementTable.



47
48
49
50
# File 'lib/active_groonga/migrator.rb', line 47

def initialize
  ensure_table
  @table = Base.context[TABLE_NAME]
end

Instance Method Details

#current_versionObject



52
53
54
# File 'lib/active_groonga/migrator.rb', line 52

def current_version
  @current_version ||= (migrated_versions.last || [0]).first
end

#migrated_versionsObject



56
57
58
59
60
61
62
# File 'lib/active_groonga/migrator.rb', line 56

def migrated_versions
  @migrated_versions ||= @table.collect do |record|
    [record.key, record.migrated_at]
  end.sort_by do |version, migrated_at|
    version
  end
end

#remove_version(version) ⇒ Object



69
70
71
72
# File 'lib/active_groonga/migrator.rb', line 69

def remove_version(version)
  @table[version].delete
  clear_cache
end

#update_version(version) ⇒ Object



64
65
66
67
# File 'lib/active_groonga/migrator.rb', line 64

def update_version(version)
  @table.add(version, :migrated_at => Time.now)
  clear_cache
end