Module: PluginAWeek::PluginMigrations::Extensions::SchemaStatements
- Defined in:
- lib/plugin_migrations/extensions/schema_statements.rb
Overview
Adds support for the plugin schema info table
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#dump_schema_information_with_plugins ⇒ Object
Dumps the plugin schema info table as well as information about the current plugin migrations.
-
#initialize_schema_information_with_plugins ⇒ Object
Creates the plugin schema info table.
Class Method Details
.included(base) ⇒ Object
:nodoc:
6 7 8 9 10 11 |
# File 'lib/plugin_migrations/extensions/schema_statements.rb', line 6 def self.included(base) #:nodoc: base.class_eval do alias_method_chain :initialize_schema_information, :plugins alias_method_chain :dump_schema_information, :plugins end end |
Instance Method Details
#dump_schema_information_with_plugins ⇒ Object
Dumps the plugin schema info table as well as information about the current plugin migrations
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/plugin_migrations/extensions/schema_statements.rb', line 26 def dump_schema_information_with_plugins schema_information = [] dump = dump_schema_information_without_plugins schema_information << dump if dump begin plugins = ActiveRecord::Base.connection.select_all("SELECT * FROM #{PluginAWeek::PluginMigrations::Migrator.schema_info_table_name}") plugins.each do |plugin| if (version = plugin['version'].to_i) > 0 plugin_name = ActiveRecord::Base.quote_value(plugin['plugin_name']) schema_information << "INSERT INTO #{PluginAWeek::PluginMigrations::Migrator.schema_info_table_name} (plugin_name, version) VALUES (#{plugin_name}, #{version})" end end rescue ActiveRecord::StatementInvalid # No Schema Info end schema_information.join(";\n") end |
#initialize_schema_information_with_plugins ⇒ Object
Creates the plugin schema info table
14 15 16 17 18 19 20 21 22 |
# File 'lib/plugin_migrations/extensions/schema_statements.rb', line 14 def initialize_schema_information_with_plugins initialize_schema_information_without_plugins begin execute "CREATE TABLE #{PluginAWeek::PluginMigrations::Migrator.schema_info_table_name} (plugin_name #{type_to_sql(:string)}, version #{type_to_sql(:integer)})" rescue ActiveRecord::StatementInvalid # Schema has been initialized end end |