Class: Engines::Plugin::Migrator

Inherits:
ActiveRecord::Migrator
  • Object
show all
Defined in:
vendor/plugins/engines/lib/engines/plugin/migrator.rb

Overview

The Plugin::Migrator class contains the logic to run migrations from within plugin directories. The directory in which a plugin’s migrations should be is determined by the Plugin#migration_directory method.

To migrate a plugin, you can simple call the migrate method (Plugin#migrate) with the version number that plugin should be at. The plugin’s migrations will then be used to migrate up (or down) to the given version.

For more information, see Engines::RailsExtensions::Migrations

Class Method Summary

Instance Method Summary

Class Method Details

+ (Object) current_version(plugin = current_plugin)



23
24
25
26
27
28
# File 'vendor/plugins/engines/lib/engines/plugin/migrator.rb', line 23

def current_version(plugin=current_plugin)
  # Delete migrations that don't match .. to_i will work because the number comes first
  ::ActiveRecord::Base.connection.select_values(
    "SELECT version FROM #{schema_migrations_table_name}"
  ).delete_if{ |v| v.match(/-#{plugin.name}/) == nil }.map(&:to_i).max || 0
end

+ (Object) migrate_plugin(plugin, version)

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



17
18
19
20
21
# File 'vendor/plugins/engines/lib/engines/plugin/migrator.rb', line 17

def migrate_plugin(plugin, version)
  self.current_plugin = plugin
  return if current_version(plugin) == version
  migrate(plugin.migration_directory, version)
end

Instance Method Details

- (Object) migrated



31
32
33
34
35
36
# File 'vendor/plugins/engines/lib/engines/plugin/migrator.rb', line 31

def migrated
  sm_table = self.class.schema_migrations_table_name
  ::ActiveRecord::Base.connection.select_values(
    "SELECT version FROM #{sm_table}"
  ).delete_if{ |v| v.match(/-#{current_plugin.name}/) == nil }.map(&:to_i).sort
end

- (Object) record_version_state_after_migrating(version)



38
39
40
# File 'vendor/plugins/engines/lib/engines/plugin/migrator.rb', line 38

def record_version_state_after_migrating(version)
  super(version.to_s + "-" + current_plugin.name)
end