What's the simplest way to update mnesia schema?
Asked Answered
L

1

7

For example, I saved {id, name} in mnesia and want to update to {id, name, age}, do I have to call transform_table every time I change schema?

Lenwood answered 14/4, 2013 at 10:51 Comment(5)
What else would you expect to be able to do? You have to change the table through some function call, right? transform_table/{3-4} does give you some options to change the approach to adjusting the schema though.Unlucky
yes. you have to transform that tableAirstrip
Does transform_table take very long time when mnesia table grows very large? If so, it will affect the benefit of hot-code upgrades.If via another solution, keep track of record version and only upgrade the records which are loaded, could cause the upgrade code tedious and error-prone.Lenwood
Welcome to the world of big-data, where moving through data and upgrading them takes too much time. You need to version your data eventually and support multiple versions. There is no way around that in practice, however irritating that is. Transformations on data are only viable when data are rather small in size.Trichology
When I use mnesia in production, always add an options::proplists() column to each table :)Delbert
F
3

The simplest way is to delete the table and recreate it. If you need to keep the data in the table, mnesia:transform_table is the way to go.

Flare answered 23/12, 2013 at 13:8 Comment(3)
Don't you think deleting and recreating the tables might break the production system.Steno
In most cases, yes, unless you make it not access the database while you're recreating the tables. transform_table avoids such problems.Flare
Yep, transform_table is the decent approach to tackle such problem. I was just giving a wider perspective to the answer.Steno

© 2022 - 2024 — McMap. All rights reserved.