mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #28883 from yahonda/fix28797
PostgreSQL 10 does not convert `CURRENT_DATE` into `('now'::text)::date`
This commit is contained in:
commit
1583e260f9
2 changed files with 8 additions and 3 deletions
|
@ -555,7 +555,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def has_default_function?(default_value, default)
|
||||
!default_value && (%r{\w+\(.*\)|\(.*\)::\w+} === default)
|
||||
!default_value && %r{\w+\(.*\)|\(.*\)::\w+|CURRENT_DATE|CURRENT_TIMESTAMP}.match?(default)
|
||||
end
|
||||
|
||||
def load_additional_types(type_map, oids = nil)
|
||||
|
|
|
@ -87,9 +87,14 @@ if current_adapter?(:PostgreSQLAdapter)
|
|||
|
||||
test "schema dump includes default expression" do
|
||||
output = dump_table_schema("defaults")
|
||||
assert_match %r/t\.date\s+"modified_date",\s+default: -> { "\('now'::text\)::date" }/, output
|
||||
if ActiveRecord::Base.connection.postgresql_version >= 100000
|
||||
assert_match %r/t\.date\s+"modified_date",\s+default: -> { "CURRENT_DATE" }/, output
|
||||
assert_match %r/t\.datetime\s+"modified_time",\s+default: -> { "CURRENT_TIMESTAMP" }/, output
|
||||
else
|
||||
assert_match %r/t\.date\s+"modified_date",\s+default: -> { "\('now'::text\)::date" }/, output
|
||||
assert_match %r/t\.datetime\s+"modified_time",\s+default: -> { "now\(\)" }/, output
|
||||
end
|
||||
assert_match %r/t\.date\s+"modified_date_function",\s+default: -> { "now\(\)" }/, output
|
||||
assert_match %r/t\.datetime\s+"modified_time",\s+default: -> { "now\(\)" }/, output
|
||||
assert_match %r/t\.datetime\s+"modified_time_function",\s+default: -> { "now\(\)" }/, output
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue