Fork me on GitHub
#datascript
<
2023-01-20
>
Jonor20:01:10

How can I change/alter/update the database schema in a DataScript database? I saw a tip about replacing the :schema entry, but it doesn't work, there seem to be more about it (there is an :rschema entry also which is not updated?).

Niki21:01:58

Changing schema is not really supported

Niki21:01:21

Although you can assoc new schema and recalc re-schema, should work

Jonor21:01:39

Thanks. Is there a way to trigger automatic recalc of rschema or I have to do it manually? Maybe it is easer to reload the data in a new DB?

Jonor23:01:29

I re-built the :rschema and it works when adding data, I guess that is the one actually used. I was just thinking along possibilities to allow a user to add data and custom types successively.

Niki18:01:18

> Maybe it is easer to reload the data in a new DB? Depends on how much data :) But basically the reason why there’s no official API for schema migrations is because it’s hard to ensure constraints between schemas. E.g. if you change multi-arity to single-arity, someone has to guarantee that there are no multi-arity values left in the database

Jonor23:01:15

I see that a schema change has to be accompanied by a transaction that makes the database consistent with the constraints, so in practice it is a transaction including the schema into a new valid state. It is an interesting problem how to generate the necessary transaction for a schema change.

Jonor17:02:24

Docs describe a trial and error process to change data until computer says yes. Maybe some tool could automatically suggest a destructive or not transformation of the data based on the schema change. "Attempting a schema change that violates an invariant will cause the transaction to abort with an exception. To enable such change, first change your data so the invariant you want becomes true."