<commit_before>module UsesguidMigrations
  module ActiveRecordExtensions
    module ConnectionAdapters
      module SchemaStatements
      
        def self.included( base )
          base.module_eval do
            alias_method_chain :create_table, :lfe_usesguid_migrations
          end
        end

        def create_table_with_lfe_usesguid_migrations( table_name, options={} )
          table_definition = ActiveRecord::ConnectionAdapters::TableDefinition.new( self )
          #table_definition = TableDefinition.new( self )

          if options[:guid] == false
            table_definition.primary_key( options[:primary_key] || ActiveRecord::Base.get_primary_key( table_name ) ) unless options[:id] == false
          else
            table_definition.guid_primary_key( options[:primary_key] || ActiveRecord::Base.get_primary_key( table_name ) ) unless options[:id] == false
          end

          yield table_definition

          if options[:force] && table_exists?( table_name )
            drop_table( table_name, options )
          end

          create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} TABLE "
          create_sql << "#{quote_table_name( table_name )} ("
          create_sql << table_definition.to_sql
          create_sql << ") #{options[:options]}"
          execute create_sql

          # TODO this needs to be different for each adapter
          unless table_name == "schema_migrations"
            unless options[:id] == false || options[:guid] == false
              execute "ALTER TABLE `#{table_name}` MODIFY COLUMN `#{table_definition.primary_key_name}` VARCHAR(22) BINARY CHARACTER SET latin1 COLLATE latin1_bin NOT NULL;"
              execute "ALTER TABLE `#{table_name}` ADD PRIMARY KEY (#{table_definition.primary_key_name})"
            end

            return if table_definition.associative_keys.nil?

            table_definition.associative_keys.each do |assoc|
              key = assoc.name
              opts = assoc.options
              sql = "ALTER TABLE `#{table_name}` MODIFY COLUMN `#{key}` VARCHAR(#{opts[:limit] || 22}) BINARY CHARACTER SET latin1 COLLATE latin1_bin"
              if opts[:null] == false || opts[:null].nil?
                sql << " NOT NULL;"
              else
                sql << ";"
              end
              execute( sql )
            end
          end
        end
      
      end
    end
  end
end<commit_msg>Overriding add_column method to allow for :guid type.<commit_after>module UsesguidMigrations
  module ActiveRecordExtensions
    module ConnectionAdapters
      module SchemaStatements
      
        def self.included( base )
          base.module_eval do
            alias_method_chain :create_table, :lfe_usesguid_migrations
            alias_method_chain :add_column, :lfe_usesguid_migrations
          end
        end

        def create_table_with_lfe_usesguid_migrations( table_name, options={} )
          table_definition = ActiveRecord::ConnectionAdapters::TableDefinition.new( self )
          #table_definition = TableDefinition.new( self )

          if options[:guid] == false
            table_definition.primary_key( options[:primary_key] || ActiveRecord::Base.get_primary_key( table_name ) ) unless options[:id] == false
          else
            table_definition.guid_primary_key( options[:primary_key] || ActiveRecord::Base.get_primary_key( table_name ) ) unless options[:id] == false
          end

          yield table_definition

          if options[:force] && table_exists?( table_name )
            drop_table( table_name, options )
          end

          create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} TABLE "
          create_sql << "#{quote_table_name( table_name )} ("
          create_sql << table_definition.to_sql
          create_sql << ") #{options[:options]}"
          execute create_sql

          # TODO this needs to be different for each adapter
          unless table_name == "schema_migrations"
            unless options[:id] == false || options[:guid] == false
              execute "ALTER TABLE `#{table_name}` MODIFY COLUMN `#{table_definition.primary_key_name}` VARCHAR(22) BINARY CHARACTER SET latin1 COLLATE latin1_bin NOT NULL;"
              execute "ALTER TABLE `#{table_name}` ADD PRIMARY KEY (#{table_definition.primary_key_name})"
            end

            return if table_definition.associative_keys.nil?

            table_definition.associative_keys.each do |assoc|
              key = assoc.name
              opts = assoc.options
              sql = "ALTER TABLE `#{table_name}` MODIFY COLUMN `#{key}` VARCHAR(#{opts[:limit] || 22}) BINARY CHARACTER SET latin1 COLLATE latin1_bin"
              if opts[:null] == false || opts[:null].nil?
                sql << " NOT NULL;"
              else
                sql << ";"
              end
              execute( sql )
            end
          end
        end

        def add_column_with_lfe_usesguid_migrations( table_name, column_name, type, options={} )
          return add_column_without_lfe_usesguid_migrations( table_name, column_name, type, options ) unless type.to_s == 'guid'

          add_column_sql = "ALTER TABLE #{quote_table_name( table_name )} ADD #{quote_column_name( column_name )} VARCHAR(#{options[:limit] || 22}) BINARY CHARACTER SET latin1 COLLATE latin1_bin"
          add_column_options!( add_column_sql, options )
          execute( add_column_sql )
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09015942825728422, 'fraction_numerical': 0.003665017408832692, 'mean_word_length': 2.4027431421446384, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 3, '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': '6652091', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1509, 'n_words': 362}