logidze icon indicating copy to clipboard operation
logidze copied to clipboard

Add Sequel preliminary support

Open snacks02 opened this issue 2 years ago • 18 comments

Thanks for the amazing library!

Fixes #28.

What is the purpose of this pull request?

This is an attempt to get the original Sequel preliminary support PR merged.

What changes did you make? (overview)

Merged master from upstream, fixed conflicts, took the comments from the original PR into account.

Is there anything you'd like reviewers to focus on?

The original PR is a brilliant piece of work, so I just wanted it merged so I could use upstream Logidze for a project. Not sure if there's anything else to say. :)

Checklist

  • [x] I've added tests for this change
  • [x] I've added a Changelog entry
  • [x] I've updated a documentation (Readme)

^ All of this was already done.

snacks02 avatar Oct 26 '23 14:10 snacks02

@sanks02 Hello, thank you for your work and for advancing the agenda!

This feature is indeed important, especially since there isn't a record tracker within the Sequel ecosystem. We should certainly make a final push to make it into the gem.

There are just 2 things left to address:

  1. We overlooked this comment - https://github.com/palkan/logidze/pull/229#discussion_r1163280458 The term "adapter" is a bit too generic. Considering we might support other databases like MySQL in the near future, we should rename it.
  2. It might be a good idea to remove the strict dependency on ActiveSupport before the release (https://github.com/palkan/logidze/pull/229#discussion_r1169116900). We only employ it for JSON serialization / deserialization as seen here: https://github.com/palkan/logidze/pull/242/files#diff-fbdceda80b1b58da4bd608bbe7ee747e0d3569ecc991fbfcbd6688c02fc793ecR12-R32

The required steps would be:

  1. Use the JSON encoding / decoding features provided by Sequel: https://github.com/jeremyevans/sequel/blob/master/lib/sequel/core.rb#L169-L177
  2. Run tests and set up two demo apps, one with ActiveRecord and the other with Sequel only. So we can ensure nothing is broken without ActiveSupport.

@sanks02, would you be interested to help with these tasks? It would be a great help (also do not forget to add yourself to the contributors list in the README.md).

If you're busy, I'll hope to address these issues this week.

ardecvz avatar Oct 30 '23 17:10 ardecvz

@ardecvz Thanks for the heads up! It doesn't sound complicated, so I think I can do it.

snacks02 avatar Oct 30 '23 18:10 snacks02

I'm halfway through adding bundle exec rake spec:sequel that doesn't depend on ActiveRecord and ActiveSupport.

There is a problem with generators depending on ActiveRecord. I'm not sure how to remove this dependency, so I'll remove Sequel-specific code from generators and associated specs for now.

Later we can see what sequel-rails does, and try to do a similar thing to add the generators back. Does this sound good?

snacks02 avatar Nov 03 '23 12:11 snacks02

@ardecvz Would you mind helping me from this point?

snacks02 avatar Nov 08 '23 11:11 snacks02

Hi again! Sorry for the late reply, I missed the first notification.

Oh, you've found an interesting edge case! And we're so close to the proper merge.

According to Sequel's philosophy, you don't need generators - the authors recommend using your normal text editor environment.

So, your recent removal of generators is fine, but in this case, we need to prepare a separate, detailed guide on how to craft installation and model migrations as done in Sequel.

However, in my opinion, Logidze migrations are much harder to copy and paste manually without mistakes. And Evil Martians' gems are all about quick starts and usability, so I personally recommend keeping them.

Yes, we'll keep a dependency on Railties (and ActionPack, unfortunately), but we'll remove the redundant dependency on ActiveRecord.

On the other hand, Sequel is popular among minimal environments, so ActionPack may be overkill for them.

Also, I'm not aware of any lightweight alternatives to Rails generators (sequel-rails seems to rely on Railties).

It's a decision with drawbacks, so let's get @palkan to decide:

  1. Keep a dependency on Rails generators, accepting the extra ActionPack from Railties;
  2. Find a lightweight alternative to generators, potentially compromising the main gem's codebase;
  3. Remove generators for Sequel and create a detailed guide as intended by Sequel.

ardecvz avatar Nov 08 '23 11:11 ardecvz

I'm not aware of any lightweight alternatives to Rails generators

We can use plain Thor; that would, probably, require adding a standalone bin/logidze CLI to perform the installation, etc.

Remove generators for Sequel and create a detailed guide as intended by Sequel.

Another option is to add an application template via Ruby Bytes: https://github.com/palkan/rbytes

Basically, the same idea as using Thor but without dealing with CLIs, etc.

palkan avatar Nov 09 '23 16:11 palkan

It looks like Ruby Bytes does not support RSpec, which is used in this project.

snacks02 avatar Nov 14 '23 03:11 snacks02

@ardecvz I added the Sequel generators back.

My knowledge of Rails generators, Thor and Ruby Bytes is limited, so if you don't mind picking the PR up, I'd appreciate it.

The issues with the current generators are:

  • https://github.com/palkan/logidze/blob/caf7d9042d34bc1a4e289b3c4e32d6595646df5a/lib/generators/logidze/install/install_generator.rb#L95-L97
  • https://github.com/palkan/logidze/blob/caf7d9042d34bc1a4e289b3c4e32d6595646df5a/lib/generators/logidze/model/model_generator.rb#L10

snacks02 avatar Nov 14 '23 04:11 snacks02

It would be great to have this PR merged.

I think the easiest solution is to add the ActiveRecord/ActiveSupport dependency back (but keep all other fixes and mention the ActiveRecord/ActiveSupport dependency in README.md).

Or do you have any other suggestions/recommendations?

snacks02 avatar Jan 08 '24 10:01 snacks02

Yes, I'm with your plan - adding support gradually is the only path forward right now. Have we test the new version in both the ActiveRecord and Sequel dummy applications? If that is the case, I believe @palkan will cut a release shortly after the merge.

ardecvz avatar Jan 08 '24 13:01 ardecvz

And we should create an issue with future improvements - to keep a plan forward.

ardecvz avatar Jan 08 '24 13:01 ardecvz

Thanks. The branch is in a half-baked state right now. I'll fix it and let you know when it can be reviewed.

snacks02 avatar Jan 08 '24 14:01 snacks02

Should be ready for a review.

Suggestions from the original PR have been taken into account and small changes have been made to further separate Logidze from ActiveSupport.

I didn't finish adding a separate Sequel demo as it would be impossible to test if it works without ActiveRecord anyway, but I mentioned it in the newly created issue.

The difference between this and the original PR. I hope this helps. Let me know if anything else is needed. :)

snacks02 avatar Jan 18 '24 04:01 snacks02

Thanks @sanks02!

Please, take a look at the RuboCop offenses (look legit) and RSpec failures.

@ardecvz Waiting for your approval 🙂 (and the green CI, of course)

palkan avatar Jan 19 '24 02:01 palkan

Sorry about that, I may have accidentally tested bundle exec rake on a wrong branch. Should be fixed now.

snacks02 avatar Jan 19 '24 04:01 snacks02

diff.tar.gz

snacks02 avatar Jan 19 '24 04:01 snacks02

I've started using this in a real world application and it seems to work just fine

snacks02 avatar Feb 06 '24 10:02 snacks02

@sanks02 Thanks!

@ardecvz I'm still waiting for your pair of eyes 👀

palkan avatar Feb 06 '24 19:02 palkan