igorkasyanchuk / rails_db

Rails Database Viewer and SQL Query Runner
https://www.railsjazz.com/
MIT License
1.46k stars 111 forks source link

Is rails (gem) a necessary dependency? #126

Open nimmolo opened 2 years ago

nimmolo commented 2 years ago

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")
igorkasyanchuk commented 2 years ago

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

nimmolo commented 2 years ago

Okay. I'll try it!

nimmolo commented 2 years ago

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:

igorkasyanchuk commented 2 years ago

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

nimmolo commented 2 years ago

I will try that and report back.

nimmolo commented 2 years ago

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. 🙂

nimmolo commented 1 year ago

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.