<commit_before>require 'consistency_fail/index'

module ConsistencyFail
  module Introspectors
    class TableData
      def unique_indexes(model)
        return [] if !model.table_exists?

        unique_indexes_by_table(model, model.connection, model.table_name)
      end

      def unique_indexes_by_table(model, connection, table_name)
        ar_indexes = connection.indexes(table_name).select(&:unique)
        result = ar_indexes.map do |index|
          ConsistencyFail::Index.new(model,
                                     table_name,
                                     index.columns)
        end
        result
      end<commit_msg>select current schema<commit_after>require 'consistency_fail/index'

module ConsistencyFail
  module Introspectors
    class TableData
      def unique_indexes(model)
        return [] if !model.table_exists?

        unique_indexes_by_table(model, model.connection, model.table_name, schema)
      end

      def unique_indexes_by_table(model, connection, table_name)
        schema = "public"
        if ActiveRecord::Base.connection.instance_values["config"][:adapter] == "postgresql"
          schema = ActiveRecord::Base.connection.execute("select current_schema();").to_a.first["current_schema"]
        end
        table_name = "#{schema}." + table_name if table_name.present?
        ar_indexes = connection.indexes(table_name).select(&:unique)
        result = ar_indexes.map do |index|
          ConsistencyFail::Index.new(model,
                                     table_name,
                                     index.columns)
        end
        result
      end
{'fraction_non_alphanumeric': 0.08317929759704251, 'fraction_numerical': 0.0, 'mean_word_length': 2.3075356415478616, 'pattern_counts': {'":': 0, '<': 3, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5037276', 'n_tokens_mistral': 451, 'n_tokens_neox': 441, 'n_words': 82}