This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-11
Channels
- # announcements (3)
- # asami (4)
- # babashka (79)
- # babashka-sci-dev (47)
- # beginners (97)
- # biff (12)
- # calva (7)
- # clj-commons (3)
- # clj-kondo (22)
- # clj-on-windows (13)
- # cljdoc (31)
- # cljfx (2)
- # cljs-dev (1)
- # clojure (85)
- # clojure-austin (4)
- # clojure-dev (12)
- # clojure-europe (15)
- # clojure-italy (8)
- # clojure-nl (4)
- # clojure-uk (4)
- # community-development (19)
- # conjure (3)
- # core-typed (40)
- # cursive (9)
- # datahike (21)
- # datomic (1)
- # emacs (7)
- # exercism (2)
- # graalvm (20)
- # graphql (1)
- # honeysql (16)
- # jobs (1)
- # malli (2)
- # off-topic (3)
- # pathom (28)
- # pedestal (3)
- # polylith (7)
- # reitit (14)
- # releases (1)
- # remote-jobs (1)
- # rewrite-clj (4)
- # shadow-cljs (21)
- # sql (21)
- # testing (8)
- # tools-deps (23)
- # vscode (8)
- # xtdb (38)
let's suppose i wanted to create a schema in datahike (or datomic) how would i do that ? i've seen the xample here: https://cljdoc.org/d/io.replikativ/datahike/0.4.1490/doc/readme but how would i do it in a real project
How about this? https://github.com/replikativ/datahike/blob/main/examples/basic/src/examples/schema.clj
yes thank you !
also is there a a concept similar to "migrations" in datahike ? what i'd do if my schema changes ?
There are solutions out there for migrations. I guess the main thing wrt migrations is idempotence, right? Maybe @UB95JRKM3 has a good answer?
2018 though. there is wanderung as a project under the replikativ org on github but I don't know the current state of it. It is being worked on.
thanks timo for the answers
i also found this very interesting doc: https://github.com/replikativ/datahike/blob/main/doc/schema.md
Hi @U03BMTULBSL, so you mean something like https://github.com/avescodes/conformity or https://github.com/yogthos/migratus? I tried to create something based on conformity but it was not so easy since we have some internal differences to Datomic, so I only used the ideas of norms in our projects to ensure certain schemas to be in the database and to be applied. You can find an example https://github.com/lambdaforge/mtool-web/blob/main/src/clj/lf/administration/migrations.clj. I have some plans to move that into a separate library.
hey @UB95JRKM3 thanks for the tips; the docs of datahike mention that migrations aren't supported... you can only add fields and if you want to do more changes to the fields you need to create a new database and move your data
Yes, that's right. Changing things like schema names is not so easy on the index level and we don't have aliases yet.
yes i understand that's nice to know so i can understand the consequences
@U03BMTULBSL I have written some code that handles that for me. You can have a look at it here: https://github.com/hhucn/decide3/blob/master/src/main/decide/server_components/db/migrate.clj It uses https://github.com/weavejester/ragtime, and it handles schema migration as well as more complex migrations, that restructure data.
thank you so this does the migration automatically ?
The upsert!
function looks at the current schema.
I calculate the difference of the current and the new schema.
If there is a difference, I transact that difference.
Then there is the migrate-data!
function takes a seq of migrations like:
{:id "Rename :db/txUser to :tx/by"
:up
(fn [db]
(for [[tx user] (d/q '[:find ?e ?user :where [?e :db/txUser ?user]] db)]
[:db/add tx :tx/by user]))}
Which take a database and return a seq of transaction statements.
Those get transacted into the database and the id of the transaction gets stored in the database in the singleton ::applied-migrations
However, I have never really cleaned up the code, so you should be careful with that.very interestingg thank you!