Sha256: 8a6f70e05a544fc98f836d2ec33878e597b6d73844208a0022d536ffd8bdaa92

Contents?: true

Size: 1.21 KB

Versions: 24

Compression:

Stored size: 1.21 KB

Contents

module ActiveRecord
  module ConnectionAdapters
    module MySQL
      class Column < ConnectionAdapters::Column # :nodoc:
        delegate :strict, :extra, to: :sql_type_metadata, allow_nil: true

        def initialize(*)
          super
          assert_valid_default
          extract_default
        end

        def has_default?
          return false if blob_or_text_column? # MySQL forbids defaults on blob and text columns
          super
        end

        def blob_or_text_column?
          /\A(?:tiny|medium|long)?blob\b/ === sql_type || type == :text
        end

        def unsigned?
          /\A(?:enum|set)\b/ !~ sql_type && /\bunsigned\b/ === sql_type
        end

        def case_sensitive?
          collation && collation !~ /_ci\z/
        end

        def auto_increment?
          extra == 'auto_increment'
        end

        private

        def extract_default
          if blob_or_text_column?
            @default = null || strict ? nil : ''
          end
        end

        def assert_valid_default
          if blob_or_text_column? && default.present?
            raise ArgumentError, "#{type} columns cannot have a default value: #{default.inspect}"
          end
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 3 rubygems

Version Path
activerecord-5.0.7.2 lib/active_record/connection_adapters/mysql/column.rb
activerecord-5.0.7.1 lib/active_record/connection_adapters/mysql/column.rb
activerecord-5.0.7 lib/active_record/connection_adapters/mysql/column.rb
activerecord-5.0.6 lib/active_record/connection_adapters/mysql/column.rb
activerecord-5.0.6.rc1 lib/active_record/connection_adapters/mysql/column.rb
activerecord-5.0.5 lib/active_record/connection_adapters/mysql/column.rb
activerecord-5.0.5.rc2 lib/active_record/connection_adapters/mysql/column.rb
activerecord-5.0.5.rc1 lib/active_record/connection_adapters/mysql/column.rb
activerecord-5.0.4 lib/active_record/connection_adapters/mysql/column.rb
activerecord-5.0.4.rc1 lib/active_record/connection_adapters/mysql/column.rb
activerecord-5.0.3 lib/active_record/connection_adapters/mysql/column.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activerecord-5.0.2/lib/active_record/connection_adapters/mysql/column.rb
activerecord-5.0.2 lib/active_record/connection_adapters/mysql/column.rb
activerecord-5.0.2.rc1 lib/active_record/connection_adapters/mysql/column.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/mysql/column.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/mysql/column.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/mysql/column.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/mysql/column.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/mysql/column.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/mysql/column.rb