Skip to content
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

Merged
merged 10 commits into from
Aug 24, 2016
Merged

Conversation

myabc
Copy link
Contributor

@myabc myabc commented Aug 14, 2016

  • You probably want to merge this into the activerecord-5.0 branch rather than master. 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).

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>
@ronen
Copy link
Member

ronen commented Aug 15, 2016

@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 ?

@myabc myabc changed the title Activerecord 5.0 Full support for Active Record 5 Aug 15, 2016
@myabc myabc changed the title Full support for Active Record 5 Support for Active Record 5 Aug 15, 2016
@myabc
Copy link
Contributor Author

myabc commented Aug 15, 2016

@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).

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#14 ?

Having this in my Gemfile.local works fine:

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
Copy link
Contributor Author

@myabc myabc Aug 15, 2016

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.

Copy link
Member

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

Copy link
Contributor Author

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.

@myabc
Copy link
Contributor Author

myabc commented Aug 15, 2016

@ronen Do you have a standard way of telling Travis to use a different upstream branch. I had considered configuring .travis.yml to write out a `Gemfile.local, but I know it's auto-generated, thus would be overriden on the first matrix run.

@myabc myabc force-pushed the activerecord-5.0 branch 2 times, most recently from 3f2d201 to 7f02db6 Compare August 15, 2016 19:25
@coveralls
Copy link

Coverage Status

Coverage decreased (-3.9%) to 96.094% when pulling 7f02db6 on myabc:activerecord-5.0 into 8fe9ae7 on SchemaPlus:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-3.9%) to 96.094% when pulling 7f02db6 on myabc:activerecord-5.0 into 8fe9ae7 on SchemaPlus:master.

@ronen
Copy link
Member

ronen commented Aug 15, 2016

@myabc

Do you have a standard way of telling Travis to use a different upstream branch.

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

Signed-off-by: Alex Coles <alex@alexbcoles.com>
@coveralls
Copy link

coveralls commented Aug 16, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 53e4c45 on myabc:activerecord-5.0 into 8fe9ae7 on SchemaPlus:master.

@coveralls
Copy link

coveralls commented Aug 16, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling f0b08df on myabc:activerecord-5.0 into 8fe9ae7 on SchemaPlus:master.

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.
@@ -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?
Copy link
Contributor Author

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.

Copy link
Member

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.

@myabc
Copy link
Contributor Author

myabc commented Aug 16, 2016

@ronen I think this is now ready for an initial review.

@coveralls
Copy link

coveralls commented Aug 16, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 02283eb on myabc:activerecord-5.0 into 8fe9ae7 on SchemaPlus:master.

@@ -5,11 +5,11 @@
---
sudo: false
rvm:
- 2.1.5
- 2.3.0
Copy link
Member

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.

@ronen
Copy link
Member

ronen commented Aug 17, 2016

@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>
@coveralls
Copy link

coveralls commented Aug 17, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 1b4cfee on myabc:activerecord-5.0 into 8fe9ae7 on SchemaPlus:master.

Signed-off-by: Alex Coles <alex@alexbcoles.com>
@coveralls
Copy link

coveralls commented Aug 18, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 0c9d021 on myabc:activerecord-5.0 into 8fe9ae7 on SchemaPlus:master.

@boazy
Copy link
Member

boazy commented Aug 21, 2016

Is this PR ready to be merged?
Once it gets released, schema_plus_columns could be released as well.
Next comes schema_validations, but seems to take a little bit more work.

@ronen ronen merged commit ff0a3b6 into SchemaPlus:master Aug 24, 2016
@ronen
Copy link
Member

ronen commented Aug 24, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants