mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
PostgreSQL 10 allows CURRENT_DATE
and CURRENT_TIMESTAMP
as default functions
Address #28797
In the previous versions of PostgreSQL, `CURRENT_DATE` converted to `('now'::text)::date`
and `CURRENT_TIMESTAMP` converted to `now()`.
Refer these discussions and commit at PostgreSQL :
https://www.postgresql.org/message-id/flat/5878.1463098164%40sss.pgh.pa.us#5878.1463098164@sss.pgh.pa.us
0bb51aa967
This commit is contained in:
parent
deba47799f
commit
4181b677e5
2 changed files with 8 additions and 3 deletions
|
@ -561,7 +561,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