kit-clj / kit

Lightweight, modular framework for scalable web development in Clojure
https://kit-clj.github.io/
MIT License
463 stars 43 forks source link

Could a Datomic profile be interesting to have? #131

Open VictorVSa opened 4 months ago

VictorVSa commented 4 months ago

I recently integrated a Datomic database (both dev/file version and with PostgreSQL) in a kit project, and I found it extremely interesting and exciting. I was wondering if it would be interesting to have a profile that adds the necessary bits for having Datomic ready to use, including a migration tool, I used https://github.com/gethop-dev/stork for example. I can try to make the profile and contribute!

yogthos commented 4 months ago

A contribution for Datomic would be very much welcome, it might be worth taking a look at making it a module instead of a profile. I generally prefer adding functionality via modules since they can be instantiated after project creation meaning you don't need to know what functionality you'll need up front when making the initial project.

The modules repo is located here https://github.com/kit-clj/modules

gerdint commented 4 months ago

I would love to have an easy way to hook in Datomic, especially as a module.

VictorVSa commented 4 months ago

@yogthos @gerdint I have 2 approaches for Datomic support, please check the diffs and let me know which one follows the philosophy best, then I'll open the MR in the modules repo:


With transactor process management: Datomic can be deployed in many ways, so most of it should be done outside the lifecycle of the system in Kit, but it is a bit annoying having to manually start the transactor for development (that uses file DB) every time. This branch includes starting a dev transactor with defaults taken from the Getting started section of Datomic Pro. The user could just provide a DATOMIC_PATH env variable after following the instructions there and it works.

It includes a Thread/sleep because usually you can't connect to the transactor right after spawning the process, it will fail and retry, but it can be, because it happened to me, that the retry timeout is too short and you never end up connecting to the transactor, being left with a very polluted repl full of errors. The transactor has a healthcheck endpoint, but for that you have to edit the config file, which is an extra step for the user and not very beginner friendly, probably.

https://github.com/kit-clj/modules/compare/master...VictorVSa:modules:datomic-with-transactor?expand=1


Without transactor: Much simpler, it only cares about the DB URI to know where to connect and that's it.

https://github.com/kit-clj/modules/compare/master...VictorVSa:modules:datomic-without-transactor?expand=1

Thanks!

yogthos commented 4 months ago

I wonder if a bb task might be a better place for starting the transactor since it's not actually part of the app and it's only used for dev.

VictorVSa commented 4 months ago

That might need creating a scripts folder and call the scripts from the bb.edn like how rewrite-clj does it maybe? The approach without transactor can be the start, and if you like the idea of having a scripts folder that can be extended by the user at will, then I can create a script for the transactor, + support for datomic migrations

VictorVSa commented 4 months ago

Well, I'm assuming including that as a base feature of kit-clj, it could also be a documentation tutorial on how to add such a script instead

yogthos commented 4 months ago

Adding scripts folder by default might be the way to go, there's already build.clj script. So that could be moved into scripts, and then other scripts can be populated there as well via modules. That should be a relatively small change for the base template.

So, let's go with the version without the transactor then, and we can make a follow up issue to update the template and then add a script for starting the transactor for the module.