-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Sqlite3 Migration Error Fixed (issue #26087) #26089
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @matthewd (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
Can we add a regression test here, to ensure that the bug is now fixed? 😬 |
How do I do a regression test? Is it a built in test like the Sqlite test suite that I ran from the contribution guide? |
You can add a regression test by creating another test case -- I'd advise you stick around this area, where it seems like there are other tests that deal with migration errors. Also, when get a chance, can you take a look at the Travis CI errors? Thanks! |
Looks like the Travis CI is failing because I used the safe navigation operator from 2.3.0 Will change to work on older versions. Edit: pushed change |
#/activerecord/test/cases/migration_test.rb:312
def test_allows_sqlite3_rollback_on_invalid_column_type
if current_adapter?(:SQLite3Adapter)
Person.connection.create_table :something, force: true do |t|
t.column :number, :integer
t.column :name, :string
t.column :foo, :bar
end
assert Person.connection.column_exists?(:something, :foo)
assert_nothing_raised { Person.connection.remove_column :something, :foo, :bar }
assert !Person.connection.column_exists?(:something, :foo)
assert Person.connection.column_exists?(:something, :name)
assert Person.connection.column_exists?(:something, :number)
end
end |
Noticed a very minor issue wile running the tests. Doesn't break, just yells at you: rails/activerecord/test/cases/scoping/relation_scoping_test.rb:249: warning: ambiguous first argument; put parentheses or a space even after `/' operator assert_match /LIMIT 10|ROWNUM <= 10|FETCH FIRST 10 ROWS ONLY/, sql I got rid of this message by simply putting parens around the arguments: assert_match(/LIMIT 10|ROWNUM <= 10|FETCH FIRST 10 ROWS ONLY/, sql) Would you like me to add this change to the pull request? |
@travisoneill You accidentally pushed your |
@alexcameron89 Thanks for catching that. Fixed |
@matthewd @maclover7 |
Can you please squash down your five commits to one? Thanks! |
9e9bebf
to
7dc082f
Compare
@maclover7 Squashed commits but now failing Travis CI. Coming from tests in '/actionview' Diffs are exactly the same as before I squashed and when I ran tests locally it fails in 'master' too, so maybe unrelated? Do you have any idea what's going on or how to fix it? |
@maclover7 Merged with master to get the Travis CI to pass. Do I need to squash these merge commits too? |
If possible, that'd be great :) |
1e630dc
to
3158a65
Compare
@maclover7 When I squashed this time it drags in changes that other people made and failing codeclimate because of those changes. Is that OK? (sorry for all the questions, it's my first time contributing to a large project). |
Up to you what you'd like to do. I'd encourage fixing them :) |
53519cc
to
90e4e1c
Compare
@maclover7 Fixed, squashed, and passing! Learned some cool Git stuff there too! Let me know if there is anything else that needs doing. |
Thank you for all of your efforts @travisoneill! Now we will have to wait until someone higher up the chain can come and review your PR. |
@@ -303,7 +303,7 @@ def [](name) | |||
# end | |||
def column(name, type, options = {}) | |||
name = name.to_s | |||
type = type.to_sym | |||
type = type ? type.to_sym : :__placeholder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if type
information is not there should not we just not call to_sym
on it and pass nil
down in the stream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelfranca It calls type.to_sym
one more time before finishing so I would have to go in and also handle the nil case there to fix. Would that be preferable to this solution? Can fix it quickly if so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where it does call it? Yeah, I think it is better to just ignore nil than adding a placeholder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelfranca /activerecord/lib/active_record/connection_adapters/abstract/schema_statements
have a working fix now. Will push up.
d6498d0
to
abb61a3
Compare
@@ -309,6 +309,21 @@ def migrate(x) | |||
"On error, the Migrator should revert schema changes but it did not." | |||
end | |||
|
|||
def test_allows_sqlite3_rollback_on_invalid_column_type | |||
if current_adapter?(:SQLite3Adapter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put this if outside the test
f178ace
to
1e6610f
Compare
invalid column type /activerecord/lib/active_record/connection_adapters /abstract/schema_definitions.rb:306 type = type.to_sym Changed to the following to handle nil case: type = type.to_sym if type Added regression test for this case: /activerecord/test/cases/migration_test.rb:554 if current_adapter?(:SQLite3Adapter) def test_allows_sqlite3_rollback_on_invalid_column_type Person.connection.create_table :something, force: true do |t| t.column :number, :integer t.column :name, :string t.column :foo, :bar end assert Person.connection.column_exists?(:something, :foo) assert_nothing_raised { Person.connection.remove_column :something, :foo, :bar } assert !Person.connection.column_exists?(:something, :foo) assert Person.connection.column_exists?(:something, :name) assert Person.connection.column_exists?(:something, :number) ensure Person.connection.drop_table :something, if_exists: true end end
1e6610f
to
906ff07
Compare
@rafaelfranca Made your changes. Test now in new if block at activerecord/test/cases/migration_test.rb:554: if current_adapter?(:SQLite3Adapter)
def test_allows_sqlite3_rollback_on_invalid_column_type
Person.connection.create_table :something, force: true do |t|
t.column :number, :integer
t.column :name, :string
t.column :foo, :bar
end
assert Person.connection.column_exists?(:something, :foo)
assert_nothing_raised { Person.connection.remove_column :something, :foo, :bar }
assert !Person.connection.column_exists?(:something, :foo)
assert Person.connection.column_exists?(:something, :name)
assert Person.connection.column_exists?(:something, :number)
ensure
Person.connection.drop_table :something, if_exists: true
end
end |
@rafaelfranca How do I deal with this conflict with base branch? Do I need to rebase and push again? |
I can fix it myself. |
Sqlite3 Migration Error Fixed (issue #26087)
Sqlite3 Migration Error Fixed (issue #26087)
Backported in 7938aab |
Summary
Fixed error in issue #26087
Other Information
Error seems to be coming from an undefined method error when 'type' = nil on line 306:
Changed to the following to handle nil casetype = type&.to_sym || :placeholderNow handles nil by passing it through without type error rather than assigning a placeholder on suggestion of @rafaelfranca:
Sqlite3 test suite runs with 0 errors and 3 skips (same as when run on unmodified code)