Database / Mnesia basics Interview questions
How do you migrate a Mnesia record definition when its fields change?
Simply changing a -record definition in your code and recompiling doesn't retroactively update
records already stored in a Mnesia table — existing rows keep whatever shape they were written with,
which will mismatch the new record definition the next time your code tries to read them.
%% old: -record(person, {id, name, age}). %% new: -record(person, {id, name, age, email}). mnesia:transform_table(person, fun(P) -> P#person{email = undefined} end, record_info(fields, person)).
The standard fix is mnesia:transform_table/3: it walks every existing record in the table,
applies a transformation function you provide to reshape each one into the new format, and updates the table's
schema to match, all while the table can remain usable. This must be run once as a deliberate migration step
whenever a record's field list changes, not something that happens automatically just from recompiling.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
