<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>You should absolutely update all existing records in the table. You do this with</div><div><br></div><div>mnesia:transform_table(Tab, Fun, NewAttributeList)</div><div><br></div><div>Note that the manual says:</div><div><br></div><div>"<span class="code" style="font-family: Courier, monospace; font-weight: normal; color: rgb(0, 0, 0); font-size: medium; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">Fun</span><span style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none;"> is a function which takes a record of the old type and returns a transformed record of the new type. The </span><span class="code" style="font-family: Courier, monospace; font-weight: normal; color: rgb(0, 0, 0); font-size: medium; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">Fun</span><span style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none;"> argument can also be the atom </span><span class="code" style="font-family: Courier, monospace; font-weight: normal; color: rgb(0, 0, 0); font-size: medium; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">ignore</span><span style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none;">, it indicates that only the meta data about the table will be updated. Usage of </span><span class="code" style="font-family: Courier, monospace; font-weight: normal; color: rgb(0, 0, 0); font-size: medium; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">ignore</span><span style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none;"> is not recommended but included as a possibility for the user do to his own transform."</span></div><div><br></div><div>The reason for the 'ignore' trick is that it is sometimes not feasible to transform the entire table within a transaction while user requests are held off waiting for the operation to complete. One can then instead transform the table definition and spawn a process that transforms one record at a time.</div><div><br></div><div>This would of course mean that any code that reads from the table must be prepared to get an old record, and transform it on the fly to the latest record format. This is not terribly difficult to accomplish*, but requires some forethought.</div><div><br></div><div>For various reasons like the above, it is a very good idea to have your own code access mnesia via a database API that *you* control. An alternative is to always use mnesia:activity/2 (even for dirty access), making it possible to introduce these workarounds in your own access module. That is, never use mnesia:transaction/1 - use mnesia:activity/2 instead.</div><div><br></div><div>* At least as long as you mainly read objects. If you are e.g. using QLC, it becomes a non-trivial task.</div><div><br></div><div>BR,</div><div>Ulf W</div><br><div><div>On 3 Jun 2013, at 08:01, <a href="mailto:yashgt@gmail.com">yashgt@gmail.com</a> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><p>If a record is defined as:</p><p>-record(shop, {item, quantity, cost}).</p><p>and several records are stored in an Mnesia table, and a few months later the structure is changed to :<br>-record(shop, {item, quantity, source, company, cost}).</p><p>Do we need to migrate ALL existing records in the DB to include the additional 2 elements in the tuple? I know that a record is actually a tuple. If we leave the existing records untouched, will the database get messed becaues of new records coming in with the new structure?</p><p>Thanks,<br>Yash</p>
_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>http://erlang.org/mailman/listinfo/erlang-questions<br></blockquote></div><br><div apple-content-edited="true">
<div><div>Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.</div><div><a href="http://feuerlabs.com">http://feuerlabs.com</a></div></div><div><br></div><br class="Apple-interchange-newline">
</div>
<br></body></html>