ZennerIoT / ex_audit

Ecto auditing library that transparently tracks changes and can revert them.
MIT License
367 stars 108 forks source link

A way to use the original Repo #33

Open jfrolich opened 4 years ago

jfrolich commented 4 years ago

It would be great if we can use the modified Repo of ex_audit as a separate module that calls the original Repo, so it will not completely replace the Repo, something like VersionedRepo. If parts of the app are potentially versioned (for instance a CMS), and other parts are not (the user-facing app), as in our case, I'd like to not have the performance impact of versioning on the user-facing app when I know versioning is not involved there.

narrowtux commented 4 years ago

You can simply make 2 repo modules, one with use ExAudit.Repo and the other with use Ecto.Repo.

However, beware that each repo has their own connection pool

jfrolich commented 4 years ago

Yeah it's not as simple as that, as they have their own connection pool, configuration and migrations etc.

narrowtux commented 4 years ago

your secondary repo doesn't have to have migrations, and the config to both repos can be the same (even coming from the same variable in config.exs).

I agree, a seperate connection pool might be a problem.

You can alternatively call ExAudit.Schema.insert, etc like this:

ExAudit.Schema.insert(MyRepo, MyRepo.get_dynamic_repo(), my_changeset, [])

ExAudit's wrapper around Ecto.Repo does nothing else really.

narrowtux commented 4 years ago

I'll consider defining a few important functions like insert, update, delete, history and rollback in the ExAudit module so it can be used without modifying the repo.

jfrolich commented 4 years ago

Yes that would be great. I agree it's definitely a solution to have a separate Repo, but there are trade-offs and it would be great to have an explicit API to ExAudit that doesn't involve taking over the Repo module.