Change the default `null` value for timestamps #16481

Merged
merged 1 commit into from Aug 18, 2014

Conversation

Projects
None yet
5 participants
@sgrif
Member

sgrif commented Aug 12, 2014

As per discussion, this changes the model generators to specify
null: false for timestamp columns. A warning is now emitted if
timestamps is called without a null option specified, so we can
safely change the behavior when no option is specified in Rails 5.

Change the default `null` value for timestamps
As per discussion, this changes the model generators to specify
`null: false` for timestamp columns. A warning is now emitted if
`timestamps` is called without a `null` option specified, so we can
safely change the behavior when no option is specified in Rails 5.
@jeremy

This comment has been minimized.

Show comment
Hide comment
@jeremy

jeremy Aug 12, 2014

Member

Not sure how this can be safe unless old migrations are updated as well? They'll be implicitly null: true, but will generate null: false after the app is upgraded to Rails 5.

Member

jeremy commented Aug 12, 2014

Not sure how this can be safe unless old migrations are updated as well? They'll be implicitly null: true, but will generate null: false after the app is upgraded to Rails 5.

@sgrif

This comment has been minimized.

Show comment
Hide comment
@sgrif

sgrif Aug 12, 2014

Member

That's the goal behind the deprecation warning if it is unspecified, users will need to specify null: true if they would like to keep that behavior, and will receive a deprecation warning until they specify one way or the other.

Member

sgrif commented Aug 12, 2014

That's the goal behind the deprecation warning if it is unspecified, users will need to specify null: true if they would like to keep that behavior, and will receive a deprecation warning until they specify one way or the other.

@jeremy

This comment has been minimized.

Show comment
Hide comment
@jeremy

jeremy Aug 12, 2014

Member

The deprecation warning will come too late though, after the migration already ran on the production db.

Member

jeremy commented Aug 12, 2014

The deprecation warning will come too late though, after the migration already ran on the production db.

@sgrif

This comment has been minimized.

Show comment
Hide comment
@sgrif

sgrif Aug 12, 2014

Member

The warning would also appear any time anyone did anything related to schema.rb, including running tests after a new migration is created.

Member

sgrif commented Aug 12, 2014

The warning would also appear any time anyone did anything related to schema.rb, including running tests after a new migration is created.

dhh added a commit that referenced this pull request Aug 18, 2014

Merge pull request #16481 from sgrif/sg-change-default-timestamps
Change the default `null` value for timestamps

@dhh dhh merged commit 7ee0550 into rails:master Aug 18, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@prathamesh-sonpatki

This comment has been minimized.

Show comment
Hide comment
@prathamesh-sonpatki

prathamesh-sonpatki Sep 28, 2014

Member

@sgrif @jeremy Should this be mentioned in upgrade guide?

@sgrif @jeremy Should this be mentioned in upgrade guide?

@jschroeder9000

This comment has been minimized.

Show comment
Hide comment
@jschroeder9000

jschroeder9000 Jun 4, 2015

This deprecation only pertains to the timestamps method that creates the created_at and updated_at columns, right? I had a migration that had both t.timestamps and t.timestamp :column_name in it spit this out at me and since the deprecation message says #timestamp (note lack of s) it was a bit confusing.

This deprecation only pertains to the timestamps method that creates the created_at and updated_at columns, right? I had a migration that had both t.timestamps and t.timestamp :column_name in it spit this out at me and since the deprecation message says #timestamp (note lack of s) it was a bit confusing.

@mikeastock mikeastock referenced this pull request in ClosureTree/closure_tree Jul 25, 2015

Merged

Specify null false for timestamps and pass id to exists? #170

JuanitoFatas added a commit to JuanitoFatas/mailkick that referenced this pull request Feb 1, 2016

Update timestamps in migration for Rails 5
Rails 5 timestamp has `null: false` options.

Ref. rails/rails#16481

@JuanitoFatas JuanitoFatas referenced this pull request in ankane/mailkick Feb 1, 2016

Closed

Update migration for Rails 5 #13

JuanitoFatas added a commit to JuanitoFatas/mailkick that referenced this pull request Feb 1, 2016

Update timestamps in migration for Rails 5
Rails 5 timestamp has `null: false` options.

Ref. rails/rails#16481

JuanitoFatas added a commit to JuanitoFatas/mailkick that referenced this pull request Feb 1, 2016

Update migration file for Rails 5
Rails 5 timestamp has `null: false` options.

Ref. rails/rails#16481

Add version identifier to superclass if on Rails 5

Ref. rails/rails#21538

JuanitoFatas added a commit to JuanitoFatas/mailkick that referenced this pull request Feb 1, 2016

Update migration file for Rails 5
Rails 4.2 timestamp needs to pass in `null: false` options.

Ref. rails/rails#16481

Add version identifier to superclass if on Rails 5

Ref. rails/rails#21538

ggiraldez added a commit to instedd/resourcemap that referenced this pull request Mar 29, 2016

Fix migrations for paranoia and Rails 4 [ci skip]
- Use unscoped when referring to Site to remove the deleted_at column in
  SQL queries built by ActiveRecord.
- Add :null => false to all timestamps definitions. Default changed
  from Rails 3.2 to 4.0. See rails/rails#16481

@sgrif sgrif deleted the sgrif:sg-change-default-timestamps branch Mar 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment