Sha256: 3dce1076f1576a33eed153ee08264215d85fd49155ad11f334b777da6c6c5f5a

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
  def initialize_schema_migrations_table_with_plugins
    initialize_schema_migrations_table_without_plugins

    begin
      execute "CREATE TABLE #{Desert::PluginMigrations::Migrator.schema_migrations_table_name} (plugin_name #{type_to_sql(:string)}, version #{type_to_sql(:string)})"
      plugins_and_versions = select_all("SELECT plugin_name, version from #{Desert::PluginMigrations::Migrator.schema_info_table_name}")
      plugins_and_versions.each do |plugin_data|
        plugin_name, version = plugin_data["plugin_name"], plugin_data["version"]
        plugin = Desert::Manager.find_plugin(plugin_name)
        migration_versions = Dir["#{plugin.migration_path}/*.rb"].map do |path|
          File.basename(path, ".rb")
        end.select do |migration|
          Integer(migration.split("_").first) <= Integer(version)
        end
        migration_versions.each do |migration_version|
          insert_sql = ActiveRecord::Base.send(:sanitize_sql, [
            "INSERT INTO #{Desert::PluginMigrations::Migrator.schema_migrations_table_name}(plugin_name, version) VALUES(?, ?)",
            plugin_name,
            Integer(migration_version.split("_").first)
          ])
          execute insert_sql
        end
      end
    rescue ActiveRecord::StatementInvalid
      # Schema has been initialized
    end
  end
  alias_method_chain :initialize_schema_migrations_table, :plugins
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
joshnabbott-desert-0.3.5.2 lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb
joshnabbott-desert-0.3.5.3 lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb
desert-0.3.3 lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb