DEL tout ce qui concerne la gestion du CAPTCHA
[euphorik.git] / modules / erl / euphorik_bd.erl
1 % Module de création de la base de données euphorik.
2 % @author G.Burri
3
4 -module(euphorik_bd).
5 -export([
6 create/0,
7 create_tables/0,
8 vers_version/1,
9 peupler/0
10 ]).
11
12 -include("../include/euphorik_bd.hrl").
13
14
15 % Instructions pour créer une nouvelle base :
16 % $erl -sname yaws -mnesia dir '"/projets/euphorik/BD"'
17 % >l(euphorik_bd).
18 % >euphorik_bd:create().
19 create() ->
20 mnesia:stop(),
21 mnesia:delete_schema([node()]),
22 mnesia:create_schema([node()]), % nécessaire pour les tables sur disc
23 mnesia:start(),
24 create_tables().
25
26
27 create_tables() ->
28 mnesia:create_table(counter, [
29 {attributes, record_info(fields, counter)},
30 {disc_copies, [node()]}
31 ]),
32 mnesia:create_table(minichat, [
33 {attributes, record_info(fields, minichat)},
34 {index, [auteur_id]},
35 {disc_copies, [node()]}
36 ]),
37 mnesia:create_table(reponse_minichat, [
38 {type, bag},
39 {attributes, record_info(fields, reponse_minichat)},
40 {index, [cible]},
41 {disc_copies, [node()]}
42 ]),
43 mnesia:create_table(user, [
44 {attributes, record_info(fields, user)},
45 {index, [cookie, login]},
46 {disc_copies, [node()]}
47 ]).
48
49
50 vers_version(2) ->
51 mnesia:transform_table(
52 user,
53 fun({user, Id, Cookie, Pseudo, Date_creation, Date_derniere_connexion, Css}) ->
54 {user, Id, Cookie, Pseudo, "", "", "", Date_creation, Date_derniere_connexion, Css}
55 end,
56 record_info(fields, user),
57 user
58 );
59 vers_version(3) ->
60 mnesia:transform_table(
61 user,
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}
64 end,
65 record_info(fields, user),
66 user
67 );
68 vers_version(4) ->
69 mnesia:transform_table(
70 user,
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, []}
73 end,
74 record_info(fields, user),
75 user
76 );
77 % Ajout du numéro de page de la conv principale
78 vers_version(5) ->
79 mnesia:transform_table(
80 user,
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}
83 end,
84 record_info(fields, user),
85 user
86 ).
87
88
89 % exemple de peuplage de la BD, utilisé pour les tests
90 peupler() ->
91 mnesia:transaction(
92 fun() ->
93 mnesia:write({minichat, now(), "Pierre", "Salut tout le monde"}),
94 mnesia:write({minichat, now(), "Paul", "Salut à toi !"})
95 end
96 ).