1 % Module de création de la base de données euphorik.
12 -include("../include/euphorik_bd.hrl").
15 % Instructions pour créer une nouvelle base :
16 % $erl -sname yaws -mnesia dir '"/projets/euphorik/BD"'
18 % >euphorik_bd:create().
21 mnesia:delete_schema([node()]),
22 mnesia:create_schema([node()]), % nécessaire pour les tables sur disc
28 mnesia:create_table(counter
, [
29 {attributes
, record_info(fields
, counter
)},
30 {disc_copies
, [node()]}
32 mnesia:create_table(minichat
, [
33 {attributes
, record_info(fields
, minichat
)},
35 {disc_copies
, [node()]}
37 mnesia:create_table(reponse_minichat
, [
39 {attributes
, record_info(fields
, reponse_minichat
)},
41 {disc_copies
, [node()]}
43 mnesia:create_table(user
, [
44 {attributes
, record_info(fields
, user
)},
45 {index
, [cookie
, login
]},
46 {disc_copies
, [node()]}
51 mnesia:transform_table(
53 fun({user
, Id
, Cookie
, Pseudo
, Date_creation
, Date_derniere_connexion
, Css
}) ->
54 {user
, Id
, Cookie
, Pseudo
, "", "", "", Date_creation
, Date_derniere_connexion
, Css
}
56 record_info(fields
, user
),
60 mnesia:transform_table(
62 fun({user
, Id
, Cookie
, Pseudo
, Login
, Password
, Email
, Date_creation
, Date_derniere_connexion
, Css
}) ->
63 {user
, Id
, Cookie
, Pseudo
, Login
, Password
, Email
, Date_creation
, Date_derniere_connexion
, Css
, 0}
65 record_info(fields
, user
),
69 mnesia:transform_table(
71 fun({user
, Id
, Cookie
, Pseudo
, Login
, Password
, Email
, Date_creation
, Date_derniere_connexion
, Css
, Indice_flood
}) ->
72 {user
, Id
, Cookie
, Pseudo
, Login
, Password
, Email
, Date_creation
, Date_derniere_connexion
, Css
, Indice_flood
, []}
74 record_info(fields
, user
),
77 % Ajout du numéro de page de la conv principale
79 mnesia:transform_table(
81 fun({user
, Id
, Cookie
, Pseudo
, Login
, Password
, Email
, Date_creation
, Date_derniere_connexion
, Css
, Indice_flood
, Conversations
}) ->
82 {user
, Id
, Cookie
, Pseudo
, Login
, Password
, Email
, Date_creation
, Date_derniere_connexion
, Css
, Indice_flood
, 1, Conversations
}
84 record_info(fields
, user
),
89 % exemple de peuplage de la BD, utilisé pour les tests
93 mnesia:write({minichat
, now(), "Pierre", "Salut tout le monde"}),
94 mnesia:write({minichat
, now(), "Paul", "Salut à toi !"})