Sha256: f7883c7c5479da7e80131e6c5fb0f72cb572c82337945c5d75be893dbbaf0496

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

module ActiveRecord
  module ConnectionAdapters
    module MySQL
      module ColumnDumper
        def column_spec_for_primary_key(column)
          spec = {}
          if column.bigint?
            spec[:id] = ':bigint'
            spec[:default] = schema_default(column) || 'nil' unless column.auto_increment?
            spec[:unsigned] = 'true' if column.unsigned?
          elsif column.auto_increment?
            spec[:unsigned] = 'true' if column.unsigned?
            return if spec.empty?
          else
            spec[:id] = column.type.inspect
            spec.merge!(prepare_column_options(column).delete_if { |key, _| [:name, :type, :null].include?(key) })
          end
          spec
        end

        def prepare_column_options(column)
          spec = super
          spec[:unsigned] = 'true' if column.unsigned?
          spec
        end

        def migration_keys
          super + [:unsigned]
        end

        private

        def schema_type(column)
          if column.sql_type == 'tinyblob'
            'blob'
          else
            super
          end
        end

        def schema_limit(column)
          super unless column.type == :boolean
        end

        def schema_precision(column)
          super unless /time/ === column.sql_type && column.precision == 0
        end

        def schema_collation(column)
          if column.collation && table_name = column.instance_variable_get(:@table_name)
            @table_collation_cache ||= {}
            @table_collation_cache[table_name] ||= select_one("SHOW TABLE STATUS LIKE '#{table_name}'")["Collation"]
            column.collation.inspect if column.collation != @table_collation_cache[table_name]
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activerecord-5.0.0.beta2 lib/active_record/connection_adapters/mysql/schema_dumper.rb
activerecord-5.0.0.beta1.1 lib/active_record/connection_adapters/mysql/schema_dumper.rb
activerecord-5.0.0.beta1 lib/active_record/connection_adapters/mysql/schema_dumper.rb