blob: 9c45fdd44a8e447b154221d3b0c0d3d8140c5bca (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
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?
/\bunsigned\z/ === 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
|