Skip to content

Commit 108ae52

Browse files
committed
timestamps and add_timestamps pass additional options. Closes rails#17624
Option passing was already supported when using `create_table` but not for `change_table`. This patch aligns the method signatures.
1 parent f840582 commit 108ae52

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

activerecord/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
* `timestamps` and `add_timestamps` passes additional options along.
2+
(like `null: false`)
3+
4+
Closes #17624.
5+
6+
*Yves Senn*
7+
8+
19
## Rails 4.0.12 (November 16, 2014) ##
210

311
* Cache `CollectionAssociation#reader` proxies separately before and after

activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ def rename_index(index_name, new_index_name)
393393
# Adds timestamps (+created_at+ and +updated_at+) columns to the table. See SchemaStatements#add_timestamps
394394
#
395395
# t.timestamps
396-
def timestamps
397-
@base.add_timestamps(@table_name)
396+
def timestamps(options = {})
397+
@base.add_timestamps(@table_name, options)
398398
end
399399

400400
# Changes the column's definition according to the new options.

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,9 @@ def columns_for_distinct(columns, orders) #:nodoc:
727727
#
728728
# add_timestamps(:suppliers)
729729
#
730-
def add_timestamps(table_name)
731-
add_column table_name, :created_at, :datetime
732-
add_column table_name, :updated_at, :datetime
730+
def add_timestamps(table_name, options = {})
731+
add_column table_name, :created_at, :datetime, options
732+
add_column table_name, :updated_at, :datetime, options
733733
end
734734

735735
# Removes the timestamp columns (+created_at+ and +updated_at+) from the table definition.

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,8 @@ def remove_index_sql(table_name, options = {})
721721
"DROP INDEX #{index_name}"
722722
end
723723

724-
def add_timestamps_sql(table_name)
725-
[add_column_sql(table_name, :created_at, :datetime), add_column_sql(table_name, :updated_at, :datetime)]
724+
def add_timestamps_sql(table_name, options = {})
725+
[add_column_sql(table_name, :created_at, :datetime, options), add_column_sql(table_name, :updated_at, :datetime, options)]
726726
end
727727

728728
def remove_timestamps_sql(table_name)

activerecord/test/cases/migration/change_table_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def test_remove_references_column_type_with_polymorphic_and_options_null_is_fals
7474

7575
def test_timestamps_creates_updated_at_and_created_at
7676
with_change_table do |t|
77-
@connection.expect :add_timestamps, nil, [:delete_me]
78-
t.timestamps
77+
@connection.expect :add_timestamps, nil, [:delete_me, {null: false}]
78+
t.timestamps null: false
7979
end
8080
end
8181

0 commit comments

Comments
 (0)