'Rails 7.0 schema has arbitrary precision: 6 added on my timestamps
I am working on a new rails app, when I am running the migrations the schema.rb is changing, a new param precision is added to my timestamps.
Where does this precision new param comes from?
t.datetime "created_at", precision: 6, null: false
Solution 1:[1]
precision is added by the ActiveRecord::ConnectionAdapters::SchemaStatements#add_timestamps method.
It's not arbitrary but pretty appropriate for timestamp attributes (microseconds precision vs seconds precision), if the RDBMS supports it.
Those defaults have been there for at least 3 years now (since Rails 6.0).
Since the summer of 2021 #add_column and #column methods define them too. So if you upgrade to Rails 7.0.2 — precision: 6 will be removed from schema.rb as it's now an internal logic.
You can find some relevant migration guidelines in the Active Record changelog.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
