igorkasyanchuk / rails_db

Rails Database Viewer and SQL Query Runner

Home Page:https://www.railsjazz.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is rails (gem) a necessary dependency?

nimmolo opened this issue · comments

Hi - THANK YOU for this amazing gem. I hope you are okay, if you are in Ukraine. Don't worry about this issue too much.

We are updating a legacy Rails app to Rails 6, and we are thinking to remove ActionCable and ActiveStorage from the rails app.

It's still a Rails app, of course, but this means removing the gem rails from our Gemfile, and replacing it with the list of Rails gem dependencies, without Rails.

However — it can only build correctly if no other gem depends on Rails.

We use many gems, but the only gem we use that depends explicitly on gem rails is rails_db. So i'm wondering if maybe it would be possible to narrow down your gemspec to only depend on activemodel and activerecord for example (I don't actually know which parts of Rails the gem uses, other than these).

This is how we're changing our Gemfile:

# gem("rails", "~> 6.1")
# Or bundle the constituent gems. Just be sure no gems depend on Rails
# gem("actioncable", "~> 6.1")
gem("actioncontroller", "~> 6.1")
# gem("actionmailbox", "~> 6.1")
gem("actionmailer", "~> 6.1")
gem("actionpack", "~> 6.1")
gem("actiontext", "~> 6.1")
gem("actionview", "~> 6.1")
gem("activejob", "~> 6.1")
gem("activemodel", "~> 6.1")
gem("activerecord", "~> 6.1")
# gem("activestorage", "~> 6.1")
gem("activesupport", "~> 6.1")
gem("bundler")
gem("railties", "~> 6.1")
gem("sprockets-rails")

Hello, I'm okay with it if you can prepare a PR. I specs passed I can merge it.

Okay. I'll try it!

Hi Igor — Thanks. This my first time contributing to a gem. I'm not unfamiliar with Ruby, i've been working on a legacy rails app for a few years. Obviously the workflow for gems is different because they must work with different versions of other gems.

I forked the repo and just altered the Gemfile and rails_db.gemspec - When I run bundle install to regenerate the Gemfile.lock I'm getting an error:

An error occurred while installing mysql2 (0.3.20), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.20' --source 'https://rubygems.org/'` succeeds before bundling.

If I try installing that version of mysql2, it's not working yet... working on a fix for that.

I'd like to learn how to contribute to gems, so I want to figure this out. But if you want to try it locally, I'm only changing the above two files, commenting out the lines to require rails.

I believe these simple changes will work, because rails_db's other gem dependencies already require the Rails dependencies I believe rails_db will need, so they get included in Gemfile.lock anyway:

  • simple_form requires actionpack and activemodel
  • ransack requires activerecord and activesupport
  • kaminari requires activerecord, activesupport, and actionview
  • calxlsx_rails requires actionpack

Can you try to make it work with different version of mysql2 gem?

I will try that and report back.

Hi Igor — that problem was because my dev environment wasn't set up fully for gem development.

Branch is passing tests locally... hope to submit the PR soon. 🙂

Hi Igor - I hope you are well.

If you have had a chance to review the PR, please let me know if there is anything I can change.
It's working well for me locally.