Rails 7.0 schema has arbitrary precision: 6 added on my timestamps

Viewed 824

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
1 Answers

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.2precision: 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.

Related