-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Using unsupported database features leads to incomplete schema.rb files without error or warning #36359
Comments
Oh wow, agreed this is a nasty gotcha. This is really old behaviour introduced in 87535f5 I wonder how many people are relying on this? Otherwise it feels like we can fix this by removing the |
I suspect zero people are wittingly relying on this, but that a very large number of projects will experience an error on very old migrations when running Fortunately, the solution won't be "change your old migrations", since forward-compatibility of migrations is critical. Rather the message can contain the solution: just change the dump format in your application config. As far as timing, this seems like the perfect kind of thing to include in a major version bump. Not a functional change, just one that'll break a bunch of builds but offer a <1 minute fix. |
👍 agreed, I meant along the lines of old migrations as you pointed out. As for the timing I think it makes sense to loop in @rafaelfranca who's the release manager of rails and see his thoughts on including it. |
I talked to @rafaelfranca and we were all of the same mind that this makes sense to put in for rails 6. I'll put up a PR for this shortly. |
Previoulsy the schema dumper when it encountered a failure it would rescue the exception and leave a comment on the schema.rb. Now we raise an exception and let the developer be aware that the schema was not dumped sucessfuly. If an error is raised the `db/schema.rb` file remains the same, we only modify it if the dump was successful. Fixes: rails#36359
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
I can confirm that this is still an issue, even on rails 6, and that no exception was raised - only a comment is made in schema.rb. |
Can also confirm that this still happens on 6.0.2.2. Took a while to figure out why tests were failing |
Can also confirm that this still happens in 6.0.3 as well. Only a comment made in schema.rb |
Steps to reproduce
When running migrations and using the default schema.rb dump strategy, if a table cannot be dumped, migrations will not raise an error or log a warning, but rather leave a comment.
For example, given this migration:
Running migrations will result in this
schema.rb
file:Here's a repro-repo demonstrating the issue: https://github.com/searls/rails-repro-schema-squelch
Here's the specific commit of interest.
Expected behavior
I expected Rails to raise an error in this case, and prompt the user to set
config.active_record.schema_format = :sql
, explaining that they need to switch tostructure.sql
to have a reproducible schema dump.As it stands, the only moment someone will discover their dump is incomplete is later—potentially much later—when running something like
rake db:test:prepare
orrake db:schema:load
on a new environment that depends on the schema being complete. Worse, the error they see (from a table not existing) may take users a while to trace back to an incomplete schema, since (in my experience) relatively few Rails developers have a firm understanding of when and howdb/schema.rb
is used by Rails.Actual behavior
As described above, the actual behavior is:
System configuration
Rails version: 5.2.3
Ruby version: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin18]
The text was updated successfully, but these errors were encountered: