Fork me on GitHub
#datahike
<
2022-04-11
>
Serafeim Papastefanos10:04:24

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

timo11:04:48

Does this help you?

Serafeim Papastefanos10:04:44

also is there a a concept similar to "migrations" in datahike ? what i'd do if my schema changes ?

timo11:04:21

There are solutions out there for migrations. I guess the main thing wrt migrations is idempotence, right? Maybe @UB95JRKM3 has a good answer?

timo11:04:20

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.

Serafeim Papastefanos05:04:31

thanks timo for the answers

kkuehne07:04:49

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.

Serafeim Papastefanos07:04:02

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

kkuehne07:04:45

Yes, that's right. Changing things like schema names is not so easy on the index level and we don't have aliases yet.

kkuehne07:04:21

And the change of value types and cardinality is also not so straightforward.

Serafeim Papastefanos07:04:28

yes i understand that's nice to know so i can understand the consequences

Björn Ebbinghaus10:04:23

@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.

🚀 1
Serafeim Papastefanos10:04:08

thank you so this does the migration automatically ?

Björn Ebbinghaus10:04:15

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.

1
Serafeim Papastefanos10:04:54

very interestingg thank you!