Class: Goldberg::Migrator

Inherits:
ActiveRecord::Migrator
  • Object
show all
Defined in:
lib/six-updater-web/vendor/plugins/goldberg/lib/goldberg/migrator.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.plugin_nameObject

Set the plugin name before performing any migrations



82
83
84
# File 'lib/six-updater-web/vendor/plugins/goldberg/lib/goldberg/migrator.rb', line 82

def plugin_name
  @plugin_name
end

Class Method Details

.current_versionObject



99
100
101
102
103
104
105
106
107
# File 'lib/six-updater-web/vendor/plugins/goldberg/lib/goldberg/migrator.rb', line 99

def current_version
  begin
    version = ActiveRecord::Base.connection.select_values("SELECT version FROM #{schema_migrations_table_name} WHERE plugin_name=#{Goldberg::Migrator.plugin}").map(&:to_i).max
  version || 0
  rescue ActiveRecord::StatementInvalid
    # No migration info table, so never migrated
    0
  end
end

.migrate(version = nil) ⇒ Object

Runs the migrations from a plugin, up (or down) to the version given



85
86
87
88
89
90
91
92
# File 'lib/six-updater-web/vendor/plugins/goldberg/lib/goldberg/migrator.rb', line 85

def migrate(version = nil)
  ActiveRecord::ConnectionAdapters::SchemaStatements.class_eval do
    include Goldberg::SchemaStatements
  end

  version && (version = version.to_i)
  super("#{RAILS_ROOT}/vendor/plugins/#{plugin_name}/db/migrate", version)
end

.pluginObject

Escape the current plugin name



110
111
112
# File 'lib/six-updater-web/vendor/plugins/goldberg/lib/goldberg/migrator.rb', line 110

def plugin
  ActiveRecord::Base.quote_value(plugin_name)
end

.schema_migrations_table_nameObject



94
95
96
97
# File 'lib/six-updater-web/vendor/plugins/goldberg/lib/goldberg/migrator.rb', line 94

def schema_migrations_table_name
  ActiveRecord::Base.table_name_prefix + 'plugin_schema_migrations' +
    ActiveRecord::Base.table_name_suffix
end

Instance Method Details

#migratedObject

class << self



115
116
117
118
# File 'lib/six-updater-web/vendor/plugins/goldberg/lib/goldberg/migrator.rb', line 115

def migrated
  sm_table = self.class.schema_migrations_table_name
  ActiveRecord::Base.connection.select_values("SELECT version FROM #{sm_table} WHERE plugin_name=#{self.class.plugin}").map(&:to_i).sort
end