<commit_before>module ActiveRecord  # :nodoc:
  module ConnectionAdapters  # :nodoc:
    module PostGISAdapter  # :nodoc:
      class TableDefinition < PostgreSQL::TableDefinition  # :nodoc:

        def initialize(types, name, temporary, options, as, adapter)
          @adapter = adapter
          @spatial_columns_hash = {}
          super(types, name, temporary, options, as)
        end

        # * `:geometry` -- Any geometric type
        # * `:point` -- Point data
        # * `:line_string` -- LineString data
        # * `:polygon` -- Polygon data
        # * `:geometry_collection` -- Any collection type
        # * `:multi_point` -- A collection of Points
        # * `:multi_line_string` -- A collection of LineStrings
        # * `:multi_polygon` -- A collection of Polygons

        # super: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb#L320
        def new_column_definition(name, type, options)
          if (info = MainAdapter.spatial_column_options(type.to_sym))
            options[:type] = info[:type] || type
            type = options[:type]

            if (limit = options.delete(:limit))
              options.merge!(limit) if limit.is_a?(::Hash)
            end
            if options[:geographic]
              type = :geography
              spatial_type = (options[:type] || 'geometry').to_s.upcase.gsub('_', '')
              spatial_type << 'Z' if options[:has_z]
              spatial_type << 'M' if options[:has_m]
              options[:limit] = "#{spatial_type},#{options[:srid] || 4326}"
            end
            column = super(name, type, options)
            column.spatial_type = options[:type]
            column.geographic = options[:geographic]
            column.srid = options[:srid]
            column.has_z = options[:has_z]
            column.has_m = options[:has_m]
            (column.geographic? ? @columns_hash : @spatial_columns_hash)[name] = column
          else
            column = super(name, type, options)
          end

          column
        end

        def non_geographic_spatial_columns
          @spatial_columns_hash.values
        end

        def spatial(name, options = {})
          column(name, :spatial, options)
        end

        def geography(name, options = {})
          column(name, :geography, options)
        end

        def geometry(name, options = {})
          column(name, :geometry, options)
        end

        def line_string(name, options = {})
          column(name, :line_string, options)
        end

        def point(name, options = {})
          column(name, :point, options)
        end

        def polygon(name, options = {})
          column(name, :polygon, options)
        end

        private

        def create_column_definition(name, type)
          if PostGISAdapter::MainAdapter::SPATIAL_COLUMN_OPTIONS.keys.include?(type.to_sym)
            PostGISAdapter::ColumnDefinition.new(name, type)
          else
            super
          end
        end
      end

      class ColumnDefinition < PostgreSQL::ColumnDefinition  # :nodoc:

        def spatial_type
          @spatial_type
        end

        def spatial_type=(value)
          @spatial_type = value.to_s
        end

        def geographic?
          @geographic
        end

        def geographic=(value)
          @geographic = !!value
        end

        def srid
          if @srid
            @srid.to_i
          else
            geographic? ? 4326 : PostGISAdapter::DEFAULT_SRID
          end<commit_msg>Require a type for spatial columns<commit_after>module ActiveRecord  # :nodoc:
  module ConnectionAdapters  # :nodoc:
    module PostGISAdapter  # :nodoc:
      class TableDefinition < PostgreSQL::TableDefinition  # :nodoc:

        def initialize(types, name, temporary, options, as, adapter)
          @adapter = adapter
          @spatial_columns_hash = {}
          super(types, name, temporary, options, as)
        end

        # * `:geometry` -- Any geometric type
        # * `:point` -- Point data
        # * `:line_string` -- LineString data
        # * `:polygon` -- Polygon data
        # * `:geometry_collection` -- Any collection type
        # * `:multi_point` -- A collection of Points
        # * `:multi_line_string` -- A collection of LineStrings
        # * `:multi_polygon` -- A collection of Polygons

        # super: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb#L320
        def new_column_definition(name, type, options)
          if (info = MainAdapter.spatial_column_options(type.to_sym))
            options[:type] = info[:type] || type
            type = options[:type]

            if (limit = options.delete(:limit))
              options.merge!(limit) if limit.is_a?(::Hash)
            end
            if options[:geographic]
              type = :geography
              spatial_type = (options[:type] || 'geometry').to_s.upcase.gsub('_', '')
              spatial_type << 'Z' if options[:has_z]
              spatial_type << 'M' if options[:has_m]
              options[:limit] = "#{spatial_type},#{options[:srid] || 4326}"
            end
            column = super(name, type, options)
            column.spatial_type = options[:type]
            column.geographic = options[:geographic]
            column.srid = options[:srid]
            column.has_z = options[:has_z]
            column.has_m = options[:has_m]
            (column.geographic? ? @columns_hash : @spatial_columns_hash)[name] = column
          else
            column = super(name, type, options)
          end

          column
        end

        def non_geographic_spatial_columns
          @spatial_columns_hash.values
        end

        def spatial(name, options = {})
          raise "You must set a type. For example: 't.spatial type: :point'" unless options[:type]
          column(name, options[:type], options)
        end

        def geography(name, options = {})
          column(name, :geography, options)
        end

        def geometry(name, options = {})
          column(name, :geometry, options)
        end

        def line_string(name, options = {})
          column(name, :line_string, options)
        end

        def point(name, options = {})
          column(name, :point, options)
        end

        def polygon(name, options = {})
          column(name, :polygon, options)
        end

        private

        def create_column_definition(name, type)
          if MainAdapter.spatial_column_options(type.to_sym)
            PostGISAdapter::ColumnDefinition.new(name, type)
          else
            super
          end
        end
      end

      class ColumnDefinition < PostgreSQL::ColumnDefinition  # :nodoc:

        def spatial_type
          @spatial_type
        end

        def spatial_type=(value)
          @spatial_type = value.to_s
        end

        def geographic?
          @geographic
        end

        def geographic=(value)
          @geographic = !!value
        end

        def srid
          if @srid
            @srid.to_i
          else
            geographic? ? 4326 : PostGISAdapter::DEFAULT_SRID
          end
{'fraction_non_alphanumeric': 0.10385305896975555, 'fraction_numerical': 0.003038254384753487, 'mean_word_length': 1.8783783783783783, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2773230', 'n_tokens_mistral': 2077, 'n_tokens_neox': 1996, 'n_words': 453}