Class: Desert::PluginMigrations::Migrator
- Inherits:
-
ActiveRecord::Migrator
- Object
- ActiveRecord::Migrator
- Desert::PluginMigrations::Migrator
- Defined in:
- lib/desert/plugin_migrations/migrator.rb,
lib/desert/plugin_migrations/2.1/migrator.rb
Overview
Responsible for migrating plugins. PluginMigrations.Migrator.current_plugin indicates which plugin is currently being migrated
Class Method Summary collapse
-
.current_version ⇒ Object
:nodoc:.
- .get_all_versions ⇒ Object
-
.migrate_plugin(plugin, version = nil) ⇒ Object
Runs the migrations from a plugin, up (or down) to the version given.
-
.schema_info_table_name ⇒ Object
:nodoc:.
- .schema_migrations_table_name ⇒ Object
Instance Method Summary collapse
Class Method Details
.current_version ⇒ Object
:nodoc:
5 6 7 8 9 10 11 12 13 |
# File 'lib/desert/plugin_migrations/2.1/migrator.rb', line 5 def current_version #:nodoc: result = ActiveRecord::Base.connection.select_one("SELECT version FROM #{schema_migrations_table_name} WHERE plugin_name = '#{current_plugin.name}' order by version desc") if result result['version'].to_i else # There probably isn't an entry for this plugin in the migration info table. 0 end end |
.get_all_versions ⇒ Object
15 16 17 |
# File 'lib/desert/plugin_migrations/2.1/migrator.rb', line 15 def get_all_versions ActiveRecord::Base.connection.select_values("SELECT version FROM #{schema_migrations_table_name} where plugin_name='#{current_plugin.name}'").map(&:to_i).sort end |
.migrate_plugin(plugin, version = nil) ⇒ Object
Runs the migrations from a plugin, up (or down) to the version given
11 12 13 14 15 16 17 |
# File 'lib/desert/plugin_migrations/migrator.rb', line 11 def migrate_plugin(plugin, version = nil) self.current_plugin = plugin if ActiveRecord::Base.connection.respond_to?(:initialize_schema_migrations_table) ActiveRecord::Base.connection.initialize_schema_migrations_table end migrate(plugin.migration_path, version) end |
.schema_info_table_name ⇒ Object
:nodoc:
19 20 21 |
# File 'lib/desert/plugin_migrations/migrator.rb', line 19 def schema_info_table_name #:nodoc: ActiveRecord::Base.table_name_prefix + 'plugin_schema_info' + ActiveRecord::Base.table_name_suffix end |
.schema_migrations_table_name ⇒ Object
23 24 25 |
# File 'lib/desert/plugin_migrations/migrator.rb', line 23 def schema_migrations_table_name ActiveRecord::Base.table_name_prefix + 'plugin_schema_migrations' + ActiveRecord::Base.table_name_suffix end |
Instance Method Details
#migrated ⇒ Object
30 31 32 |
# File 'lib/desert/plugin_migrations/2.1/migrator.rb', line 30 def migrated self.class.get_all_versions end |
#record_version_state_after_migrating(version) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/desert/plugin_migrations/2.1/migrator.rb', line 20 def (version) sm_table = self.class.schema_migrations_table_name if down? ActiveRecord::Base.connection.update("DELETE FROM #{sm_table} WHERE version = '#{version}' WHERE plugin_name = '#{current_plugin.name}'") else ActiveRecord::Base.connection.insert("INSERT INTO #{sm_table} (plugin_name, version) VALUES ('#{current_plugin.name}', '#{version}')") end end |