c8367761101c368360edaba78f169fd4249b961c
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"'
17 % voir doc/installation.txt
19 % >euphorik_bd:create().
22 mnesia:delete_schema([node()]),
23 mnesia:create_schema([node()]), % nécessaire pour les tables sur disc
29 mnesia:create_table(counter
, [
30 {attributes
, record_info(fields
, counter
)},
31 {disc_copies
, [node()]}
33 mnesia:create_table(minichat
, [
34 {attributes
, record_info(fields
, minichat
)},
36 {disc_copies
, [node()]}
38 mnesia:create_table(reponse_minichat
, [
40 {attributes
, record_info(fields
, reponse_minichat
)},
42 {disc_copies
, [node()]}
44 mnesia:create_table(user
, [
45 {attributes
, record_info(fields
, user
)},
46 {index
, [cookie
, login
]},
47 {disc_copies
, [node()]}
52 mnesia:transform_table(
54 fun({user
, Id
, Cookie
, Pseudo
, Date_creation
, Date_derniere_connexion
, Css
}) ->
55 {user
, Id
, Cookie
, Pseudo
, "", "", "", Date_creation
, Date_derniere_connexion
, Css
}
57 record_info(fields
, user
),
61 mnesia:transform_table(
63 fun({user
, Id
, Cookie
, Pseudo
, Login
, Password
, Email
, Date_creation
, Date_derniere_connexion
, Css
}) ->
64 {user
, Id
, Cookie
, Pseudo
, Login
, Password
, Email
, Date_creation
, Date_derniere_connexion
, Css
, 0}
66 record_info(fields
, user
),
70 mnesia:transform_table(
72 fun({user
, Id
, Cookie
, Pseudo
, Login
, Password
, Email
, Date_creation
, Date_derniere_connexion
, Css
, Indice_flood
}) ->
73 {user
, Id
, Cookie
, Pseudo
, Login
, Password
, Email
, Date_creation
, Date_derniere_connexion
, Css
, Indice_flood
, []}
75 record_info(fields
, user
),
78 % Ajout du numéro de page de la conv principale
80 mnesia:transform_table(
82 fun({user
, Id
, Cookie
, Pseudo
, Login
, Password
, Email
, Date_creation
, Date_derniere_connexion
, Css
, Indice_flood
, Conversations
}) ->
83 {user
, Id
, Cookie
, Pseudo
, Login
, Password
, Email
, Date_creation
, Date_derniere_connexion
, Css
, Indice_flood
, 1, Conversations
}
85 record_info(fields
, user
),
88 % Ajout le format d'affichage des pseudos
90 mnesia:transform_table(
92 fun({user
, Id
, Cookie
, Pseudo
, Login
, Password
, Email
, Date_creation
, Date_derniere_connexion
, Css
, Indice_flood
, Page_Principale
, Conversations
}) ->
93 {user
, Id
, Cookie
, Pseudo
, Login
, Password
, Email
, Date_creation
, Date_derniere_connexion
, Css
, nick
, Indice_flood
, Page_Principale
, Conversations
}
95 record_info(fields
, user
),
100 % exemple de peuplage de la BD, utilisé pour les tests
104 mnesia:write({minichat
, now(), "Pierre", "Salut tout le monde"}),
105 mnesia:write({minichat
, now(), "Paul", "Salut à toi !"})