init
[garradin.git] / include / data / 0.6.0.sql
1 CREATE TABLE cotisations
2 -- Types de cotisations et activités
3 (
4 id INTEGER PRIMARY KEY,
5 id_categorie_compta INTEGER NULL, -- NULL si le type n'est pas associé automatiquement à la compta
6
7 intitule TEXT NOT NULL,
8 description TEXT NULL,
9 montant REAL NOT NULL,
10
11 duree INTEGER NULL, -- En jours
12 debut TEXT NULL, -- timestamp
13 fin TEXT NULL,
14
15 FOREIGN KEY (id_categorie_compta) REFERENCES compta_categories (id)
16 );
17
18 CREATE TABLE cotisations_membres
19 -- Enregistrement des cotisations et activités
20 (
21 id INTEGER NOT NULL PRIMARY KEY,
22 id_membre INTEGER NOT NULL REFERENCES membres (id),
23 id_cotisation INTEGER NOT NULL REFERENCES cotisations (id),
24
25 date TEXT NOT NULL DEFAULT CURRENT_DATE
26 );
27
28 CREATE UNIQUE INDEX cm_unique ON cotisations_membres (id_membre, id_cotisation, date);
29
30 CREATE TABLE membres_operations
31 -- Liaision des enregistrement des paiements en compta
32 (
33 id_membre INTEGER NOT NULL REFERENCES membres (id),
34 id_operation INTEGER NOT NULL REFERENCES compta_journal (id),
35 id_cotisation INTEGER NULL REFERENCES cotisations_membres (id),
36
37 PRIMARY KEY (id_membre, id_operation)
38 );
39
40 CREATE TABLE rappels
41 -- Rappels de devoir renouveller une cotisation
42 (
43 id INTEGER PRIMARY KEY,
44 id_cotisation INTEGER NOT NULL REFERENCES cotisations (id),
45
46 delai INTEGER NOT NULL, -- Délai en jours pour envoyer le rappel
47
48 sujet TEXT NOT NULL,
49 texte TEXT NOT NULL
50 );
51
52 CREATE TABLE rappels_envoyes
53 -- Enregistrement des rappels envoyés à qui et quand
54 (
55 id INTEGER PRIMARY KEY,
56
57 id_membre INTEGER NOT NULL REFERENCES membres (id),
58 id_cotisation INTEGER NOT NULL REFERENCES cotisations (id),
59
60 date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
61
62 media INTEGER NOT NULL -- Média utilisé pour le rappel : 1 = email, 2 = courrier, 3 = autre
63 );
64
65 CREATE TABLE plugins
66 -- Plugins / extensions
67 (
68 id TEXT PRIMARY KEY,
69 officiel INTEGER NOT NULL DEFAULT 0,
70 nom TEXT NOT NULL,
71 description TEXT,
72 auteur TEXT,
73 url TEXT,
74 version TEXT NOT NULL,
75 menu INTEGER NOT NULL DEFAULT 0,
76 config TEXT
77 );
78
79 -- Mise à jour des catégories
80
81 CREATE TABLE membres_categories_tmp
82 -- Catégories de membres
83 (
84 id INTEGER PRIMARY KEY,
85 nom TEXT,
86 description TEXT,
87
88 droit_wiki INT DEFAULT 1,
89 droit_membres INT DEFAULT 1,
90 droit_compta INT DEFAULT 1,
91 droit_inscription INT DEFAULT 0,
92 droit_connexion INT DEFAULT 1,
93 droit_config INT DEFAULT 0,
94 cacher INT DEFAULT 0,
95
96 id_cotisation_obligatoire INTEGER NULL REFERENCES cotisations (id)
97 );
98
99 -- Remise des anciennes infos
100 INSERT INTO membres_categories_tmp SELECT id, nom, description, droit_wiki, droit_membres,
101 droit_compta, droit_inscription, droit_connexion, droit_config, cacher, NULL FROM membres_categories;
102
103 -- Suppression de l'ancienne table et renommage de la nouvelle
104 DROP TABLE membres_categories;
105 ALTER TABLE membres_categories_tmp RENAME TO membres_categories;
106
107 -- Ajout désactivation compte
108 ALTER TABLE compta_comptes ADD COLUMN desactive INTEGER NOT NULL DEFAULT 0;
109
110 PRAGMA foreign_keys = ON;