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

Add Sequel preliminary support #229

Closed

Conversation

ardecvz
Copy link

@ardecvz ardecvz commented Mar 3, 2023

Hi, Vladimir!

What is the purpose of this pull request?

Add Sequel preliminary support.

It's an important feature for the Sequel ecosystem as, AFAIK, there's no model change trackers at all.

Fixes #28

What changes did you make? (overview)

It supports:

  • Whole Logidze model API for Sequel::Model
  • Whole Logidze scope API for Sequel::Dataset
  • Generators
  • Database specific top-level manipulations (Logidze.with_responsible, Logidze.without_logging)
  • Decoupled Logidze internal code from Active Record

Preliminary support means that although Active Record is decoupled already, it's still a hard dependency for the gemspec in order to minimize any possible breaks.
However, there should be no breaking changes for the current users.

Moreover, it removes:

  • Model method pollution with private Logidze methods
    It's hidden now in implementation adapters, only public API is included to models.
  • ignores_log_data global model pollution
    The method was included to all ActiveRecord::Base models; it's included only with has_logidze now.
    It's somewhat breaking change but it seems unlikely that someone uses a Logidze method on models without Logidze included.
  • log_version possible breakage with null log_data (for example, no version at some range)
    It returns nil now.

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

Fun fact: a really crude version of this code is saved one real world project with Sequel in 2020
(manually applied triggers and Logidze::History).

You know, an application-independent tracker rules! Thank you!

Checklist

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

Copy link
Owner

@palkan palkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work!

Left just a few minor comments.

extend Logidze::Meta
require "logidze/adapter/base"
require "logidze/adapter/active_record"
require "logidze/adapter/sequel"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we check for defined?(::Sequel) here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's safe to reference Sequel there as within the file we call Sequel inside method calls only.
However, it's always better to reduce allocated classes so indeed we should conditionally load.

require "logidze/meta"

extend Logidze::Meta
require "logidze/adapter/base"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "adapter" name is too generic; what about "database_adapter"? Or "connection_adapters" like in Active Record.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's stick with the Rails naming.

@@ -190,6 +194,28 @@ bundle exec rails destroy logidze:model Post

**IMPORTANT**: If you use non-UTC time zone for Active Record (`config.active_record.default_timezone`), you MUST always infer log timestamps from a timestamp column (e.g., when back-filling data); otherwise, you may end up with inconsistent logs ([#199](https://github.com/palkan/logidze/issues/199)). In general, we recommend using UTC as the database time unless there is a very strong reason not to.

### Sequel support

All mentioned generators also optionally support Sequel.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention here that the current Sequel support is more like "Sequel within Rails" support, since we still re-use a lot of Rails features. Splitting the library to work with pure Sequel (and without any Rails stuff) will be a next step (some day in the future).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll mention the limitations, thanks.

By the way, Sequel support does not need Rails extensively - we use it for JSON encode / decode only.
Of course, Sequel offers the same facilities to solve this problem too.
Maybe, fully separate modes are nearer than it looks ;)

@snacks02 snacks02 mentioned this pull request Oct 26, 2023
3 tasks
@ardecvz
Copy link
Author

ardecvz commented Oct 30, 2023

Closed in favor of #242

@ardecvz ardecvz closed this Oct 30, 2023
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.

Sequel support
2 participants