Sha256: 45b64898ad8f2caf4f2c6d2d14c012d6335aec4bd4a561d0e2c757fce0a9c2d3

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

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

    begin
      smt = Desert::PluginMigrations::Migrator.schema_migrations_table_name
      unless ActiveRecord::Base.connection.tables.include?(smt)
        execute "CREATE TABLE #{smt} (plugin_name #{type_to_sql(:string)}, version #{type_to_sql(:string)})"
      end
      if Desert::PluginMigrations::Migrator.legacy_schema_table_exists?
        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|
            # Make sure versions don't start with zero, or Integer will interpret them as octal
            version_from_table_stripped = version.to_s.sub(/^0*/, '')
            migration_version_stripped = migration.split("_").first.sub(/^0*/, '')
            Integer(migration_version_stripped) <= Integer(version_from_table_stripped)
          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.sub(/^0*/, ''))
            ])
            execute insert_sql
          end
        end
      end
    end
  end
  alias_method_chain :initialize_schema_migrations_table, :plugins
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
desert-0.5.4 lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb