-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
DB schema dumper uncompatibility in Rails 7.0 #43909
Comments
Same here.
@robertomiranda do you have a clue maybe what could cause it in #42297 ? |
We are also seeing an issue here. Our |
Looks like #44171 may help fix this issue. |
The merged PR was about mysql. We're using postgresql, so I think this still will be an issue |
Before loading the schema with a new version of Rails you should dump it. I'm going to fix this requirement, but right now that is the correct way to solve the issue. |
Long term fix is here #44286 |
Since #42297, Rails now generates datetime columns on MySQL 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 problems like this in the future, Rails will now freeze `ActiveRecord::Schema` class to be the 7.0 implementation, and will allow access to other version using the same mechanism of `ActiveRecord::Migration`. The schema dumper will generate the new format which will include the Rails version and will look like this: ``` ActiveRecord::Schema[7.0].define ``` Related to #43934 and #43909.
I don't think that would solve this issue- because the old default I believe your pending PR that allows specifying the compatibility version of the Schema class will fix it- that solution looks great. But I've found no simple temporary fix, and have currently resorted to monkey patching |
This is already fixed in 7-0-stable. |
Since #42297, Rails now generates datetime columns on MySQL 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 problems like this in the future, Rails will now freeze `ActiveRecord::Schema` class to be the 7.0 implementation, and will allow access to other version using the same mechanism of `ActiveRecord::Migration`. The schema dumper will generate the new format which will include the Rails version and will look like this: ``` ActiveRecord::Schema[7.0].define ``` Related to #43934 and #43909.
I see the patch eca89fd from PR #44171 on 7-0-stable, but that will only affect MySQL and not Postgres, right? Whereas your PR should effectively solve for any DB adapter after setting the schema.rb version to 6.1. Unless you're referring to a different fix. |
Postgres should not have that problem. Does it? |
Here's a minimal reproduction with PG, forked from the MySQL example in the issue description:
|
Wait, that makes no sense at all. You don't even loaded the schema, so the precision in the database should not be 6. Are those really the steps you took? |
@rafaelfranca The steps here #43909 (comment) are reproducing it for PostgreSQL |
That is still loading the schema generated in 6.1 without dumping in first in 7.0, so not really reproducing the issue. The fix for that is load the schema in 6.1 and them dump in 7.0. |
So steps to fix you problem are:
Or dump the production database using Rails 7.0. |
Ok. I think I got the problem now. #44356 should fix it. Can someone try? |
Since Rails 7.0 the datetime column precision is 6 by default. That means that `t.datetime` calls without setting the `:precision` option would have its precision set to 6. The schema dumper was generating a call without precision for columns with the precision set to `nil` (which has the same effect of 0), making the schema dump incorrect for the next load since that would be interpreted as if the precision was 6. This didn't affect MySQL since #44171, since MySQL precision is 0 by default not `nil` but it affected PostgreSQL and SQLite3. Now the dumper will generate the precision as 0 for columns without precision and omit it when the precision is 6. Related to #43909.
Since rails#42297, Rails now generates datetime columns on MySQL 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 problems like this in the future, Rails will now freeze `ActiveRecord::Schema` class to be the 7.0 implementation, and will allow access to other version using the same mechanism of `ActiveRecord::Migration`. The schema dumper will generate the new format which will include the Rails version and will look like this: ``` ActiveRecord::Schema[7.0].define ``` Related to rails#43934 and rails#43909.
Since Rails 7.0 the datetime column precision is 6 by default. That means that `t.datetime` calls without setting the `:precision` option would have its precision set to 6. The schema dumper was generating a call without precision for columns with the precision set to `nil` (which has the same effect of 0), making the schema dump incorrect for the next load since that would be interpreted as if the precision was 6. This didn't affect MySQL since rails#44171, since MySQL precision is 0 by default not `nil` but it affected PostgreSQL and SQLite3. Now the dumper will generate the precision as 0 for columns without precision and omit it when the precision is 6. Related to rails#43909.
@rafaelfranca I have an issue with
More importantly, I think this means an actual schema change that would not be reflected on production, only locally. Opened an issue: #44571 |
Steps to reproduce
Expected behavior
No diffs in schema.rb
Actual behavior
The following differences will occur
I think there was a lack of compatibility considerations in #42297.
System configuration
Rails version: v7.0.0
Ruby version: v3.0.3
The text was updated successfully, but these errors were encountered: