Skip to content

Comments

Support activerecord v7.0.2#380

Merged
winebarrel merged 2 commits intoridgepole:1.0from
sankichi92:1.0
Feb 11, 2022
Merged

Support activerecord v7.0.2#380
winebarrel merged 2 commits intoridgepole:1.0from
sankichi92:1.0

Conversation

@sankichi92
Copy link
Contributor

@sankichi92 sankichi92 commented Feb 11, 2022

close #379

According to CHANGELOG, activerecord v7.0.2 includes the following related changes.

  • Dump the precision for datetime columns following the new defaults.
  • Dump the database schema containing the current Rails version.

    Since #42297, Rails now generate datetime columns
    with a default precision of 6. This means that users upgrading to Rails 7.0 from 6.1,
    when loading the database schema, would get the new precision value, which would not match
    the production schema.

    To avoid this the schema dumper will generate the new format which will include the Rails
    version and will look like this:

    ActiveRecord::Schema[7.0].define
    

This PR deals with these changes by:

  • update the regexp in Ridgepole::Dumper#dump to handle the new format of schema dump.
  • remove the workaround for activerecord v7.0 in Ridgepole::Diff#normalize_column_options! and fix tests since the precision option for datetime columns follows the new defaults.

@coveralls
Copy link

coveralls commented Feb 11, 2022

Coverage Status

Coverage decreased (-0.002%) to 96.86% when pulling a0f4660 on sankichi92:1.0 into 3f9f8c2 on ridgepole:1.0.

delta = subject.diff(erbh(<<-ERB))
create_table "foos", force: :cascade do |t|
t.datetime "bar", <%= i cond(">= 7.0", { precision: nil }) %>, default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "bar", default: -> { "CURRENT_TIMESTAMP<%= i cond(">= 7.0", "(6)") %>" }, null: false
Copy link
Contributor Author

@sankichi92 sankichi92 Feb 11, 2022

Choose a reason for hiding this comment

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

I think it is better to follow the new default of activerecord v7.0 (referred to rails/rails#43292).

delta = subject.diff(erbh(<<-ERB))
create_table "foos", force: :cascade do |t|
t.datetime "bar", default: -> { '"1970-01-01 00:00:00"' }, null: false
t.datetime "bar", <%= i cond(">= 7.0", { precision: 6 }) %>, default: -> { '"1970-01-01 00:00:00"' }, null: false
Copy link
Contributor Author

@sankichi92 sankichi92 Feb 11, 2022

Choose a reason for hiding this comment

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

The test failed when I omitted this precision option.
But I feel this behavior is odd 🤔

@winebarrel
Copy link
Member

Thank you!

@winebarrel winebarrel merged commit 78b733a into ridgepole:1.0 Feb 11, 2022
@winebarrel
Copy link
Member

v1.0.3 has been released

@sankichi92
Copy link
Contributor Author

Thank you, too!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Idempotency is broken with activerecord v7.0.2

3 participants