New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix migration compatibility for default precision value on datetime columns #42606
Fix migration compatibility for default precision value on datetime columns #42606
Conversation
cc68421
to
365acb6
Compare
👋 @robertomiranda @guilleiguaran this seems to have broken some migrations in our application when using class AddColumnWorks < ActiveRecord::Migration[4.2]
def change
add_column :my_table, :some_column, :datetime, default: -> { "NOW()" }, null: false
end
end works but class AddColumnWorks < ActiveRecord::Migration[4.2]
def change
create_table :my_table do |t|
t.datetime :some_column, default: -> { "NOW()" }, null: false
end
end
end fails with |
@Tonkpils interesting, it would be good to add a test case, which RDMS are you using? |
mysql |
@Tonkpils is the issue specific to |
The compatibility broke for |
Looks like they are broken from 4.2 to 6.0 I'm working on a fix here #42631 |
For added context and in case it helps @robertomiranda , looks like the query generated when on this PR looks like
because the precision is added (not sure how), the |
In theory the |
Background
I have made a mistake on #42297, the definitions for add_column and column were put under the wrong class
rails/activerecord/lib/active_record/migration/compatibility.rb
Lines 286 to 335 in 246bac4
As you can notice above they are in the V4_2 class when they should be in V6_1, in 9b9d9c7 I could verify this by changing the versions of the migrations from 4.2 to 6.1, please the errors here https://buildkite.com/rails/rails/builds/78711#d5c2b003-4552-4173-afc9-61e46d8b4fde
Solution
Move the definitions to v6_1 and tweak V5_0 to add support older than 5.0 365acb6
cc @guilleiguaran @zzak @ghiculescu