[erlang-questions] Strategies for updating Mnesia tables

Ulf Wiger (TN/EAB) <>
Fri May 9 20:22:54 CEST 2008


Alexander Lamb skrev:
> 
> Le 9 mai 08 à 17:42, Ulf Wiger (TN/EAB) a écrit :
> 
>>
>> If you use records, you can write
>>
>>  #profiles{key = {'_','_','_'},
>>            system_name = System_Name,
>>            production_type = Production_Type,
>>            _ = '_'}
>>
>> Remember to load a new version of the module at the
>> same time as you convert the table.
>>
> Not quite certain what you mean. I do use records:

I'm sorry. I should have been more clear.

> To define the table I used:
> 
> -record(profiles, {full_profile, system_name, production_type, 
> timestamp, features, security_level}).
> 
> So if I understand correctly, I can do:
> 
> R = #profiles{full_profile = {'_','_','_'} , system_name = System_Name, 
> production_type = Production_Type, _ = '_' },
> F = fun() -> mnesia:match_object(profiles,R,read) end,
> 
> Or am I totally wrong?

Yes. What I was referring to was that your code relies on
a compile-time definition of records, and the syntax
above will be expanded to the pattern that you had
initially (remember that records are just syntactic sugar).
If you follow something like this sequence:

1. suspend your processes (sys:suspend(Pid))
2. load new versions of the modules that depend on the
    record definition
3. Transform the mnesia table
4. Let your processes continue (sys:resume(Pid))

Then, your wildcard syntax will work, and be consistent with
the representation in the mnesia table.

My other alternative retrieves the record information from
mnesia and will always work, but comes with a runtime
penalty.

BR,
Ulf W



More information about the erlang-questions mailing list