grosser / cia

Central Internal Auditing: Audit model events like update/create/delete + attribute changes + grouped them by transaction, in normalized table layout for easy query access.
12 stars 18 forks source link

convert event and attribute_change models to mixins #19

Closed razumau closed 2 months ago

razumau commented 3 months ago

To work with multiple databases in Active Record (including sharding), models need to inherit from an abstract class layered between it and ActiveRecord::Base. We can’t know names of these classes in applications, so instead of loading a complete Event and AttributeChange models, we will now require app developers to create these models themselves.

See also a similar recent change in Arturo: https://github.com/zendesk/arturo/pull/133 and https://github.com/zendesk/arturo/pull/138.

razumau commented 2 months ago

Unfortunately, no, models have to have an abstract superclass (like in the examples in the multiple database guide).

The connects_to method, which handles connections, can only be called on abstract classes and on ActiveRecord::Base (and will raise an exception otherwise): https://github.com/rails/rails/blob/4fa56814f18fd3da49c83931fa773caa727d8096/activerecord/lib/active_record/connection_handling.rb#L81

It would definitely be simpler for us to mix in database connection details (instead of everything else), but it works like in that in Rails because connections are created and stored wherever this connects_to method is called (it’s not just “store this connection details for a future call”, it’s actually returning a list of connections). Because they don’t want to create too many connections, connection management is allowed only in a few places.

grosser commented 2 months ago

thx, makes sense :)

grosser commented 2 months ago

you are done here and this should be released as a major change right ?

razumau commented 2 months ago

you are done here and this should be released as a major change right ?

yes

grosser commented 2 months ago

FYI dropping ruby 2.6 and rails 4 too https://github.com/grosser/cia/pull/20 (mostly to avoid sqlite3 version hell)

grosser commented 2 months ago

1.0.0