+++ /dev/null
-% Module de création de la base de données euphorik.
-% @author G.Burri
-
--module(euphorik_bd).\r
--export([\r
- create/0,\r
- create_tables/0,\r
- vers_version/1,\r
- peupler/0\r
- ]).\r
-\r
--include("../include/euphorik_bd.hrl").\r
-
-
-% Instructions pour créer une nouvelle base :
-% $erl -sname yaws -mnesia dir '"/projets/euphorik/BD"'
-% voir doc/installation.txt
-% >l(euphorik_bd).
-% >euphorik_bd:create().\r
-create() ->\r
- mnesia:stop(),\r
- mnesia:delete_schema([node()]),\r
- mnesia:create_schema([node()]), % nécessaire pour les tables sur disc\r
- mnesia:start(),\r
- create_tables().
- \r
-
-create_tables() ->\r
- mnesia:create_table(counter, [\r
- {attributes, record_info(fields, counter)},\r
- {disc_copies, [node()]}\r
- ]),\r
- mnesia:create_table(minichat, [
- {attributes, record_info(fields, minichat)},
- {index, [auteur_id]},
- {disc_copies, [node()]}
- ]),\r
- mnesia:create_table(reponse_minichat, [\r
- {type, bag},\r
- {attributes, record_info(fields, reponse_minichat)},\r
- {index, [cible]},\r
- {disc_copies, [node()]}\r
- ]),\r
- mnesia:create_table(user, [\r
- {attributes, record_info(fields, user)},
- {index, [cookie, login]},\r
- {disc_copies, [node()]}\r
- ]),
- mnesia:create_table(ip_table, [
- {attributes, record_info(fields, ip_table)},
- {disc_copies, [node()]}
- ]),
- mnesia:create_table(troll, [
- {attributes, record_info(fields, troll)},
- {disc_copies, [node()]}
- ]).
-
-
-vers_version(2) ->
- mnesia:transform_table(
- user,
- fun({user, Id, Cookie, Pseudo, Date_creation, Date_derniere_connexion, Css}) ->
- {user, Id, Cookie, Pseudo, "", "", "", Date_creation, Date_derniere_connexion, Css}
- end,
- record_info(fields, user),
- user
- );
-vers_version(3) ->
- mnesia:transform_table(
- user,
- fun({user, Id, Cookie, Pseudo, Login, Password, Email, Date_creation, Date_derniere_connexion, Css}) ->
- {user, Id, Cookie, Pseudo, Login, Password, Email, Date_creation, Date_derniere_connexion, Css, 0}
- end,
- record_info(fields, user),
- user
- );
-vers_version(4) ->
- mnesia:transform_table(
- user,
- fun({user, Id, Cookie, Pseudo, Login, Password, Email, Date_creation, Date_derniere_connexion, Css, Indice_flood}) ->
- {user, Id, Cookie, Pseudo, Login, Password, Email, Date_creation, Date_derniere_connexion, Css, Indice_flood, []}
- end,
- record_info(fields, user),
- user
- );
-% Ajout du numéro de page de la conv principale
-vers_version(5) ->
- mnesia:transform_table(
- user,
- fun({user, Id, Cookie, Pseudo, Login, Password, Email, Date_creation, Date_derniere_connexion, Css, Indice_flood, Conversations}) ->
- {user, Id, Cookie, Pseudo, Login, Password, Email, Date_creation, Date_derniere_connexion, Css, Indice_flood, 1, Conversations}
- end,
- record_info(fields, user),
- user
- );
-% Ajout le format d'affichage des pseudos
-vers_version(6) ->
- mnesia:transform_table(
- user,
- fun({user, Id, Cookie, Pseudo, Login, Password, Email, Date_creation, Date_derniere_connexion, Css, Indice_flood, Page_Principale, Conversations}) ->
- {user, Id, Cookie, Pseudo, Login, Password, Email, Date_creation, Date_derniere_connexion, Css, nick, Indice_flood, Page_Principale, Conversations}
- end,
- record_info(fields, user),
- user
- );
-% Ajout de la table 'ip_table'
-% Ajout du statut 'ek_master' pour les users
-vers_version(7) ->
- mnesia:transform_table(
- user,
- fun({user, Id, Cookie, Pseudo, Login, Password, Email, Date_creation, Date_derniere_connexion, Css, Nick_format, Indice_flood, Page_Principale, Conversations}) ->
- {user, Id, Cookie, Pseudo, Login, Password, Email, Date_creation, Date_derniere_connexion, Css, Nick_format, Indice_flood, Page_Principale, Conversations, false, undefined}
- end,
- record_info(fields, user),
- user
- ),
- mnesia:create_table(ip_table, [
- {attributes, record_info(fields, ip_table)},
- {disc_copies, [node()]}
- ]),
- mnesia:create_table(troll, [
- {attributes, record_info(fields, troll)},
- {disc_copies, [node()]}
- ]);
-vers_version(8) ->
- mnesia:transform_table(
- ip_table,
- fun() -> null end,
- record_info(fields, ip_table),
- ip_table
- ).
-
-
-
-% exemple de peuplage de la BD, utilisé pour les tests
-peupler() ->
- mnesia:transaction(
- fun() ->
- mnesia:write({minichat, now(), "Pierre", "Salut tout le monde"}),
- mnesia:write({minichat, now(), "Paul", "Salut à toi !"})
- end
- ).