Fork me on GitHub
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: but how would i do it in a real project


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 ?


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.

Serafeim Papastefanos05:04:31

thanks timo for the answers


Hi @U03BMTULBSL, so you mean something like or 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 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


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


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: It uses, 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"
  (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.

Serafeim Papastefanos10:04:54

very interestingg thank you!