Merge pull request #41483 from 97jaz/schema-dumper-infinite-date

Fix schema dumper for infinite dates in PostgreSQL
This commit is contained in:
Ryuta Kamizono 2021-02-18 18:05:40 +09:00 committed by GitHub
commit 50b5371001
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -16,6 +16,14 @@ module ActiveRecord
super
end
end
def type_cast_for_schema(value)
case value
when ::Float::INFINITY then "::Float::INFINITY"
when -::Float::INFINITY then "-::Float::INFINITY"
else super
end
end
end
end
end

View File

@ -598,6 +598,8 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase
t.float :float_with_nan_default, default: Float::NAN
t.datetime :beginning_of_time, default: "-infinity"
t.datetime :end_of_time, default: "infinity"
t.date :date_with_neg_inf_default, default: -::Float::INFINITY
t.date :date_with_pos_inf_default, default: ::Float::INFINITY
end
end
end
@ -623,5 +625,7 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase
assert_match %r{t\.float\s+"float_with_nan_default",\s+default: ::Float::NAN}, output
assert_match %r{t\.datetime\s+"beginning_of_time",\s+default: -::Float::INFINITY}, output
assert_match %r{t\.datetime\s+"end_of_time",\s+default: ::Float::INFINITY}, output
assert_match %r{t\.date\s+"date_with_neg_inf_default",\s+default: -::Float::INFINITY}, output
assert_match %r{t\.date\s+"date_with_pos_inf_default",\s+default: ::Float::INFINITY}, output
end
end