Skip to content

Instantly share code, notes, and snippets.

@ngerakines
Created December 30, 2009 19:45
Show Gist options
  • Select an option

  • Save ngerakines/266324 to your computer and use it in GitHub Desktop.

Select an option

Save ngerakines/266324 to your computer and use it in GitHub Desktop.
%% Store username as binary
mnesia:transform_table(user, fun({user, Id, Name, Streak, Current, Last, Imp}) -> {user, Id, list_to_binary(Name), Streak, Current, Last, Imp} end, [id, username, longest_streak, current_streak, last_updated, importance], user).
%% Reference username and projects as binary
TransFun = fun({day, Id, Username, Date, Projects}) ->
{day, {list_to_binary(Username), Date}, list_to_binary(Username), Date, lists:usort([ list_to_binary(P) || P <- Projects])}
end.
[ begin [Record] = mnesia:dirty_read(day, Key), mnesia:dirty_delete_object(day, Record), mnesia:dirty_write(day, TransFun(Record)) end || Key <- mnesia:dirty_all_keys(day)].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment