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?

raina77ow
  • 103,633
  • 15
  • 192
  • 229
Comet Liao
  • 295
  • 2
  • 13
  • 2
    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. – d11wtq Apr 14 '13 at 14:27
  • 1
    yes. you have to transform that table – Muzaaya Joshua Apr 15 '13 at 05:38
  • 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. – Comet Liao Apr 15 '13 at 15:05
  • 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. – I GIVE CRAP ANSWERS May 18 '13 at 09:10
  • 4
    When I use mnesia in production, always add an `options::proplists()` column to each table :) – shino Oct 29 '13 at 09:01

1 Answers1

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.

2240
  • 1,547
  • 2
  • 12
  • 30
legoscia
  • 39,593
  • 22
  • 116
  • 167
  • 2
    Don't you think deleting and recreating the tables might break the production system. – anuj pradhan Nov 03 '15 at 05:40
  • In most cases, yes, unless you make it not access the database while you're recreating the tables. `transform_table` avoids such problems. – legoscia Nov 03 '15 at 08:01
  • Yep, transform_table is the decent approach to tackle such problem. I was just giving a wider perspective to the answer. – anuj pradhan Nov 04 '15 at 05:51