How to add a column to all connected nodes - mnesia table

224 views Asked by At

I am trying to add new column to an existing mnesia table. For that, I use following code.

test()->

Transformer =
  fun(X)-> % when is_record(X, user) -> %previous users
      #userss{name = X#user.name,
           age = X#user.age,
           email = X#user.email,
          year = 1990}
end,
AF = mnesia:transform_table(user, Transformer,record_info(fields, userss),userss),

 mnesia:sync_transaction(AF).

Two records I have

-record(user,{name,age,email}).
-record(users,{name,age,email,year}).

I want to update all connected node's tables. But it fails.

{aborted,{badarg,{aborted,{"Bad transform function",user,
                           #Fun<test.2.61379004>,'[email protected]',
                           {badfun,#Fun<test.2.61379004>}}},
                 [],infinity,mnesia}}

What is the problem here?

1

There are 1 answers

1
legoscia On BEST ANSWER

The problem is that an anonymous function can only be called on nodes where the module that defines it is loaded. I guess you loaded the module containing the test function only on one node in the cluster - you need to load it on all nodes for this to work. You can use the nl command ("network load") instead of l in the Erlang shell for that:

nl(my_module).

nl and other commands are described here.