Class: Desert::PluginMigrations::Migrator
- Inherits:
-
ActiveRecord::Migrator
- Object
- ActiveRecord::Migrator
- Desert::PluginMigrations::Migrator
- Defined in:
- lib/desert/plugin_migrations/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:.
-
.migrate_plugin(plugin, version = nil) ⇒ Object
Runs the migrations from a plugin, up (or down) to the version given.
-
.schema_info_table_name ⇒ Object
(also: schema_migrations_table_name)
:nodoc:.
Instance Method Summary collapse
- #migrated ⇒ Object
- #set_schema_version(version) ⇒ Object (also: #record_version_state_after_migrating)
Class Method Details
.current_version ⇒ Object
:nodoc:
24 25 26 27 28 29 30 31 32 |
# File 'lib/desert/plugin_migrations/migrator.rb', line 24 def current_version #:nodoc: result = ActiveRecord::Base.connection.select_one("SELECT version FROM #{schema_info_table_name} WHERE plugin_name = '#{current_plugin.name}'") if result result['version'].to_i else # There probably isn't an entry for this plugin in the migration info table. 0 end 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 Also known as: schema_migrations_table_name
: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 |
Instance Method Details
#migrated ⇒ Object
48 49 50 51 |
# File 'lib/desert/plugin_migrations/migrator.rb', line 48 def migrated current_plugin_version = self.class.current_version (1..current_plugin_version).to_a end |
#set_schema_version(version) ⇒ Object Also known as: record_version_state_after_migrating
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/desert/plugin_migrations/migrator.rb', line 35 def set_schema_version(version) version = down? ? version.to_i - 1 : version.to_i if ActiveRecord::Base.connection.select_one("SELECT version FROM #{self.class.schema_info_table_name} WHERE plugin_name = '#{current_plugin.name}'").nil? # We need to create the entry since it doesn't exist ActiveRecord::Base.connection.execute("INSERT INTO #{self.class.schema_info_table_name} (version, plugin_name) VALUES (#{version},'#{current_plugin.name}')") else ActiveRecord::Base.connection.update("UPDATE #{self.class.schema_info_table_name} SET version = #{version} WHERE plugin_name = '#{current_plugin.name}'") end end |