-
Notifications
You must be signed in to change notification settings - Fork 22
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
Support for Active Record 5 #4
Conversation
Signed-off-by: Alex Coles <alex@alexbcoles.com>
Signed-off-by: Alex Coles <alex@alexbcoles.com>
Signed-off-by: Alex Coles <alex@alexbcoles.com>
Signed-off-by: Alex Coles <alex@alexbcoles.com>
@myabc Thanks for working on this! Since you marked it as Work In Progress I'll ignore it for now until you say it's ready. BTW I presume you're using the soon-to-be-released schema_plus_core 2.0.0 that @boazy created in SchemaPlus/schema_plus_core/pull/14 ? |
@ronen I have specs passing locally for MySQL; PostgreSQL. SQLite3 still needs some work, hence the PR title (It's probably the RDBMS I'm least familiar with).
Having this in my gem 'schema_plus_core', github: 'boazy/schema_plus_core',
branch: 'activerecord-5.0' I'm just trying to get the same working on Travis. |
@@ -37,7 +37,7 @@ def before(env) | |||
end | |||
|
|||
it "does not fail when reverting" do | |||
migration = Class.new ::ActiveRecord::Migration do | |||
migration = Class.new ::ActiveRecord::Migration[5.0] do |
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.
this allows the spec to pass, but is probably not the right solution:
env.options[:index] = { name: 'whatever' } if enabled_middleware(AddIndexBefore, env)
(in this case, the call to enabled_middleware
always returns false)
I need to better understand what the desired behaviour should be.
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.
Strange that enabled_middleware
always returns false. Are you sure? (Actually it should return either a class or nil
. See spec/support/enableable.rb
The intent of the spec is to make sure that the middleware doesn't cause a :down
migration to fail; I probably introduced this test to fix a bug. In particular, it should exercise the code in lib/schema_plus/indexes/active_record/migration/command_recorder.rb
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.
Strange that enabled_middleware always returns false. Are you sure? (Actually it should return either a class or nil. See spec/support/enableable.rb
Sorry, I had meant falsey (i.e. nil
), not false
.
(in this case, the call to enabled_middleware always returns false)
This statement was actually incorrect. I took a fresh look at it this morning. All appending [5.0]
to ::ActiveRecord::Migration
does is fix a deprecation warning.
@ronen Do you have a standard way of telling Travis to use a different upstream branch. I had considered configuring |
3f2d201
to
7f02db6
Compare
1 similar comment
The thing you did with Gemfile.local ought to work I think... but in any case it's moot since I've just released schema_plus_core 2.0.0 |
7f02db6
to
95d51a0
Compare
Signed-off-by: Alex Coles <alex@alexbcoles.com>
Currently the `Result` returned includes auto-generated indexes e.g. `sqlite_autoindex_ar_internal_metadata_1` for which the `sql` value will always be `nil`. Signed-off-by: Alex Coles <alex@alexbcoles.com>
In these cases, `#tables` is actually the appropriate method. This reverts commit e543c18.
f0b08df
to
02283eb
Compare
@@ -8,7 +8,7 @@ def after(env) | |||
indexes = Hash[env.index_definitions.map{ |d| [d.name, d] }] | |||
|
|||
env.connection.exec_query("SELECT name, sql FROM sqlite_master WHERE type = 'index'").map do |row| | |||
if (desc_columns = row['sql'].scan(/['"`]?(\w+)['"`]? DESC\b/).flatten).any? | |||
if row['sql'] && (desc_columns = row['sql'].scan(/['"`]?(\w+)['"`]? DESC\b/).flatten).any? |
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.
@ronen I'm not completely sure why the query returns auto-generated indexes here.
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.
I'm OK with adding the guard if the tests show it's needed.
@ronen I think this is now ready for an initial review. |
@@ -5,11 +5,11 @@ | |||
--- | |||
sudo: false | |||
rvm: | |||
- 2.1.5 | |||
- 2.3.0 |
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.
May as well use 2.3.1 , since that's the current officially stable release.
@myabc thanks again for working on this! Duplicating my own comment in SchemaPlus/schema_plus_foreign_keys#11 (comment) ... My only other overall question is, as AR keeps increasing its support for indexes, what (if any) functionality of schema_plus_indexes is now natively supported by AR? Though potentially with different syntax? (Revealing my ignorance about AR 5, I don't know what has been added. Part of why I've been so behind the ball on the AR 5 upgrades to SchemaPlus is that I'm not currently using rails much in my day jobs.) |
Signed-off-by: Alex Coles <alex@alexbcoles.com>
Signed-off-by: Alex Coles <alex@alexbcoles.com>
Is this PR ready to be merged? |
Sorry for the delay. @myabc thanks for the update! I've merged and adjusted the dependencies because this actually still works for AR 4.2 and 5.0. Since there are no new features or breaking changes, this is just a patch release :) I've released v0.2.4 |
activerecord-5.0
branch rather thanmaster
. PR is here for discussion/tracking (unlike Full support for AR5 schema_plus_core#14 though, it might not be so difficult to support AR 4.2 + 5.0 in the same project).