This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-14
Channels
- # ai (24)
- # announcements (36)
- # babashka (15)
- # babashka-sci-dev (8)
- # beginners (18)
- # biff (4)
- # calva (24)
- # cider (13)
- # clj-kondo (1)
- # clj-on-windows (2)
- # clojars (15)
- # clojure (120)
- # clojure-dev (13)
- # clojure-europe (69)
- # clojure-nl (1)
- # clojure-norway (8)
- # clojure-uk (2)
- # clojurescript (4)
- # core-logic (2)
- # cursive (6)
- # datomic (193)
- # dev-tooling (4)
- # emacs (1)
- # hyperfiddle (57)
- # lsp (56)
- # malli (11)
- # missionary (15)
- # nbb (61)
- # off-topic (8)
- # polylith (8)
- # practicalli (2)
- # proletarian (1)
- # reitit (3)
- # releases (2)
- # remote-jobs (1)
- # shadow-cljs (13)
- # spacemacs (1)
- # specter (2)
- # sql (17)
- # tools-deps (3)
- # vim (38)
How does one handle components that need to talk to a database, and end up being used in two different projects? Is this something to avoid or is it manageable? What happens when a component is changed, and migrations needs to run? What runs them? Then how are deployments of separate projects handled?
So, I've just started using polylith myself, and what I've opted for is abstracting database access into its own component
That is: I have a mysql
component, with some exposed functions that wrap some generic queries, and then lets say I have some family of things that access the Widget
table: I then make a widget
component, and expose functions that query that table behind the scenes (through the mysql
component).
Example functions would just be stuff like
(defn db [] (mysql/get-datasource-by-name :widget-db))
(defn find-by-id [id]
(mysql/query! (db)
{:select [:*] :from [:widgets] :where [:= :id id]}))
;; Note that my mysql/query! function expects a honey-map, I have raw versions exposed as well
And you would then access that in another component via
(widget/find-by-id 42)
Thanks for this, I can see how this pattern would insulate code from db changes a bit better. I do still wonder how people have handled deployments of multiple services that depend on a component that has breaking changes, and how migrations are handled
How to handle DDL changes to your database(s) and deploy your running application(s) can be tricky, whether you use Polylith or not. I think you need to execute the database upgrade script(s) before or after you deploy your affected project artefacts, depending on the options you have (whether the database change is breaking or not).
thanks, ye we've been thinking a long those lines