Skip to content

Make t.timestamps with precision by default. - #34970

Merged
kamipo merged 1 commit into
rails:masterfrom
kamipo:timestamps_with_precision_by_default
Jan 26, 2019
Merged

kamipo merged 1 commit into
rails:masterfrom
kamipo:timestamps_with_precision_by_default

Conversation

@kamipo

@kamipo kamipo commented Jan 18, 2019

Copy link
Copy Markdown
Member

I'm not sure it is what we want make it in Rails 6.0.
But I've just implemented to ease to discuss that on this PR.

Context: #34956 (comment)

@kamipo
kamipo force-pushed the timestamps_with_precision_by_default branch 2 times, most recently from fd2746b to 5fcf8e9 Compare January 18, 2019 03:39

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this not cause warnings of unused arguments?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently Ruby doesn't raise any warnings of unused method arguments for now.

https://travis-ci.org/rails/rails/jobs/481187001

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to do this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just keep db/schema.rb as before.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need these similar overrides?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is to inject V5_2::TableDefinition to the table definition instance.

https://github.com/rails/rails/pull/34970/files#diff-2a8be25f82da6b3935cc6a41300a1b01R19`

If the change_table is removed, the test_timestamps_doesnt_set_precision_on_change_table is failed.

https://github.com/rails/rails/pull/34970/files#diff-ec048630132cce280a9445022318906eR140

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be supports_datetime_with_precision??

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supports_datetime_with_precision? can't be used in the ActiveRecord::TestCase scope.
subsecond_precision_supported? is defined in the top level as a helper.

https://github.com/rails/rails/blob/5fcf8e98808c59bc1496a4048e133a7b32512765/activerecord/test/cases/helper.rb#L43-L45

@kamipo
kamipo force-pushed the timestamps_with_precision_by_default branch from 5fcf8e9 to ec47e62 Compare January 26, 2019 13:13
@kamipo
kamipo force-pushed the timestamps_with_precision_by_default branch from ec47e62 to 57015cd Compare January 26, 2019 13:51
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed to apply new default the same with Action Mailbox.

@kamipo
kamipo merged commit 5a8f0c7 into rails:master Jan 26, 2019
@kamipo
kamipo deleted the timestamps_with_precision_by_default branch January 26, 2019 14:37
kamipo added a commit to kamipo/rails that referenced this pull request May 28, 2019
Currently, if `:datetime` type has a precision, type casting always does
round off subseconds regardless of whether necessary or not, it is a bit
slow.

Since rails#34970, `t.timestamps` with `precision: 6` by default, so
`pluck(:created_at)` in newly created app will always be affected by the
round off.

This avoids the round off if possible, it makes `pluck(:created_at)`
about 25% faster.

https://gist.github.com/kamipo/e029539f2632aee9f5e711fe66fc8842

Before (0a87d7c with postgresql adapter):

```
Warming up --------------------------------------
    users.pluck(:id)      344.000  i/100ms
  users.pluck(:name)      336.000  i/100ms
users.pluck(:created_at)  206.000  i/100ms
Calculating -------------------------------------
    users.pluck(:id)      3.620k (± 8.5%) i/s -     18.232k in   5.077316s
  users.pluck(:name)      3.579k (± 9.4%) i/s -     17.808k in   5.020230s
users.pluck(:created_at)  2.069k (± 8.0%) i/s -     10.300k in   5.019284s
```

Before (0a87d7c with mysql2 adapter):

```
Warming up --------------------------------------
    users.pluck(:id)      245.000  i/100ms
  users.pluck(:name)      240.000  i/100ms
users.pluck(:created_at)  180.000  i/100ms
Calculating -------------------------------------
    users.pluck(:id)      2.548k (± 9.4%) i/s -     12.740k in   5.066574s
  users.pluck(:name)      2.513k (± 8.0%) i/s -     12.480k in   5.011260s
users.pluck(:created_at)  1.771k (±11.2%) i/s -      8.820k in   5.084473s
```

After (this change with postgresql adapter):

```
Warming up --------------------------------------
    users.pluck(:id)      348.000  i/100ms
  users.pluck(:name)      357.000  i/100ms
users.pluck(:created_at)  254.000  i/100ms
Calculating -------------------------------------
    users.pluck(:id)      3.628k (± 8.2%) i/s -     18.096k in   5.024748s
  users.pluck(:name)      3.624k (±12.4%) i/s -     17.850k in   5.020959s
users.pluck(:created_at)  2.567k (± 7.0%) i/s -     12.954k in   5.081153s
```

After (this change with mysql2 adapter):

```
Warming up --------------------------------------
    users.pluck(:id)      268.000  i/100ms
  users.pluck(:name)      265.000  i/100ms
users.pluck(:created_at)  207.000  i/100ms
Calculating -------------------------------------
    users.pluck(:id)      2.586k (±10.9%) i/s -     12.864k in   5.050546s
  users.pluck(:name)      2.543k (±10.2%) i/s -     12.720k in   5.067726s
users.pluck(:created_at)  2.263k (±14.5%) i/s -     10.971k in   5.004039s
```
suketa added a commit to suketa/rails_sandbox that referenced this pull request Jul 26, 2019
Make `t.timestamps` with precision by default
rails/rails#34970
suketa added a commit to suketa/rails_sandbox that referenced this pull request Jul 26, 2019
Make `t.timestamps` with precision by default
rails/rails#34970
@andrewhaines

Copy link
Copy Markdown
Contributor

@kamipo Do you think there's any benefit to documenting that this is incompatible w/ MySQL 5.5? I ran across that issue the other day (the shared ClearDB environments for Heroku don't allow higher versions than 5.5) and it took me a while to figure out what was happening. If so, I'm happy to contribute it.

@kamipo

kamipo commented Feb 8, 2020

Copy link
Copy Markdown
Member Author

What is the incompatible you mean?

@andrewhaines

Copy link
Copy Markdown
Contributor

datetime doesn't support precision in MySQL 5.5.

@jcoleman

Copy link
Copy Markdown
Contributor

@kamipo I'm still interested in what the reasoning for this was. Following the links to the discussion it appears this came out of a discussion about MySQL, but this change affected not just MySQL but also databases like Postgres that don't need this change. And I can't find any discussion at all explaining why the change is desirable or was made in the first place.

@jcoleman

Copy link
Copy Markdown
Contributor

In fact the comment actually says this should be for MySQL only and be omitted on PostgreSQL, but that's not what this PR ending up doing.

@zzak

zzak commented Feb 16, 2023

Copy link
Copy Markdown
Member

@jcoleman Unfortunately, you might not be able to get a response on a 3 or 4 year old PR. If there is a bug that you've identified, I recommend opening a new issue, or submitting a PR which applies your desired behavior. 🙏

@jcoleman

Copy link
Copy Markdown
Contributor

@zzak Unfortunately getting responses on even new PRs in the Rails project is...not common.

Another issue was opened the same year as this PR asking for an explanation of the change, and no one answered the question there either.

kamipo added a commit that referenced this pull request Sep 10, 2024
The `timestamps` tests for #34970 and a939506 are mostly overlapped, so
consolidate these tests as "test timestamps with implicit defalut".
DanielaVelasquez pushed a commit to DanielaVelasquez/rails that referenced this pull request Oct 3, 2024
The `timestamps` tests for rails#34970 and a939506 are mostly overlapped, so
consolidate these tests as "test timestamps with implicit defalut".
yahonda added a commit to yahonda/rails that referenced this pull request Jul 16, 2026
Seven Migration::Compatibility version classes carried an identical
private compatible_table_definition override whose only job was to
prepend the class's own TableDefinition module. Compose the modules in
a single walk in Migration::Current#compatible_table_definition
instead: it prepends the TableDefinition module of every Compatibility
version class among the migration's ancestors, oldest version first,
which produces the same method lookup order as the per-class overrides.
The walk filters the ancestors against the new memoized
`Compatibility.version_classes`. A version class now only declares its
TableDefinition module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Jul 18, 2026
Seven Migration::Compatibility version classes carried an identical
private compatible_table_definition override whose only job was to
prepend the class's own TableDefinition module. Compose the modules in
a single walk in Migration::Current#compatible_table_definition
instead: it prepends the TableDefinition module of every Compatibility
version class among the migration's ancestors, oldest version first,
which produces the same method lookup order as the per-class overrides.
The walk filters the ancestors against the new memoized
`Compatibility.version_classes`. A version class now only declares its
TableDefinition module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Jul 18, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Jul 20, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Jul 21, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Aug 6, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Aug 7, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Aug 18, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Aug 20, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Aug 20, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Aug 21, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Aug 25, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Aug 31, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Sep 1, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Sep 1, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Sep 3, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Sep 3, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Sep 8, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Sep 16, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yahonda added a commit to yahonda/rails that referenced this pull request Sep 20, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
excid3 pushed a commit to excid3/rails that referenced this pull request Oct 5, 2026
Seven Migration::Compatibility version classes carried an identical
compatible_table_definition override just to prepend their own
TableDefinition module. Replace the overrides with a single ancestor
walk in Migration::Current, preserving the method lookup order; a
version class now only declares its module.

The seven overrides accumulated one version class at a time:

* 214dc7d - V5_0 and V4_2
* 57015cd (rails#34970) - V5_2
* e8437a6 (rails#38717) - V6_0
* 867d27d (rails#41084) - V6_1
* da472b6 (rails#43904) - V7_0
* 489e08d (rails#55086) - V8_0

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants