<commit_before>module ActiveWarehouse #:nodoc:
  # Responsible for migrating ActiveWarehouse tables which are automatically created.
  class Migrator < ActiveRecord::Migrator
    class << self
      def schema_info_table_name #:nodoc:
        ActiveRecord::Base.table_name_prefix + 'activewarehouse_schema_info' + ActiveRecord::Base.table_name_suffix
      end
      
      def current_version #:nodoc:
        result = ActiveRecord::Base.connection.select_one("SELECT version FROM #{schema_info_table_name}")
        if result
          result['version'].to_i
        else
          # There probably isn't an entry for this plugin in the migration info table.
          # We need to create that entry, and set the version to 0
          ActiveRecord::Base.connection.execute("INSERT INTO #{schema_info_table_name} (version) VALUES (0)")      
          0
        end
      end    
    end
    
    def set_schema_version(version)
      ActiveRecord::Base.connection.update("UPDATE #{self.class.schema_info_table_name} SET version = #{down? ? version.to_i - 1 : version.to_i}")
    end
  end
end

module ActiveRecord #:nodoc:
  module ConnectionAdapters #:nodoc:
    module SchemaStatements #:nodoc:
      def initialize_schema_information_with_activewarehouse
        initialize_schema_information_without_activewarehouse
        
        begin
          execute "CREATE TABLE #{ActiveWarehouse::Migrator.schema_info_table_name} (version #{type_to_sql(:integer)})"
        rescue ActiveRecord::StatementInvalid
          # Schema has been initialized
        end
      end
      alias_method_chain :initialize_schema_information, :activewarehouse
      
      def dump_schema_information_with_activewarehouse
        schema_information = []
        
        dump = dump_schema_information_without_activewarehouse
        schema_information << dump if dump
        
        begin
          plugins = ActiveRecord::Base.connection.select_all("SELECT * FROM #{ActiveWarehouse::Migrator.schema_info_table_name}")
          plugins.each do |plugin|
            if (version = plugin['version'].to_i) > 0
              schema_information << "INSERT INTO #{ActiveWarehouse::Migrator.schema_info_table_name} (version) VALUES (#{version})"
            end
          end
        rescue ActiveRecord::StatementInvalid 
          # No Schema Info
        end
        
        schema_information.join("\n")
      end
      alias_method_chain :dump_schema_information, :activewarehouse
    end
  end
end<commit_msg>update for Rails 2.1 migrations<commit_after>module ActiveWarehouse #:nodoc:
  # Responsible for migrating ActiveWarehouse tables which are automatically created.
  class Migrator < ActiveRecord::Migrator
    class << self
      def schema_info_table_name #:nodoc:
        ActiveRecord::Base.table_name_prefix + 'activewarehouse_schema_migrations' + ActiveRecord::Base.table_name_suffix
      end
      
      def current_version #:nodoc:
        result = ActiveRecord::Base.connection.select_one("SELECT max(version) FROM #{schema_migrations_table_name}")
        if result
          result['version'].to_i
        else
          # There probably isn't an entry for this plugin in the migration info table.
          # We need to create that entry, and set the version to 0
          ActiveRecord::Base.connection.execute("INSERT INTO #{schema_migrations_table_name} (version) VALUES (0)")      
          0
        end
      end    
    end
    
    def set_schema_version(version)
      ActiveRecord::Base.connection.update("UPDATE #{self.class.schema_migrations_table_name} SET version = #{down? ? version.to_i - 1 : version.to_i}")
    end
  end
end

module ActiveRecord #:nodoc:
  module ConnectionAdapters #:nodoc:
    module SchemaStatements #:nodoc:
      def initialize_schema_migrations_table_with_activewarehouse
        initialize_schema_schema_migrations_table_without_activewarehouse
        
        begin
          execute "CREATE TABLE #{ActiveWarehouse::Migrator.schema_migrations_table_name} (version #{type_to_sql(:integer)})"
        rescue ActiveRecord::StatementInvalid
          # Schema has been initialized
        end
      end
      alias_method_chain :initialize_schema_migrations_table, :activewarehouse
      
      def dump_schema_information_with_activewarehouse
        schema_information = []
        
        dump = dump_schema_information_without_activewarehouse
        schema_information << dump if dump
        
        begin
          plugins = ActiveRecord::Base.connection.select_all("SELECT * FROM #{ActiveWarehouse::Migrator.schema_migrations_table_name}")
          plugins.each do |plugin|
            if (version = plugin['version'].to_i) > 0
              schema_information << "INSERT INTO #{ActiveWarehouse::Migrator.schema_migrations_table_name} (version) VALUES (#{version})"
            end
          end
        rescue ActiveRecord::StatementInvalid 
          # No Schema Info
        end
        
        schema_information.join("\n")
      end
      alias_method_chain :dump_schema_information, :activewarehouse
    end
  end
end
{'fraction_non_alphanumeric': 0.07329534289644331, 'fraction_numerical': 0.002358027117311849, 'mean_word_length': 2.9093701996927805, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7385269', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1366, 'n_words': 319}