initial commit

This commit is contained in:
Matthieu Bessat 2024-01-19 16:39:49 +01:00
commit 5ebc506921
975 changed files with 154341 additions and 0 deletions

View file

@ -0,0 +1,64 @@
CREATE TABLE plugins_signaux
-- Association entre plugins et signaux (hooks)
(
signal TEXT NOT NULL,
plugin TEXT NOT NULL REFERENCES plugins (id),
callback TEXT NOT NULL,
PRIMARY KEY (signal, plugin)
);
CREATE TABLE compta_rapprochement
-- Rapprochement entre compta et relevés de comptes
(
operation INTEGER NOT NULL PRIMARY KEY REFERENCES compta_journal (id),
date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
auteur INTEGER NOT NULL REFERENCES membres (id)
);
CREATE TABLE fichiers
-- Données sur les fichiers
(
id INTEGER NOT NULL PRIMARY KEY,
nom TEXT NOT NULL, -- nom de fichier (par exemple image1234.jpeg)
type TEXT NULL, -- Type MIME
image INTEGER NOT NULL DEFAULT 0, -- 1 = image reconnue
datetime TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Date d'ajout ou mise à jour du fichier
id_contenu INTEGER NOT NULL REFERENCES fichiers_contenu (id)
);
CREATE INDEX fichiers_date ON fichiers (datetime);
CREATE TABLE fichiers_contenu
-- Contenu des fichiers
(
id INTEGER NOT NULL PRIMARY KEY,
hash TEXT NOT NULL, -- Hash SHA1 du contenu du fichier
taille INTEGER NOT NULL, -- Taille en octets
contenu BLOB NULL
);
CREATE UNIQUE INDEX fichiers_hash ON fichiers_contenu (hash);
CREATE TABLE fichiers_membres
-- Associations entre fichiers et membres (photo de profil par exemple)
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES membres (id),
PRIMARY KEY(fichier, id)
);
CREATE TABLE fichiers_wiki_pages
-- Associations entre fichiers et pages du wiki
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES wiki_pages (id),
PRIMARY KEY(fichier, id)
);
CREATE TABLE fichiers_compta_journal
-- Associations entre fichiers et journal de compta (pièce comptable par exemple)
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES compta_journal (id),
PRIMARY KEY(fichier, id)
);

View file

@ -0,0 +1,24 @@
-- Colonne manquante
ALTER TABLE rappels_envoyes ADD COLUMN id_rappel INTEGER NULL REFERENCES rappels (id);
-- Un bug a permis d'insérer des comptes avec des lettres minuscules, créant des problèmes
-- corrigeons donc les comptes pour les mettre en majuscules.
UPDATE compta_comptes SET id = UPPER(id);
-- Le champ id_auteur était à NOT NULL, il faut corriger ça pour pouvoir avoir un rapprochement anonyme
-- une fois que le membre a été supprimé
CREATE TABLE compta_rapprochement2
-- Rapprochement entre compta et relevés de comptes
(
id_operation INTEGER NOT NULL PRIMARY KEY REFERENCES compta_journal (id),
date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
id_auteur INTEGER NULL REFERENCES membres (id)
);
INSERT INTO compta_rapprochement2 SELECT operation, date, auteur FROM compta_rapprochement;
DROP TABLE compta_rapprochement;
ALTER TABLE compta_rapprochement2 RENAME TO compta_rapprochement;

View file

@ -0,0 +1,85 @@
-- Ajouter champ pour OTP
ALTER TABLE membres ADD COLUMN secret_otp TEXT NULL;
-- Ajouter champ clé PGP
ALTER TABLE membres ADD COLUMN clef_pgp TEXT NULL;
--------------------------------------------------------------------------------
-- Mise à jour des tables contenant un champ date pour ajouter la contrainte --
-- Ceci afin de forcer les champs à contenir un format de date correct --
-- On en profite pour ajouter les ON DELETE nécessaires --
--------------------------------------------------------------------------------
-- Convertir les dates UNIX en date Y-m-d, apparemment il y en a encore parfois ?
UPDATE wiki_pages SET date_creation = datetime(date_creation, "unixepoch") WHERE CAST(date_creation AS INT) = date_creation;
UPDATE wiki_pages SET date_creation = datetime(date_creation) WHERE datetime(date_creation) != date_creation;
-- Renommage des tables qu'il faut mettre à jour
ALTER TABLE cotisations_membres RENAME TO cotisations_membres_old;
ALTER TABLE rappels RENAME TO rappels_old;
ALTER TABLE rappels_envoyes RENAME TO rappels_envoyes_old;
ALTER TABLE wiki_pages RENAME TO wiki_pages_old;
ALTER TABLE wiki_revisions RENAME TO wiki_revisions_old;
ALTER TABLE compta_categories RENAME TO compta_categories_old;
ALTER TABLE compta_comptes_bancaires RENAME TO compta_comptes_bancaires_old;
ALTER TABLE compta_exercices RENAME TO compta_exercices_old;
ALTER TABLE compta_journal RENAME TO compta_journal_old;
ALTER TABLE compta_rapprochement RENAME TO compta_rapprochement_old;
ALTER TABLE fichiers RENAME TO fichiers_old;
ALTER TABLE membres_operations RENAME TO membres_operations_old;
ALTER TABLE membres_categories RENAME TO membres_categories_old;
-- Suppression des index pour que les nouveaux soient liés aux nouvelles tables
DROP INDEX cm_unique;
DROP INDEX wiki_uri;
DROP INDEX wiki_revisions_id_page;
DROP INDEX wiki_revisions_id_auteur;
DROP INDEX compta_operations_exercice;
DROP INDEX compta_operations_date;
DROP INDEX compta_operations_comptes;
DROP INDEX compta_operations_auteur;
DROP INDEX fichiers_date;
-- Suppression ancienne table recherche
DROP TABLE wiki_recherche;
-- Suppression des triggers
-- Sinon les nouveaux ne seront pas créés sur la nouvelle table
DROP TRIGGER wiki_recherche_delete;
DROP TRIGGER wiki_recherche_update;
DROP TRIGGER wiki_recherche_contenu_insert;
DROP TRIGGER wiki_recherche_contenu_chiffre;
-- Création des tables mises à jour (et de leurs index)
.read 0.8.0_schema.sql
-- Copie des données
INSERT INTO cotisations_membres SELECT * FROM cotisations_membres_old;
INSERT INTO rappels SELECT * FROM rappels_old;
INSERT INTO rappels_envoyes SELECT id, id_membre, id_cotisation, id_rappel, date, media FROM rappels_envoyes_old;
INSERT INTO wiki_pages SELECT * FROM wiki_pages_old;
INSERT INTO wiki_revisions SELECT * FROM wiki_revisions_old;
INSERT INTO compta_categories SELECT * FROM compta_categories_old;
INSERT INTO compta_comptes_bancaires SELECT * FROM compta_comptes_bancaires_old;
INSERT INTO compta_exercices SELECT * FROM compta_exercices_old;
INSERT INTO compta_journal SELECT *, NULL FROM compta_journal_old;
INSERT INTO compta_rapprochement SELECT * FROM compta_rapprochement_old;
INSERT INTO fichiers SELECT * FROM fichiers_old;
INSERT INTO membres_operations SELECT * FROM membres_operations_old;
INSERT INTO membres_categories SELECT id, nom, droit_wiki, droit_membres, droit_compta,
droit_inscription, droit_connexion, droit_config, cacher, id_cotisation_obligatoire FROM membres_categories_old;
-- Suppression des anciennes tables
DROP TABLE cotisations_membres_old;
DROP TABLE rappels_old;
DROP TABLE rappels_envoyes_old;
DROP TABLE wiki_pages_old;
DROP TABLE wiki_revisions_old;
DROP TABLE compta_categories_old;
DROP TABLE compta_comptes_bancaires_old;
DROP TABLE compta_exercices_old;
DROP TABLE compta_journal_old;
DROP TABLE compta_rapprochement_old;
DROP TABLE fichiers_old;
DROP TABLE membres_operations_old;
DROP TABLE membres_categories_old;

390
archives/0.8.0_schema.sql Normal file
View file

@ -0,0 +1,390 @@
CREATE TABLE IF NOT EXISTS config (
-- Configuration de Garradin
cle TEXT PRIMARY KEY NOT NULL,
valeur TEXT
);
-- On stocke ici les ID de catégorie de compta correspondant aux types spéciaux
-- compta_categorie_cotisations => id_categorie
-- compta_categorie_dons => id_categorie
CREATE TABLE IF NOT EXISTS membres_categories
-- Catégories de membres
(
id INTEGER PRIMARY KEY NOT NULL,
nom TEXT NOT NULL,
description TEXT NULL,
droit_wiki INTEGER NOT NULL DEFAULT 1,
droit_membres INTEGER NOT NULL DEFAULT 1,
droit_compta INTEGER NOT NULL DEFAULT 1,
droit_inscription INTEGER NOT NULL DEFAULT 0,
droit_connexion INTEGER NOT NULL DEFAULT 1,
droit_config INTEGER NOT NULL DEFAULT 0,
cacher INTEGER NOT NULL DEFAULT 0,
id_cotisation_obligatoire INTEGER NULL REFERENCES cotisations (id) ON DELETE SET NULL
);
-- Membres de l'asso
-- Table dynamique générée par l'application
-- voir Garradin\Membres\Champs.php
CREATE TABLE IF NOT EXISTS membres_sessions
-- Sessions
(
selecteur TEXT NOT NULL,
hash TEXT NOT NULL,
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
expire INT NOT NULL,
PRIMARY KEY (selecteur, id_membre)
);
CREATE TABLE IF NOT EXISTS cotisations
-- Types de cotisations et activités
(
id INTEGER PRIMARY KEY NOT NULL,
id_categorie_compta INTEGER NULL, -- NULL si le type n'est pas associé automatiquement à la compta
intitule TEXT NOT NULL,
description TEXT NULL,
montant REAL NOT NULL,
duree INTEGER NULL, -- En jours
debut TEXT NULL, -- timestamp
fin TEXT NULL,
FOREIGN KEY (id_categorie_compta) REFERENCES compta_categories (id)
);
CREATE TABLE IF NOT EXISTS cotisations_membres
-- Enregistrement des cotisations et activités
(
id INTEGER NOT NULL PRIMARY KEY,
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date)
);
CREATE UNIQUE INDEX IF NOT EXISTS cm_unique ON cotisations_membres (id_membre, id_cotisation, date);
CREATE TABLE IF NOT EXISTS membres_operations
-- Liaision des enregistrement des paiements en compta
(
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_operation INTEGER NOT NULL REFERENCES compta_journal (id) ON DELETE CASCADE,
id_cotisation INTEGER NULL REFERENCES cotisations_membres (id) ON DELETE SET NULL,
PRIMARY KEY (id_membre, id_operation)
);
CREATE TABLE IF NOT EXISTS rappels
-- Rappels de devoir renouveller une cotisation
(
id INTEGER NOT NULL PRIMARY KEY,
id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,
delai INTEGER NOT NULL, -- Délai en jours pour envoyer le rappel
sujet TEXT NOT NULL,
texte TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS rappels_envoyes
-- Enregistrement des rappels envoyés à qui et quand
(
id INTEGER NOT NULL PRIMARY KEY,
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,
id_rappel INTEGER NULL REFERENCES rappels (id) ON DELETE CASCADE,
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date),
media INTEGER NOT NULL -- Média utilisé pour le rappel : 1 = email, 2 = courrier, 3 = autre
);
--
-- WIKI
--
CREATE TABLE IF NOT EXISTS wiki_pages
-- Pages du wiki
(
id INTEGER PRIMARY KEY NOT NULL,
uri TEXT NOT NULL, -- URI unique (équivalent NomPageWiki)
titre TEXT NOT NULL,
date_creation TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date_creation) IS NOT NULL AND datetime(date_creation) = date_creation),
date_modification TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date_modification) IS NOT NULL AND datetime(date_modification) = date_modification),
parent INTEGER NOT NULL DEFAULT 0, -- ID de la page parent
revision INTEGER NOT NULL DEFAULT 0, -- Numéro de révision (commence à 0 si pas de texte, +1 à chaque changement du texte)
droit_lecture INTEGER NOT NULL DEFAULT 0, -- Accès en lecture (-1 = public [site web], 0 = tous ceux qui ont accès en lecture au wiki, 1+ = ID de groupe)
droit_ecriture INTEGER NOT NULL DEFAULT 0 -- Accès en écriture (0 = tous ceux qui ont droit d'écriture sur le wiki, 1+ = ID de groupe)
);
CREATE UNIQUE INDEX IF NOT EXISTS wiki_uri ON wiki_pages (uri);
CREATE VIRTUAL TABLE IF NOT EXISTS wiki_recherche USING fts4
-- Table dupliquée pour chercher une page
(
id INT PRIMARY KEY NOT NULL, -- Clé externe obligatoire
titre TEXT NOT NULL,
contenu TEXT NULL, -- Contenu de la dernière révision
FOREIGN KEY (id) REFERENCES wiki_pages(id)
);
CREATE TABLE IF NOT EXISTS wiki_revisions
-- Révisions du contenu des pages
(
id_page INTEGER NOT NULL REFERENCES wiki_pages (id) ON DELETE CASCADE,
revision INTEGER NULL,
id_auteur INTEGER NULL REFERENCES membres (id) ON DELETE SET NULL,
contenu TEXT NOT NULL,
modification TEXT NULL, -- Description des modifications effectuées
chiffrement INTEGER NOT NULL DEFAULT 0, -- 1 si le contenu est chiffré, 0 sinon
date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date) IS NOT NULL AND datetime(date) = date),
PRIMARY KEY(id_page, revision)
);
CREATE INDEX IF NOT EXISTS wiki_revisions_id_page ON wiki_revisions (id_page);
CREATE INDEX IF NOT EXISTS wiki_revisions_id_auteur ON wiki_revisions (id_auteur);
-- Triggers pour synchro avec table wiki_pages
CREATE TRIGGER IF NOT EXISTS wiki_recherche_delete AFTER DELETE ON wiki_pages
BEGIN
DELETE FROM wiki_recherche WHERE id = old.id;
END;
CREATE TRIGGER IF NOT EXISTS wiki_recherche_update AFTER UPDATE OF id, titre ON wiki_pages
BEGIN
UPDATE wiki_recherche SET id = new.id, titre = new.titre WHERE id = old.id;
END;
-- Trigger pour mettre à jour le contenu de la table de recherche lors d'une nouvelle révision
CREATE TRIGGER IF NOT EXISTS wiki_recherche_contenu_insert AFTER INSERT ON wiki_revisions WHEN new.chiffrement != 1
BEGIN
UPDATE wiki_recherche SET contenu = new.contenu WHERE id = new.id_page;
END;
-- Si le contenu est chiffré, la recherche n'affiche pas de contenu
CREATE TRIGGER IF NOT EXISTS wiki_recherche_contenu_chiffre AFTER INSERT ON wiki_revisions WHEN new.chiffrement = 1
BEGIN
UPDATE wiki_recherche SET contenu = '' WHERE id = new.id_page;
END;
/*
CREATE TABLE wiki_suivi
-- Suivi des pages
(
id_membre INTEGER NOT NULL,
id_page INTEGER NOT NULL,
PRIMARY KEY (id_membre, id_page),
FOREIGN KEY (id_page) REFERENCES wiki_pages (id), -- Clé externe obligatoire
FOREIGN KEY (id_membre) REFERENCES membres (id) -- Clé externe obligatoire
);
*/
--
-- COMPTA
--
CREATE TABLE IF NOT EXISTS compta_exercices
-- Exercices
(
id INTEGER NOT NULL PRIMARY KEY,
libelle TEXT NOT NULL,
debut TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(debut) IS NOT NULL AND date(debut) = debut),
fin TEXT NULL DEFAULT NULL CHECK (fin IS NULL OR (date(fin) IS NOT NULL AND date(fin) = fin)),
cloture INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS compta_comptes
-- Plan comptable
(
id TEXT NOT NULL PRIMARY KEY, -- peut contenir des lettres, eg. 53A, 53B, etc.
parent TEXT NOT NULL DEFAULT 0,
libelle TEXT NOT NULL,
position INTEGER NOT NULL, -- position actif/passif/charge/produit
plan_comptable INTEGER NOT NULL DEFAULT 1, -- 1 = fait partie du plan comptable, 0 = a été ajouté par l'utilisateur
desactive INTEGER NOT NULL DEFAULT 0 -- 1 = compte historique désactivé
);
CREATE INDEX IF NOT EXISTS compta_comptes_parent ON compta_comptes (parent);
CREATE TABLE IF NOT EXISTS compta_comptes_bancaires
-- Comptes bancaires
(
id TEXT NOT NULL PRIMARY KEY,
banque TEXT NOT NULL,
iban TEXT NULL,
bic TEXT NULL,
FOREIGN KEY(id) REFERENCES compta_comptes(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS compta_projets
-- Projets (compta analytique)
(
id INTEGER PRIMARY KEY NOT NULL,
libelle TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS compta_journal
-- Journal des opérations comptables
(
id INTEGER PRIMARY KEY NOT NULL,
libelle TEXT NOT NULL,
remarques TEXT NULL,
numero_piece TEXT NULL, -- N° de pièce comptable
montant REAL NOT NULL,
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date),
moyen_paiement TEXT NULL,
numero_cheque TEXT NULL,
compte_debit TEXT NULL, -- N° du compte dans le plan, NULL est utilisé pour une opération qui vient d'un exercice précédent
compte_credit TEXT NULL, -- N° du compte dans le plan
id_exercice INTEGER NULL DEFAULT NULL, -- En cas de compta simple, l'exercice est permanent (NULL)
id_auteur INTEGER NULL,
id_categorie INTEGER NULL, -- Numéro de catégorie (en mode simple)
id_projet INTEGER NULL,
FOREIGN KEY(moyen_paiement) REFERENCES compta_moyens_paiement(code),
FOREIGN KEY(compte_debit) REFERENCES compta_comptes(id),
FOREIGN KEY(compte_credit) REFERENCES compta_comptes(id),
FOREIGN KEY(id_exercice) REFERENCES compta_exercices(id),
FOREIGN KEY(id_auteur) REFERENCES membres(id) ON DELETE SET NULL,
FOREIGN KEY(id_categorie) REFERENCES compta_categories(id) ON DELETE SET NULL,
FOREIGN KEY(id_projet) REFERENCES compta_projets(id) ON DELETE SET NULL
);
CREATE INDEX IF NOT EXISTS compta_operations_exercice ON compta_journal (id_exercice);
CREATE INDEX IF NOT EXISTS compta_operations_date ON compta_journal (date);
CREATE INDEX IF NOT EXISTS compta_operations_comptes ON compta_journal (compte_debit, compte_credit);
CREATE INDEX IF NOT EXISTS compta_operations_auteur ON compta_journal (id_auteur);
CREATE TABLE IF NOT EXISTS compta_moyens_paiement
-- Moyens de paiement
(
code TEXT NOT NULL PRIMARY KEY,
nom TEXT NOT NULL
);
--INSERT INTO compta_moyens_paiement (code, nom) VALUES ('AU', 'Autre');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('CB', 'Carte bleue');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('CH', 'Chèque');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('ES', 'Espèces');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('PR', 'Prélèvement');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('TI', 'TIP');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('VI', 'Virement');
CREATE TABLE IF NOT EXISTS compta_categories
-- Catégories pour simplifier le plan comptable
(
id INTEGER NOT NULL PRIMARY KEY,
type INTEGER NOT NULL DEFAULT 1, -- 1 = recette, -1 = dépense, 0 = autre (utilisé uniquement pour l'interface)
intitule TEXT NOT NULL,
description TEXT NULL,
compte TEXT NOT NULL, -- Compte affecté par cette catégorie
FOREIGN KEY(compte) REFERENCES compta_comptes(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS plugins
(
id TEXT NOT NULL PRIMARY KEY,
officiel INTEGER NOT NULL DEFAULT 0,
nom TEXT NOT NULL,
description TEXT NULL,
auteur TEXT NULL,
url TEXT NULL,
version TEXT NOT NULL,
menu INTEGER NOT NULL DEFAULT 0,
config TEXT NULL
);
CREATE TABLE IF NOT EXISTS plugins_signaux
-- Association entre plugins et signaux (hooks)
(
signal TEXT NOT NULL,
plugin TEXT NOT NULL REFERENCES plugins (id),
callback TEXT NOT NULL,
PRIMARY KEY (signal, plugin)
);
CREATE TABLE IF NOT EXISTS compta_rapprochement
-- Rapprochement entre compta et relevés de comptes
(
id_operation INTEGER NOT NULL PRIMARY KEY REFERENCES compta_journal (id) ON DELETE CASCADE,
date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date) IS NOT NULL AND datetime(date) = date),
id_auteur INTEGER NULL REFERENCES membres (id)
);
CREATE TABLE IF NOT EXISTS fichiers
-- Données sur les fichiers
(
id INTEGER NOT NULL PRIMARY KEY,
nom TEXT NOT NULL, -- nom de fichier (par exemple image1234.jpeg)
type TEXT NULL, -- Type MIME
image INTEGER NOT NULL DEFAULT 0, -- 1 = image reconnue
datetime TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(datetime) IS NOT NULL AND datetime(datetime) = datetime), -- Date d'ajout ou mise à jour du fichier
id_contenu INTEGER NOT NULL REFERENCES fichiers_contenu (id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS fichiers_date ON fichiers (datetime);
CREATE TABLE IF NOT EXISTS fichiers_contenu
-- Contenu des fichiers
(
id INTEGER NOT NULL PRIMARY KEY,
hash TEXT NOT NULL, -- Hash SHA1 du contenu du fichier
taille INTEGER NOT NULL, -- Taille en octets
contenu BLOB NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS fichiers_hash ON fichiers_contenu (hash);
CREATE TABLE IF NOT EXISTS fichiers_membres
-- Associations entre fichiers et membres (photo de profil par exemple)
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES membres (id),
PRIMARY KEY(fichier, id)
);
CREATE TABLE IF NOT EXISTS fichiers_wiki_pages
-- Associations entre fichiers et pages du wiki
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES wiki_pages (id),
PRIMARY KEY(fichier, id)
);
CREATE TABLE IF NOT EXISTS fichiers_compta_journal
-- Associations entre fichiers et journal de compta (pièce comptable par exemple)
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES compta_journal (id),
PRIMARY KEY(fichier, id)
);

View file

@ -0,0 +1,11 @@
-- Ajout d'une clause ON DELETE SET NULL sur la table cotisations
ALTER TABLE cotisations_membres RENAME TO cotisations_membres_old;
-- Création des tables mises à jour (et de leurs index)
.read 0.8.3_schema.sql
-- Copie des données
INSERT INTO cotisations_membres SELECT * FROM cotisations_membres_old;
-- Suppression des anciennes tables
DROP TABLE cotisations_membres_old;

388
archives/0.8.3_schema.sql Normal file
View file

@ -0,0 +1,388 @@
CREATE TABLE IF NOT EXISTS config (
-- Configuration de Garradin
cle TEXT PRIMARY KEY NOT NULL,
valeur TEXT
);
-- On stocke ici les ID de catégorie de compta correspondant aux types spéciaux
-- compta_categorie_cotisations => id_categorie
-- compta_categorie_dons => id_categorie
CREATE TABLE IF NOT EXISTS membres_categories
-- Catégories de membres
(
id INTEGER PRIMARY KEY NOT NULL,
nom TEXT NOT NULL,
description TEXT NULL,
droit_wiki INTEGER NOT NULL DEFAULT 1,
droit_membres INTEGER NOT NULL DEFAULT 1,
droit_compta INTEGER NOT NULL DEFAULT 1,
droit_inscription INTEGER NOT NULL DEFAULT 0,
droit_connexion INTEGER NOT NULL DEFAULT 1,
droit_config INTEGER NOT NULL DEFAULT 0,
cacher INTEGER NOT NULL DEFAULT 0,
id_cotisation_obligatoire INTEGER NULL REFERENCES cotisations (id) ON DELETE SET NULL
);
-- Membres de l'asso
-- Table dynamique générée par l'application
-- voir Garradin\Membres\Champs.php
CREATE TABLE IF NOT EXISTS membres_sessions
-- Sessions
(
selecteur TEXT NOT NULL,
hash TEXT NOT NULL,
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
expire INT NOT NULL,
PRIMARY KEY (selecteur, id_membre)
);
CREATE TABLE IF NOT EXISTS cotisations
-- Types de cotisations et activités
(
id INTEGER PRIMARY KEY NOT NULL,
id_categorie_compta INTEGER NULL REFERENCES compta_categories (id) ON DELETE SET NULL, -- NULL si le type n'est pas associé automatiquement à la compta
intitule TEXT NOT NULL,
description TEXT NULL,
montant REAL NOT NULL,
duree INTEGER NULL, -- En jours
debut TEXT NULL, -- timestamp
fin TEXT NULL
);
CREATE TABLE IF NOT EXISTS cotisations_membres
-- Enregistrement des cotisations et activités
(
id INTEGER NOT NULL PRIMARY KEY,
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date)
);
CREATE UNIQUE INDEX IF NOT EXISTS cm_unique ON cotisations_membres (id_membre, id_cotisation, date);
CREATE TABLE IF NOT EXISTS membres_operations
-- Liaison des enregistrement des paiements en compta
(
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_operation INTEGER NOT NULL REFERENCES compta_journal (id) ON DELETE CASCADE,
id_cotisation INTEGER NULL REFERENCES cotisations_membres (id) ON DELETE SET NULL,
PRIMARY KEY (id_membre, id_operation)
);
CREATE TABLE IF NOT EXISTS rappels
-- Rappels de devoir renouveller une cotisation
(
id INTEGER NOT NULL PRIMARY KEY,
id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,
delai INTEGER NOT NULL, -- Délai en jours pour envoyer le rappel
sujet TEXT NOT NULL,
texte TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS rappels_envoyes
-- Enregistrement des rappels envoyés à qui et quand
(
id INTEGER NOT NULL PRIMARY KEY,
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,
id_rappel INTEGER NULL REFERENCES rappels (id) ON DELETE CASCADE,
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date),
media INTEGER NOT NULL -- Média utilisé pour le rappel : 1 = email, 2 = courrier, 3 = autre
);
--
-- WIKI
--
CREATE TABLE IF NOT EXISTS wiki_pages
-- Pages du wiki
(
id INTEGER PRIMARY KEY NOT NULL,
uri TEXT NOT NULL, -- URI unique (équivalent NomPageWiki)
titre TEXT NOT NULL,
date_creation TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date_creation) IS NOT NULL AND datetime(date_creation) = date_creation),
date_modification TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date_modification) IS NOT NULL AND datetime(date_modification) = date_modification),
parent INTEGER NOT NULL DEFAULT 0, -- ID de la page parent
revision INTEGER NOT NULL DEFAULT 0, -- Numéro de révision (commence à 0 si pas de texte, +1 à chaque changement du texte)
droit_lecture INTEGER NOT NULL DEFAULT 0, -- Accès en lecture (-1 = public [site web], 0 = tous ceux qui ont accès en lecture au wiki, 1+ = ID de groupe)
droit_ecriture INTEGER NOT NULL DEFAULT 0 -- Accès en écriture (0 = tous ceux qui ont droit d'écriture sur le wiki, 1+ = ID de groupe)
);
CREATE UNIQUE INDEX IF NOT EXISTS wiki_uri ON wiki_pages (uri);
CREATE VIRTUAL TABLE IF NOT EXISTS wiki_recherche USING fts4
-- Table dupliquée pour chercher une page
(
id INT PRIMARY KEY NOT NULL, -- Clé externe obligatoire
titre TEXT NOT NULL,
contenu TEXT NULL, -- Contenu de la dernière révision
FOREIGN KEY (id) REFERENCES wiki_pages(id)
);
CREATE TABLE IF NOT EXISTS wiki_revisions
-- Révisions du contenu des pages
(
id_page INTEGER NOT NULL REFERENCES wiki_pages (id) ON DELETE CASCADE,
revision INTEGER NULL,
id_auteur INTEGER NULL REFERENCES membres (id) ON DELETE SET NULL,
contenu TEXT NOT NULL,
modification TEXT NULL, -- Description des modifications effectuées
chiffrement INTEGER NOT NULL DEFAULT 0, -- 1 si le contenu est chiffré, 0 sinon
date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date) IS NOT NULL AND datetime(date) = date),
PRIMARY KEY(id_page, revision)
);
CREATE INDEX IF NOT EXISTS wiki_revisions_id_page ON wiki_revisions (id_page);
CREATE INDEX IF NOT EXISTS wiki_revisions_id_auteur ON wiki_revisions (id_auteur);
-- Triggers pour synchro avec table wiki_pages
CREATE TRIGGER IF NOT EXISTS wiki_recherche_delete AFTER DELETE ON wiki_pages
BEGIN
DELETE FROM wiki_recherche WHERE id = old.id;
END;
CREATE TRIGGER IF NOT EXISTS wiki_recherche_update AFTER UPDATE OF id, titre ON wiki_pages
BEGIN
UPDATE wiki_recherche SET id = new.id, titre = new.titre WHERE id = old.id;
END;
-- Trigger pour mettre à jour le contenu de la table de recherche lors d'une nouvelle révision
CREATE TRIGGER IF NOT EXISTS wiki_recherche_contenu_insert AFTER INSERT ON wiki_revisions WHEN new.chiffrement != 1
BEGIN
UPDATE wiki_recherche SET contenu = new.contenu WHERE id = new.id_page;
END;
-- Si le contenu est chiffré, la recherche n'affiche pas de contenu
CREATE TRIGGER IF NOT EXISTS wiki_recherche_contenu_chiffre AFTER INSERT ON wiki_revisions WHEN new.chiffrement = 1
BEGIN
UPDATE wiki_recherche SET contenu = '' WHERE id = new.id_page;
END;
/*
CREATE TABLE wiki_suivi
-- Suivi des pages
(
id_membre INTEGER NOT NULL,
id_page INTEGER NOT NULL,
PRIMARY KEY (id_membre, id_page),
FOREIGN KEY (id_page) REFERENCES wiki_pages (id), -- Clé externe obligatoire
FOREIGN KEY (id_membre) REFERENCES membres (id) -- Clé externe obligatoire
);
*/
--
-- COMPTA
--
CREATE TABLE IF NOT EXISTS compta_exercices
-- Exercices
(
id INTEGER NOT NULL PRIMARY KEY,
libelle TEXT NOT NULL,
debut TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(debut) IS NOT NULL AND date(debut) = debut),
fin TEXT NULL DEFAULT NULL CHECK (fin IS NULL OR (date(fin) IS NOT NULL AND date(fin) = fin)),
cloture INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS compta_comptes
-- Plan comptable
(
id TEXT NOT NULL PRIMARY KEY, -- peut contenir des lettres, eg. 53A, 53B, etc.
parent TEXT NOT NULL DEFAULT 0,
libelle TEXT NOT NULL,
position INTEGER NOT NULL, -- position actif/passif/charge/produit
plan_comptable INTEGER NOT NULL DEFAULT 1, -- 1 = fait partie du plan comptable, 0 = a été ajouté par l'utilisateur
desactive INTEGER NOT NULL DEFAULT 0 -- 1 = compte historique désactivé
);
CREATE INDEX IF NOT EXISTS compta_comptes_parent ON compta_comptes (parent);
CREATE TABLE IF NOT EXISTS compta_comptes_bancaires
-- Comptes bancaires
(
id TEXT NOT NULL PRIMARY KEY,
banque TEXT NOT NULL,
iban TEXT NULL,
bic TEXT NULL,
FOREIGN KEY(id) REFERENCES compta_comptes(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS compta_projets
-- Projets (compta analytique)
(
id INTEGER PRIMARY KEY NOT NULL,
libelle TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS compta_journal
-- Journal des opérations comptables
(
id INTEGER PRIMARY KEY NOT NULL,
libelle TEXT NOT NULL,
remarques TEXT NULL,
numero_piece TEXT NULL, -- N° de pièce comptable
montant REAL NOT NULL,
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date),
moyen_paiement TEXT NULL,
numero_cheque TEXT NULL,
compte_debit TEXT NULL, -- N° du compte dans le plan, NULL est utilisé pour une opération qui vient d'un exercice précédent
compte_credit TEXT NULL, -- N° du compte dans le plan
id_exercice INTEGER NULL DEFAULT NULL, -- En cas de compta simple, l'exercice est permanent (NULL)
id_auteur INTEGER NULL,
id_categorie INTEGER NULL, -- Numéro de catégorie (en mode simple)
id_projet INTEGER NULL,
FOREIGN KEY(moyen_paiement) REFERENCES compta_moyens_paiement(code),
FOREIGN KEY(compte_debit) REFERENCES compta_comptes(id),
FOREIGN KEY(compte_credit) REFERENCES compta_comptes(id),
FOREIGN KEY(id_exercice) REFERENCES compta_exercices(id),
FOREIGN KEY(id_auteur) REFERENCES membres(id) ON DELETE SET NULL,
FOREIGN KEY(id_categorie) REFERENCES compta_categories(id) ON DELETE SET NULL,
FOREIGN KEY(id_projet) REFERENCES compta_projets(id) ON DELETE SET NULL
);
CREATE INDEX IF NOT EXISTS compta_operations_exercice ON compta_journal (id_exercice);
CREATE INDEX IF NOT EXISTS compta_operations_date ON compta_journal (date);
CREATE INDEX IF NOT EXISTS compta_operations_comptes ON compta_journal (compte_debit, compte_credit);
CREATE INDEX IF NOT EXISTS compta_operations_auteur ON compta_journal (id_auteur);
CREATE TABLE IF NOT EXISTS compta_moyens_paiement
-- Moyens de paiement
(
code TEXT NOT NULL PRIMARY KEY,
nom TEXT NOT NULL
);
--INSERT INTO compta_moyens_paiement (code, nom) VALUES ('AU', 'Autre');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('CB', 'Carte bleue');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('CH', 'Chèque');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('ES', 'Espèces');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('PR', 'Prélèvement');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('TI', 'TIP');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('VI', 'Virement');
CREATE TABLE IF NOT EXISTS compta_categories
-- Catégories pour simplifier le plan comptable
(
id INTEGER NOT NULL PRIMARY KEY,
type INTEGER NOT NULL DEFAULT 1, -- 1 = recette, -1 = dépense, 0 = autre (utilisé uniquement pour l'interface)
intitule TEXT NOT NULL,
description TEXT NULL,
compte TEXT NOT NULL, -- Compte affecté par cette catégorie
FOREIGN KEY(compte) REFERENCES compta_comptes(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS plugins
(
id TEXT NOT NULL PRIMARY KEY,
officiel INTEGER NOT NULL DEFAULT 0,
nom TEXT NOT NULL,
description TEXT NULL,
auteur TEXT NULL,
url TEXT NULL,
version TEXT NOT NULL,
menu INTEGER NOT NULL DEFAULT 0,
config TEXT NULL
);
CREATE TABLE IF NOT EXISTS plugins_signaux
-- Association entre plugins et signaux (hooks)
(
signal TEXT NOT NULL,
plugin TEXT NOT NULL REFERENCES plugins (id),
callback TEXT NOT NULL,
PRIMARY KEY (signal, plugin)
);
CREATE TABLE IF NOT EXISTS compta_rapprochement
-- Rapprochement entre compta et relevés de comptes
(
id_operation INTEGER NOT NULL PRIMARY KEY REFERENCES compta_journal (id) ON DELETE CASCADE,
date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date) IS NOT NULL AND datetime(date) = date),
id_auteur INTEGER NULL REFERENCES membres (id)
);
CREATE TABLE IF NOT EXISTS fichiers
-- Données sur les fichiers
(
id INTEGER NOT NULL PRIMARY KEY,
nom TEXT NOT NULL, -- nom de fichier (par exemple image1234.jpeg)
type TEXT NULL, -- Type MIME
image INTEGER NOT NULL DEFAULT 0, -- 1 = image reconnue
datetime TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(datetime) IS NOT NULL AND datetime(datetime) = datetime), -- Date d'ajout ou mise à jour du fichier
id_contenu INTEGER NOT NULL REFERENCES fichiers_contenu (id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS fichiers_date ON fichiers (datetime);
CREATE TABLE IF NOT EXISTS fichiers_contenu
-- Contenu des fichiers
(
id INTEGER NOT NULL PRIMARY KEY,
hash TEXT NOT NULL, -- Hash SHA1 du contenu du fichier
taille INTEGER NOT NULL, -- Taille en octets
contenu BLOB NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS fichiers_hash ON fichiers_contenu (hash);
CREATE TABLE IF NOT EXISTS fichiers_membres
-- Associations entre fichiers et membres (photo de profil par exemple)
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES membres (id),
PRIMARY KEY(fichier, id)
);
CREATE TABLE IF NOT EXISTS fichiers_wiki_pages
-- Associations entre fichiers et pages du wiki
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES wiki_pages (id),
PRIMARY KEY(fichier, id)
);
CREATE TABLE IF NOT EXISTS fichiers_compta_journal
-- Associations entre fichiers et journal de compta (pièce comptable par exemple)
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES compta_journal (id),
PRIMARY KEY(fichier, id)
);

View file

@ -0,0 +1,3 @@
-- Mise à jour des URI du wiki pour ne pas inclure les tirets en début et fin de chaîne
-- (problème de concordance entre API PHP et données SQLite)
UPDATE wiki_pages SET uri = trim(uri, '-') WHERE uri != trim(uri, '-');

View file

@ -0,0 +1,35 @@
-- Désactivation de l'accès aux membres, pour les groupes qui n'avaient que le droit de lecture
-- car maintenant ce droit permet de voir les fiches de membres complètes
UPDATE membres_categories SET droit_membres = 0 WHERE droit_membres = 1;
-- Suppression de la colonne description des catégories
ALTER TABLE membres_categories RENAME TO membres_categories_old;
-- Mise à jour table compta_rapprochement: la foreign key sur membres est passée
-- à ON DELETE SET NULL
ALTER TABLE compta_rapprochement RENAME TO compta_rapprochement_old;
-- Re-créer la table
-- Créer également les nouvelles tables email
.read 0.9.0_schema.sql
-- Copie des données, sauf la colonne description
INSERT INTO membres_categories SELECT id, nom, droit_wiki,
droit_membres, droit_compta, droit_inscription,
droit_connexion, droit_config, cacher,
id_cotisation_obligatoire FROM membres_categories_old;
-- Suppression des anciennes tables
DROP TABLE membres_categories_old;
-- Migration des données
INSERT INTO compta_rapprochement SELECT * FROM compta_rapprochement_old;
DROP TABLE compta_rapprochement_old;
-- Cette variable n'est plus utilisée
DELETE FROM config WHERE cle = 'email_envoi_automatique';
ALTER TABLE plugins ADD COLUMN menu_condition TEXT NULL;
-- Supprimer le début dans le nom des plugins
UPDATE plugins_signaux SET callback = replace(callback, 'Garradin\Plugin\', '');

35
archives/0.9.0_schema.sql Normal file
View file

@ -0,0 +1,35 @@
-- Désactivation de l'accès aux membres, pour les groupes qui n'avaient que le droit de lecture
-- car maintenant ce droit permet de voir les fiches de membres complètes
UPDATE membres_categories SET droit_membres = 0 WHERE droit_membres = 1;
-- Suppression de la colonne description des catégories
ALTER TABLE membres_categories RENAME TO membres_categories_old;
-- Mise à jour table compta_rapprochement: la foreign key sur membres est passée
-- à ON DELETE SET NULL
ALTER TABLE compta_rapprochement RENAME TO compta_rapprochement_old;
-- Re-créer la table
-- Créer également les nouvelles tables email
.read schema.sql
-- Copie des données, sauf la colonne description
INSERT INTO membres_categories SELECT id, nom, droit_wiki,
droit_membres, droit_compta, droit_inscription,
droit_connexion, droit_config, cacher,
id_cotisation_obligatoire FROM membres_categories_old;
-- Suppression des anciennes tables
DROP TABLE membres_categories_old;
-- Migration des données
INSERT INTO compta_rapprochement SELECT * FROM compta_rapprochement_old;
DROP TABLE compta_rapprochement_old;
-- Cette variable n'est plus utilisée
DELETE FROM config WHERE cle = 'email_envoi_automatique';
ALTER TABLE plugins ADD COLUMN menu_condition TEXT NULL;
-- Supprimer le début dans le nom des plugins
UPDATE plugins_signaux SET callback = replace(callback, 'Garradin\Plugin\', '');

View file

@ -0,0 +1,14 @@
-- Il manquait une clause ON DELETE SET NULL sur la foreign key
-- de cotisations quand on faisait une mise à jour depuis une
-- ancienne version
ALTER TABLE cotisations RENAME TO cotisations_old;
.read 0.9.1_schema.sql
INSERT INTO cotisations SELECT * FROM cotisations_old;
DROP TABLE cotisations_old;
-- Changer le compte des reports automatiques
UPDATE compta_journal SET compte_debit = '890' WHERE compte_debit IS NULL;
UPDATE compta_journal SET compte_credit = '890' WHERE compte_credit IS NULL;

400
archives/0.9.1_schema.sql Normal file
View file

@ -0,0 +1,400 @@
CREATE TABLE IF NOT EXISTS config (
-- Configuration de Garradin
cle TEXT PRIMARY KEY NOT NULL,
valeur TEXT
);
-- On stocke ici les ID de catégorie de compta correspondant aux types spéciaux
-- compta_categorie_cotisations => id_categorie
-- compta_categorie_dons => id_categorie
CREATE TABLE IF NOT EXISTS membres_categories
-- Catégories de membres
(
id INTEGER PRIMARY KEY NOT NULL,
nom TEXT NOT NULL,
droit_wiki INTEGER NOT NULL DEFAULT 1,
droit_membres INTEGER NOT NULL DEFAULT 1,
droit_compta INTEGER NOT NULL DEFAULT 1,
droit_inscription INTEGER NOT NULL DEFAULT 0,
droit_connexion INTEGER NOT NULL DEFAULT 1,
droit_config INTEGER NOT NULL DEFAULT 0,
cacher INTEGER NOT NULL DEFAULT 0,
id_cotisation_obligatoire INTEGER NULL REFERENCES cotisations (id) ON DELETE SET NULL
);
-- Membres de l'asso
-- Table dynamique générée par l'application
-- voir Garradin\Membres\Champs.php
CREATE TABLE IF NOT EXISTS membres_sessions
-- Sessions
(
selecteur TEXT NOT NULL,
hash TEXT NOT NULL,
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
expire INT NOT NULL,
PRIMARY KEY (selecteur, id_membre)
);
CREATE TABLE IF NOT EXISTS cotisations
-- Types de cotisations et activités
(
id INTEGER PRIMARY KEY NOT NULL,
id_categorie_compta INTEGER NULL REFERENCES compta_categories (id) ON DELETE SET NULL, -- NULL si le type n'est pas associé automatiquement à la compta
intitule TEXT NOT NULL,
description TEXT NULL,
montant REAL NOT NULL,
duree INTEGER NULL, -- En jours
debut TEXT NULL, -- timestamp
fin TEXT NULL
);
CREATE TABLE IF NOT EXISTS cotisations_membres
-- Enregistrement des cotisations et activités
(
id INTEGER NOT NULL PRIMARY KEY,
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date)
);
CREATE UNIQUE INDEX IF NOT EXISTS cm_unique ON cotisations_membres (id_membre, id_cotisation, date);
CREATE TABLE IF NOT EXISTS membres_operations
-- Liaison des enregistrement des paiements en compta
(
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_operation INTEGER NOT NULL REFERENCES compta_journal (id) ON DELETE CASCADE,
id_cotisation INTEGER NULL REFERENCES cotisations_membres (id) ON DELETE SET NULL,
PRIMARY KEY (id_membre, id_operation)
);
CREATE TABLE IF NOT EXISTS rappels
-- Rappels de devoir renouveller une cotisation
(
id INTEGER NOT NULL PRIMARY KEY,
id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,
delai INTEGER NOT NULL, -- Délai en jours pour envoyer le rappel
sujet TEXT NOT NULL,
texte TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS rappels_envoyes
-- Enregistrement des rappels envoyés à qui et quand
(
id INTEGER NOT NULL PRIMARY KEY,
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,
id_rappel INTEGER NULL REFERENCES rappels (id) ON DELETE CASCADE,
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date),
media INTEGER NOT NULL -- Média utilisé pour le rappel : 1 = email, 2 = courrier, 3 = autre
);
--
-- WIKI
--
CREATE TABLE IF NOT EXISTS wiki_pages
-- Pages du wiki
(
id INTEGER PRIMARY KEY NOT NULL,
uri TEXT NOT NULL, -- URI unique (équivalent NomPageWiki)
titre TEXT NOT NULL,
date_creation TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date_creation) IS NOT NULL AND datetime(date_creation) = date_creation),
date_modification TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date_modification) IS NOT NULL AND datetime(date_modification) = date_modification),
parent INTEGER NOT NULL DEFAULT 0, -- ID de la page parent
revision INTEGER NOT NULL DEFAULT 0, -- Numéro de révision (commence à 0 si pas de texte, +1 à chaque changement du texte)
droit_lecture INTEGER NOT NULL DEFAULT 0, -- Accès en lecture (-1 = public [site web], 0 = tous ceux qui ont accès en lecture au wiki, 1+ = ID de groupe)
droit_ecriture INTEGER NOT NULL DEFAULT 0 -- Accès en écriture (0 = tous ceux qui ont droit d'écriture sur le wiki, 1+ = ID de groupe)
);
CREATE UNIQUE INDEX IF NOT EXISTS wiki_uri ON wiki_pages (uri);
CREATE VIRTUAL TABLE IF NOT EXISTS wiki_recherche USING fts4
-- Table dupliquée pour chercher une page
(
id INT PRIMARY KEY NOT NULL, -- Clé externe obligatoire
titre TEXT NOT NULL,
contenu TEXT NULL, -- Contenu de la dernière révision
FOREIGN KEY (id) REFERENCES wiki_pages(id)
);
CREATE TABLE IF NOT EXISTS wiki_revisions
-- Révisions du contenu des pages
(
id_page INTEGER NOT NULL REFERENCES wiki_pages (id) ON DELETE CASCADE,
revision INTEGER NULL,
id_auteur INTEGER NULL REFERENCES membres (id) ON DELETE SET NULL,
contenu TEXT NOT NULL,
modification TEXT NULL, -- Description des modifications effectuées
chiffrement INTEGER NOT NULL DEFAULT 0, -- 1 si le contenu est chiffré, 0 sinon
date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date) IS NOT NULL AND datetime(date) = date),
PRIMARY KEY(id_page, revision)
);
CREATE INDEX IF NOT EXISTS wiki_revisions_id_page ON wiki_revisions (id_page);
CREATE INDEX IF NOT EXISTS wiki_revisions_id_auteur ON wiki_revisions (id_auteur);
-- Triggers pour synchro avec table wiki_pages
CREATE TRIGGER IF NOT EXISTS wiki_recherche_delete AFTER DELETE ON wiki_pages
BEGIN
DELETE FROM wiki_recherche WHERE id = old.id;
END;
CREATE TRIGGER IF NOT EXISTS wiki_recherche_update AFTER UPDATE OF id, titre ON wiki_pages
BEGIN
UPDATE wiki_recherche SET id = new.id, titre = new.titre WHERE id = old.id;
END;
-- Trigger pour mettre à jour le contenu de la table de recherche lors d'une nouvelle révision
CREATE TRIGGER IF NOT EXISTS wiki_recherche_contenu_insert AFTER INSERT ON wiki_revisions WHEN new.chiffrement != 1
BEGIN
UPDATE wiki_recherche SET contenu = new.contenu WHERE id = new.id_page;
END;
-- Si le contenu est chiffré, la recherche n'affiche pas de contenu
CREATE TRIGGER IF NOT EXISTS wiki_recherche_contenu_chiffre AFTER INSERT ON wiki_revisions WHEN new.chiffrement = 1
BEGIN
UPDATE wiki_recherche SET contenu = '' WHERE id = new.id_page;
END;
/*
CREATE TABLE wiki_suivi
-- Suivi des pages
(
id_membre INTEGER NOT NULL,
id_page INTEGER NOT NULL,
PRIMARY KEY (id_membre, id_page),
FOREIGN KEY (id_page) REFERENCES wiki_pages (id), -- Clé externe obligatoire
FOREIGN KEY (id_membre) REFERENCES membres (id) -- Clé externe obligatoire
);
*/
--
-- COMPTA
--
CREATE TABLE IF NOT EXISTS compta_exercices
-- Exercices
(
id INTEGER NOT NULL PRIMARY KEY,
libelle TEXT NOT NULL,
debut TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(debut) IS NOT NULL AND date(debut) = debut),
fin TEXT NULL DEFAULT NULL CHECK (fin IS NULL OR (date(fin) IS NOT NULL AND date(fin) = fin)),
cloture INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS compta_comptes
-- Plan comptable
(
id TEXT NOT NULL PRIMARY KEY, -- peut contenir des lettres, eg. 53A, 53B, etc.
parent TEXT NOT NULL DEFAULT 0,
libelle TEXT NOT NULL,
position INTEGER NOT NULL, -- position actif/passif/charge/produit
plan_comptable INTEGER NOT NULL DEFAULT 1, -- 1 = fait partie du plan comptable, 0 = a été ajouté par l'utilisateur
desactive INTEGER NOT NULL DEFAULT 0 -- 1 = compte historique désactivé
);
CREATE INDEX IF NOT EXISTS compta_comptes_parent ON compta_comptes (parent);
CREATE TABLE IF NOT EXISTS compta_comptes_bancaires
-- Comptes bancaires
(
id TEXT NOT NULL PRIMARY KEY,
banque TEXT NOT NULL,
iban TEXT NULL,
bic TEXT NULL,
FOREIGN KEY(id) REFERENCES compta_comptes(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS compta_projets
-- Projets (compta analytique)
(
id INTEGER PRIMARY KEY NOT NULL,
libelle TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS compta_journal
-- Journal des opérations comptables
(
id INTEGER PRIMARY KEY NOT NULL,
libelle TEXT NOT NULL,
remarques TEXT NULL,
numero_piece TEXT NULL, -- N° de pièce comptable
montant REAL NOT NULL,
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date),
moyen_paiement TEXT NULL,
numero_cheque TEXT NULL,
compte_debit TEXT NULL, -- N° du compte dans le plan, NULL est utilisé pour une opération qui vient d'un exercice précédent
compte_credit TEXT NULL, -- N° du compte dans le plan
id_exercice INTEGER NULL DEFAULT NULL, -- En cas de compta simple, l'exercice est permanent (NULL)
id_auteur INTEGER NULL,
id_categorie INTEGER NULL, -- Numéro de catégorie (en mode simple)
id_projet INTEGER NULL,
FOREIGN KEY(moyen_paiement) REFERENCES compta_moyens_paiement(code),
FOREIGN KEY(compte_debit) REFERENCES compta_comptes(id),
FOREIGN KEY(compte_credit) REFERENCES compta_comptes(id),
FOREIGN KEY(id_exercice) REFERENCES compta_exercices(id),
FOREIGN KEY(id_auteur) REFERENCES membres(id) ON DELETE SET NULL,
FOREIGN KEY(id_categorie) REFERENCES compta_categories(id) ON DELETE SET NULL,
FOREIGN KEY(id_projet) REFERENCES compta_projets(id) ON DELETE SET NULL
);
CREATE INDEX IF NOT EXISTS compta_operations_exercice ON compta_journal (id_exercice);
CREATE INDEX IF NOT EXISTS compta_operations_date ON compta_journal (date);
CREATE INDEX IF NOT EXISTS compta_operations_comptes ON compta_journal (compte_debit, compte_credit);
CREATE INDEX IF NOT EXISTS compta_operations_auteur ON compta_journal (id_auteur);
CREATE TABLE IF NOT EXISTS compta_moyens_paiement
-- Moyens de paiement
(
code TEXT NOT NULL PRIMARY KEY,
nom TEXT NOT NULL
);
--INSERT INTO compta_moyens_paiement (code, nom) VALUES ('AU', 'Autre');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('CB', 'Carte bleue');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('CH', 'Chèque');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('ES', 'Espèces');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('PR', 'Prélèvement');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('TI', 'TIP');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('VI', 'Virement');
CREATE TABLE IF NOT EXISTS compta_categories
-- Catégories pour simplifier le plan comptable
(
id INTEGER NOT NULL PRIMARY KEY,
type INTEGER NOT NULL DEFAULT 1, -- 1 = recette, -1 = dépense, 0 = autre (utilisé uniquement pour l'interface)
intitule TEXT NOT NULL,
description TEXT NULL,
compte TEXT NOT NULL, -- Compte affecté par cette catégorie
FOREIGN KEY(compte) REFERENCES compta_comptes(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS plugins
(
id TEXT NOT NULL PRIMARY KEY,
officiel INTEGER NOT NULL DEFAULT 0,
nom TEXT NOT NULL,
description TEXT NULL,
auteur TEXT NULL,
url TEXT NULL,
version TEXT NOT NULL,
menu INTEGER NOT NULL DEFAULT 0,
menu_condition TEXT NULL,
config TEXT NULL
);
CREATE TABLE IF NOT EXISTS plugins_signaux
-- Association entre plugins et signaux (hooks)
(
signal TEXT NOT NULL,
plugin TEXT NOT NULL REFERENCES plugins (id),
callback TEXT NOT NULL,
PRIMARY KEY (signal, plugin)
);
CREATE TABLE IF NOT EXISTS compta_rapprochement
-- Rapprochement entre compta et relevés de comptes
(
id_operation INTEGER NOT NULL PRIMARY KEY REFERENCES compta_journal (id) ON DELETE CASCADE,
date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date) IS NOT NULL AND datetime(date) = date),
id_auteur INTEGER NULL REFERENCES membres (id) ON DELETE SET NULL
);
CREATE TABLE IF NOT EXISTS fichiers
-- Données sur les fichiers
(
id INTEGER NOT NULL PRIMARY KEY,
nom TEXT NOT NULL, -- nom de fichier (par exemple image1234.jpeg)
type TEXT NULL, -- Type MIME
image INTEGER NOT NULL DEFAULT 0, -- 1 = image reconnue
datetime TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(datetime) IS NOT NULL AND datetime(datetime) = datetime), -- Date d'ajout ou mise à jour du fichier
id_contenu INTEGER NOT NULL REFERENCES fichiers_contenu (id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS fichiers_date ON fichiers (datetime);
CREATE TABLE IF NOT EXISTS fichiers_contenu
-- Contenu des fichiers
(
id INTEGER NOT NULL PRIMARY KEY,
hash TEXT NOT NULL, -- Hash SHA1 du contenu du fichier
taille INTEGER NOT NULL, -- Taille en octets
contenu BLOB NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS fichiers_hash ON fichiers_contenu (hash);
CREATE TABLE IF NOT EXISTS fichiers_membres
-- Associations entre fichiers et membres (photo de profil par exemple)
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES membres (id),
PRIMARY KEY(fichier, id)
);
CREATE TABLE IF NOT EXISTS fichiers_wiki_pages
-- Associations entre fichiers et pages du wiki
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES wiki_pages (id),
PRIMARY KEY(fichier, id)
);
CREATE TABLE IF NOT EXISTS fichiers_compta_journal
-- Associations entre fichiers et journal de compta (pièce comptable par exemple)
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES compta_journal (id),
PRIMARY KEY(fichier, id)
);
CREATE TABLE IF NOT EXISTS recherches
-- Recherches enregistrées
(
id INTEGER NOT NULL PRIMARY KEY,
id_membre INTEGER NULL REFERENCES membres (id) ON DELETE CASCADE, -- Si non NULL, alors la recherche ne sera visible que par le membre associé
intitule TEXT NOT NULL,
creation TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(creation) IS NOT NULL AND datetime(creation) = creation),
cible TEXT NOT NULL, -- "membres" ou "compta_journal"
type TEXT NOT NULL, -- "json" ou "sql"
contenu TEXT NOT NULL
);

414
archives/0.9.5_schema.sql Normal file
View file

@ -0,0 +1,414 @@
CREATE TABLE IF NOT EXISTS config (
-- Configuration de Garradin
cle TEXT PRIMARY KEY NOT NULL,
valeur TEXT
);
-- On stocke ici les ID de catégorie de compta correspondant aux types spéciaux
-- compta_categorie_cotisations => id_categorie
-- compta_categorie_dons => id_categorie
CREATE TABLE IF NOT EXISTS membres_categories
-- Catégories de membres
(
id INTEGER PRIMARY KEY NOT NULL,
nom TEXT NOT NULL,
droit_wiki INTEGER NOT NULL DEFAULT 1,
droit_membres INTEGER NOT NULL DEFAULT 1,
droit_compta INTEGER NOT NULL DEFAULT 1,
droit_inscription INTEGER NOT NULL DEFAULT 0,
droit_connexion INTEGER NOT NULL DEFAULT 1,
droit_config INTEGER NOT NULL DEFAULT 0,
cacher INTEGER NOT NULL DEFAULT 0,
id_cotisation_obligatoire INTEGER NULL REFERENCES cotisations (id) ON DELETE SET NULL
);
-- Membres de l'asso
-- Table dynamique générée par l'application
-- voir Garradin\Membres\Champs.php
CREATE TABLE IF NOT EXISTS membres_sessions
-- Sessions
(
selecteur TEXT NOT NULL,
hash TEXT NOT NULL,
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
expire INT NOT NULL,
PRIMARY KEY (selecteur, id_membre)
);
CREATE TABLE IF NOT EXISTS cotisations
-- Types de cotisations et activités
(
id INTEGER PRIMARY KEY NOT NULL,
id_categorie_compta INTEGER NULL REFERENCES compta_categories (id) ON DELETE SET NULL, -- NULL si le type n'est pas associé automatiquement à la compta
intitule TEXT NOT NULL,
description TEXT NULL,
montant REAL NOT NULL,
duree INTEGER NULL, -- En jours
debut TEXT NULL, -- timestamp
fin TEXT NULL
);
CREATE TABLE IF NOT EXISTS cotisations_membres
-- Enregistrement des cotisations et activités
(
id INTEGER NOT NULL PRIMARY KEY,
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date)
);
CREATE UNIQUE INDEX IF NOT EXISTS cm_unique ON cotisations_membres (id_membre, id_cotisation, date);
CREATE TABLE IF NOT EXISTS membres_operations
-- Liaison des enregistrement des paiements en compta
(
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_operation INTEGER NOT NULL REFERENCES compta_journal (id) ON DELETE CASCADE,
id_cotisation INTEGER NULL REFERENCES cotisations_membres (id) ON DELETE SET NULL,
PRIMARY KEY (id_membre, id_operation)
);
CREATE TABLE IF NOT EXISTS rappels
-- Rappels de devoir renouveller une cotisation
(
id INTEGER NOT NULL PRIMARY KEY,
id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,
delai INTEGER NOT NULL, -- Délai en jours pour envoyer le rappel
sujet TEXT NOT NULL,
texte TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS rappels_envoyes
-- Enregistrement des rappels envoyés à qui et quand
(
id INTEGER NOT NULL PRIMARY KEY,
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,
id_rappel INTEGER NULL REFERENCES rappels (id) ON DELETE CASCADE,
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date),
media INTEGER NOT NULL -- Média utilisé pour le rappel : 1 = email, 2 = courrier, 3 = autre
);
--
-- WIKI
--
CREATE TABLE IF NOT EXISTS wiki_pages
-- Pages du wiki
(
id INTEGER PRIMARY KEY NOT NULL,
uri TEXT NOT NULL, -- URI unique (équivalent NomPageWiki)
titre TEXT NOT NULL,
date_creation TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date_creation) IS NOT NULL AND datetime(date_creation) = date_creation),
date_modification TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date_modification) IS NOT NULL AND datetime(date_modification) = date_modification),
parent INTEGER NOT NULL DEFAULT 0, -- ID de la page parent
revision INTEGER NOT NULL DEFAULT 0, -- Numéro de révision (commence à 0 si pas de texte, +1 à chaque changement du texte)
droit_lecture INTEGER NOT NULL DEFAULT 0, -- Accès en lecture (-1 = public [site web], 0 = tous ceux qui ont accès en lecture au wiki, 1+ = ID de groupe)
droit_ecriture INTEGER NOT NULL DEFAULT 0 -- Accès en écriture (0 = tous ceux qui ont droit d'écriture sur le wiki, 1+ = ID de groupe)
);
CREATE UNIQUE INDEX IF NOT EXISTS wiki_uri ON wiki_pages (uri);
CREATE VIRTUAL TABLE IF NOT EXISTS wiki_recherche USING fts4
-- Table dupliquée pour chercher une page
(
id INT PRIMARY KEY NOT NULL, -- Clé externe obligatoire
titre TEXT NOT NULL,
contenu TEXT NULL, -- Contenu de la dernière révision
FOREIGN KEY (id) REFERENCES wiki_pages(id)
);
CREATE TABLE IF NOT EXISTS wiki_revisions
-- Révisions du contenu des pages
(
id_page INTEGER NOT NULL REFERENCES wiki_pages (id) ON DELETE CASCADE,
revision INTEGER NULL,
id_auteur INTEGER NULL REFERENCES membres (id) ON DELETE SET NULL,
contenu TEXT NOT NULL,
modification TEXT NULL, -- Description des modifications effectuées
chiffrement INTEGER NOT NULL DEFAULT 0, -- 1 si le contenu est chiffré, 0 sinon
date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date) IS NOT NULL AND datetime(date) = date),
PRIMARY KEY(id_page, revision)
);
CREATE INDEX IF NOT EXISTS wiki_revisions_id_page ON wiki_revisions (id_page);
CREATE INDEX IF NOT EXISTS wiki_revisions_id_auteur ON wiki_revisions (id_auteur);
-- Triggers pour synchro avec table wiki_pages
CREATE TRIGGER IF NOT EXISTS wiki_recherche_delete AFTER DELETE ON wiki_pages
BEGIN
DELETE FROM wiki_recherche WHERE id = old.id;
END;
CREATE TRIGGER IF NOT EXISTS wiki_recherche_update AFTER UPDATE OF id, titre ON wiki_pages
BEGIN
UPDATE wiki_recherche SET id = new.id, titre = new.titre WHERE id = old.id;
END;
-- Trigger pour mettre à jour le contenu de la table de recherche lors d'une nouvelle révision
CREATE TRIGGER IF NOT EXISTS wiki_recherche_contenu_insert AFTER INSERT ON wiki_revisions WHEN new.chiffrement != 1
BEGIN
UPDATE wiki_recherche SET contenu = new.contenu WHERE id = new.id_page;
END;
-- Si le contenu est chiffré, la recherche n'affiche pas de contenu
CREATE TRIGGER IF NOT EXISTS wiki_recherche_contenu_chiffre AFTER INSERT ON wiki_revisions WHEN new.chiffrement = 1
BEGIN
UPDATE wiki_recherche SET contenu = '' WHERE id = new.id_page;
END;
/*
CREATE TABLE wiki_suivi
-- Suivi des pages
(
id_membre INTEGER NOT NULL,
id_page INTEGER NOT NULL,
PRIMARY KEY (id_membre, id_page),
FOREIGN KEY (id_page) REFERENCES wiki_pages (id), -- Clé externe obligatoire
FOREIGN KEY (id_membre) REFERENCES membres (id) -- Clé externe obligatoire
);
*/
--
-- COMPTA
--
CREATE TABLE IF NOT EXISTS compta_exercices
-- Exercices
(
id INTEGER NOT NULL PRIMARY KEY,
libelle TEXT NOT NULL,
debut TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(debut) IS NOT NULL AND date(debut) = debut),
fin TEXT NULL DEFAULT NULL CHECK (fin IS NULL OR (date(fin) IS NOT NULL AND date(fin) = fin)),
cloture INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS compta_comptes
-- Plan comptable
(
id TEXT NOT NULL PRIMARY KEY, -- peut contenir des lettres, eg. 53A, 53B, etc.
parent TEXT NOT NULL DEFAULT 0,
libelle TEXT NOT NULL,
position INTEGER NOT NULL, -- position actif/passif/charge/produit
plan_comptable INTEGER NOT NULL DEFAULT 1, -- 1 = fait partie du plan comptable, 0 = a été ajouté par l'utilisateur
desactive INTEGER NOT NULL DEFAULT 0 -- 1 = compte historique désactivé
);
CREATE INDEX IF NOT EXISTS compta_comptes_parent ON compta_comptes (parent);
CREATE TABLE IF NOT EXISTS compta_comptes_bancaires
-- Comptes bancaires
(
id TEXT NOT NULL PRIMARY KEY,
banque TEXT NOT NULL,
iban TEXT NULL,
bic TEXT NULL,
FOREIGN KEY(id) REFERENCES compta_comptes(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS compta_projets
-- Projets (compta analytique)
(
id INTEGER PRIMARY KEY NOT NULL,
libelle TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS compta_journal
-- Journal des opérations comptables
(
id INTEGER PRIMARY KEY NOT NULL,
libelle TEXT NOT NULL,
remarques TEXT NULL,
numero_piece TEXT NULL, -- N° de pièce comptable
montant REAL NOT NULL,
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date),
moyen_paiement TEXT NULL,
numero_cheque TEXT NULL,
compte_debit TEXT NULL, -- N° du compte dans le plan, NULL est utilisé pour une opération qui vient d'un exercice précédent
compte_credit TEXT NULL, -- N° du compte dans le plan
id_exercice INTEGER NULL DEFAULT NULL, -- En cas de compta simple, l'exercice est permanent (NULL)
id_auteur INTEGER NULL,
id_categorie INTEGER NULL, -- Numéro de catégorie (en mode simple)
id_projet INTEGER NULL,
FOREIGN KEY(moyen_paiement) REFERENCES compta_moyens_paiement(code),
FOREIGN KEY(compte_debit) REFERENCES compta_comptes(id),
FOREIGN KEY(compte_credit) REFERENCES compta_comptes(id),
FOREIGN KEY(id_exercice) REFERENCES compta_exercices(id),
FOREIGN KEY(id_auteur) REFERENCES membres(id) ON DELETE SET NULL,
FOREIGN KEY(id_categorie) REFERENCES compta_categories(id) ON DELETE SET NULL,
FOREIGN KEY(id_projet) REFERENCES compta_projets(id) ON DELETE SET NULL
);
CREATE INDEX IF NOT EXISTS compta_operations_exercice ON compta_journal (id_exercice);
CREATE INDEX IF NOT EXISTS compta_operations_date ON compta_journal (date);
CREATE INDEX IF NOT EXISTS compta_operations_comptes ON compta_journal (compte_debit, compte_credit);
CREATE INDEX IF NOT EXISTS compta_operations_auteur ON compta_journal (id_auteur);
CREATE TABLE IF NOT EXISTS compta_moyens_paiement
-- Moyens de paiement
(
code TEXT NOT NULL PRIMARY KEY,
nom TEXT NOT NULL
);
--INSERT INTO compta_moyens_paiement (code, nom) VALUES ('AU', 'Autre');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('CB', 'Carte bleue');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('CH', 'Chèque');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('ES', 'Espèces');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('PR', 'Prélèvement');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('TI', 'TIP');
INSERT OR IGNORE INTO compta_moyens_paiement (code, nom) VALUES ('VI', 'Virement');
CREATE TABLE IF NOT EXISTS compta_categories
-- Catégories pour simplifier le plan comptable
(
id INTEGER NOT NULL PRIMARY KEY,
type INTEGER NOT NULL DEFAULT 1, -- 1 = recette, -1 = dépense, 0 = autre (utilisé uniquement pour l'interface)
intitule TEXT NOT NULL,
description TEXT NULL,
compte TEXT NOT NULL, -- Compte affecté par cette catégorie
FOREIGN KEY(compte) REFERENCES compta_comptes(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS plugins
(
id TEXT NOT NULL PRIMARY KEY,
officiel INTEGER NOT NULL DEFAULT 0,
nom TEXT NOT NULL,
description TEXT NULL,
auteur TEXT NULL,
url TEXT NULL,
version TEXT NOT NULL,
menu INTEGER NOT NULL DEFAULT 0,
menu_condition TEXT NULL,
config TEXT NULL
);
CREATE TABLE IF NOT EXISTS plugins_signaux
-- Association entre plugins et signaux (hooks)
(
signal TEXT NOT NULL,
plugin TEXT NOT NULL REFERENCES plugins (id),
callback TEXT NOT NULL,
PRIMARY KEY (signal, plugin)
);
CREATE TABLE IF NOT EXISTS compta_rapprochement
-- Rapprochement entre compta et relevés de comptes
(
id_operation INTEGER NOT NULL PRIMARY KEY REFERENCES compta_journal (id) ON DELETE CASCADE,
date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date) IS NOT NULL AND datetime(date) = date),
id_auteur INTEGER NULL REFERENCES membres (id) ON DELETE SET NULL
);
CREATE TABLE IF NOT EXISTS fichiers
-- Données sur les fichiers
(
id INTEGER NOT NULL PRIMARY KEY,
nom TEXT NOT NULL, -- nom de fichier (par exemple image1234.jpeg)
type TEXT NULL, -- Type MIME
image INTEGER NOT NULL DEFAULT 0, -- 1 = image reconnue
datetime TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(datetime) IS NOT NULL AND datetime(datetime) = datetime), -- Date d'ajout ou mise à jour du fichier
id_contenu INTEGER NOT NULL REFERENCES fichiers_contenu (id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS fichiers_date ON fichiers (datetime);
CREATE TABLE IF NOT EXISTS fichiers_contenu
-- Contenu des fichiers
(
id INTEGER NOT NULL PRIMARY KEY,
hash TEXT NOT NULL, -- Hash SHA1 du contenu du fichier
taille INTEGER NOT NULL, -- Taille en octets
contenu BLOB NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS fichiers_hash ON fichiers_contenu (hash);
CREATE TABLE IF NOT EXISTS fichiers_membres
-- Associations entre fichiers et membres (photo de profil par exemple)
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES membres (id),
PRIMARY KEY(fichier, id)
);
CREATE TABLE IF NOT EXISTS fichiers_wiki_pages
-- Associations entre fichiers et pages du wiki
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES wiki_pages (id),
PRIMARY KEY(fichier, id)
);
CREATE TABLE IF NOT EXISTS fichiers_compta_journal
-- Associations entre fichiers et journal de compta (pièce comptable par exemple)
(
fichier INTEGER NOT NULL REFERENCES fichiers (id),
id INTEGER NOT NULL REFERENCES compta_journal (id),
PRIMARY KEY(fichier, id)
);
CREATE TABLE IF NOT EXISTS recherches
-- Recherches enregistrées
(
id INTEGER NOT NULL PRIMARY KEY,
id_membre INTEGER NULL REFERENCES membres (id) ON DELETE CASCADE, -- Si non NULL, alors la recherche ne sera visible que par le membre associé
intitule TEXT NOT NULL,
creation TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(creation) IS NOT NULL AND datetime(creation) = creation),
cible TEXT NOT NULL, -- "membres" ou "compta_journal"
type TEXT NOT NULL, -- "json" ou "sql"
contenu TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS compromised_passwords_cache
-- Cache des hash de mots de passe compromis
(
hash TEXT NOT NULL PRIMARY KEY
);
CREATE TABLE IF NOT EXISTS compromised_passwords_cache_ranges
-- Cache des préfixes de mots de passe compromis
(
prefix TEXT NOT NULL PRIMARY KEY,
date INTEGER NOT NULL
);

406
archives/1.0.0_schema.sql Normal file
View file

@ -0,0 +1,406 @@
CREATE TABLE IF NOT EXISTS config (
-- Configuration de Garradin
cle TEXT PRIMARY KEY NOT NULL,
valeur TEXT
);
CREATE TABLE IF NOT EXISTS membres_categories
-- Catégories de membres
(
id INTEGER PRIMARY KEY NOT NULL,
nom TEXT NOT NULL,
droit_wiki INTEGER NOT NULL DEFAULT 1,
droit_membres INTEGER NOT NULL DEFAULT 1,
droit_compta INTEGER NOT NULL DEFAULT 1,
droit_inscription INTEGER NOT NULL DEFAULT 0,
droit_connexion INTEGER NOT NULL DEFAULT 1,
droit_config INTEGER NOT NULL DEFAULT 0,
cacher INTEGER NOT NULL DEFAULT 0
);
-- Membres de l'asso
-- Table dynamique générée par l'application
-- voir Garradin\Membres\Champs.php
CREATE TABLE IF NOT EXISTS membres_sessions
-- Sessions
(
selecteur TEXT NOT NULL,
hash TEXT NOT NULL,
id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
expire INT NOT NULL,
PRIMARY KEY (selecteur, id_membre)
);
CREATE TABLE IF NOT EXISTS services
-- Types de services (cotisations)
(
id INTEGER PRIMARY KEY NOT NULL,
label TEXT NOT NULL,
description TEXT NULL,
duration INTEGER NULL CHECK (duration IS NULL OR duration > 0), -- En jours
start_date TEXT NULL CHECK (start_date IS NULL OR date(start_date) = start_date),
end_date TEXT NULL CHECK (end_date IS NULL OR (date(end_date) = end_date AND date(end_date) >= date(start_date)))
);
CREATE TABLE IF NOT EXISTS services_fees
(
id INTEGER PRIMARY KEY NOT NULL,
label TEXT NOT NULL,
description TEXT NULL,
amount INTEGER NULL,
formula TEXT NULL, -- Formule de calcul du montant de la cotisation, si cotisation dynamique (exemple : membres.revenu_imposable * 0.01)
id_service INTEGER NOT NULL REFERENCES services (id) ON DELETE CASCADE,
id_account INTEGER NULL REFERENCES acc_accounts (id) ON DELETE SET NULL CHECK (id_account IS NULL OR id_year IS NOT NULL), -- NULL si le type n'est pas associé automatiquement à la compta
id_year INTEGER NULL REFERENCES acc_years (id) ON DELETE SET NULL -- NULL si le type n'est pas associé automatiquement à la compta
);
CREATE TABLE IF NOT EXISTS services_users
-- Enregistrement des cotisations et activités
(
id INTEGER NOT NULL PRIMARY KEY,
id_user INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_service INTEGER NOT NULL REFERENCES services (id) ON DELETE CASCADE,
id_fee INTEGER NULL REFERENCES services_fees (id) ON DELETE CASCADE,
paid INTEGER NOT NULL DEFAULT 0,
expected_amount INTEGER NULL,
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date),
expiry_date TEXT NULL CHECK (date(expiry_date) IS NULL OR date(expiry_date) = expiry_date)
);
CREATE UNIQUE INDEX IF NOT EXISTS su_unique ON services_users (id_user, id_service, date);
CREATE INDEX IF NOT EXISTS su_service ON services_users (id_service);
CREATE INDEX IF NOT EXISTS su_fee ON services_users (id_fee);
CREATE INDEX IF NOT EXISTS su_paid ON services_users (paid);
CREATE INDEX IF NOT EXISTS su_expiry ON services_users (expiry_date);
CREATE TABLE IF NOT EXISTS services_reminders
-- Rappels de devoir renouveller une cotisation
(
id INTEGER NOT NULL PRIMARY KEY,
id_service INTEGER NOT NULL REFERENCES services (id) ON DELETE CASCADE,
delay INTEGER NOT NULL, -- Délai en jours pour envoyer le rappel
subject TEXT NOT NULL,
body TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS services_reminders_sent
-- Enregistrement des rappels envoyés à qui et quand
(
id INTEGER NOT NULL PRIMARY KEY,
id_user INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_service INTEGER NOT NULL REFERENCES services (id) ON DELETE CASCADE,
id_reminder INTEGER NOT NULL REFERENCES services_reminders (id) ON DELETE CASCADE,
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date)
);
CREATE UNIQUE INDEX IF NOT EXISTS srs_index ON services_reminders_sent (id_user, id_service, id_reminder, date);
CREATE INDEX IF NOT EXISTS srs_reminder ON services_reminders_sent (id_reminder);
CREATE INDEX IF NOT EXISTS srs_user ON services_reminders_sent (id_user);
--
-- WIKI
--
CREATE TABLE IF NOT EXISTS wiki_pages
-- Pages du wiki
(
id INTEGER PRIMARY KEY NOT NULL,
uri TEXT NOT NULL, -- URI unique (équivalent NomPageWiki)
titre TEXT NOT NULL,
date_creation TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date_creation) IS NOT NULL AND datetime(date_creation) = date_creation),
date_modification TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date_modification) IS NOT NULL AND datetime(date_modification) = date_modification),
parent INTEGER NOT NULL DEFAULT 0, -- ID de la page parent
revision INTEGER NOT NULL DEFAULT 0, -- Numéro de révision (commence à 0 si pas de texte, +1 à chaque changement du texte)
droit_lecture INTEGER NOT NULL DEFAULT 0, -- Accès en lecture (-1 = public [site web], 0 = tous ceux qui ont accès en lecture au wiki, 1+ = ID de groupe)
droit_ecriture INTEGER NOT NULL DEFAULT 0 -- Accès en écriture (0 = tous ceux qui ont droit d'écriture sur le wiki, 1+ = ID de groupe)
);
CREATE UNIQUE INDEX IF NOT EXISTS wiki_uri ON wiki_pages (uri);
CREATE VIRTUAL TABLE IF NOT EXISTS wiki_recherche USING fts4
-- Table dupliquée pour chercher une page
(
id INT PRIMARY KEY NOT NULL, -- Clé externe obligatoire
titre TEXT NOT NULL,
contenu TEXT NULL, -- Contenu de la dernière révision
FOREIGN KEY (id) REFERENCES wiki_pages(id)
);
CREATE TABLE IF NOT EXISTS wiki_revisions
-- Révisions du contenu des pages
(
id_page INTEGER NOT NULL REFERENCES wiki_pages (id) ON DELETE CASCADE,
revision INTEGER NULL,
id_auteur INTEGER NULL REFERENCES membres (id) ON DELETE SET NULL,
contenu TEXT NOT NULL,
modification TEXT NULL, -- Description des modifications effectuées
chiffrement INTEGER NOT NULL DEFAULT 0, -- 1 si le contenu est chiffré, 0 sinon
date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(date) IS NOT NULL AND datetime(date) = date),
PRIMARY KEY(id_page, revision)
);
CREATE INDEX IF NOT EXISTS wiki_revisions_id_page ON wiki_revisions (id_page);
CREATE INDEX IF NOT EXISTS wiki_revisions_id_auteur ON wiki_revisions (id_auteur);
-- Triggers pour synchro avec table wiki_pages
CREATE TRIGGER IF NOT EXISTS wiki_recherche_delete AFTER DELETE ON wiki_pages
BEGIN
DELETE FROM wiki_recherche WHERE id = old.id;
END;
CREATE TRIGGER IF NOT EXISTS wiki_recherche_update AFTER UPDATE OF id, titre ON wiki_pages
BEGIN
UPDATE wiki_recherche SET id = new.id, titre = new.titre WHERE id = old.id;
END;
-- Trigger pour mettre à jour le contenu de la table de recherche lors d'une nouvelle révision
CREATE TRIGGER IF NOT EXISTS wiki_recherche_contenu_insert AFTER INSERT ON wiki_revisions WHEN new.chiffrement != 1
BEGIN
UPDATE wiki_recherche SET contenu = new.contenu WHERE id = new.id_page;
END;
-- Si le contenu est chiffré, la recherche n'affiche pas de contenu
CREATE TRIGGER IF NOT EXISTS wiki_recherche_contenu_chiffre AFTER INSERT ON wiki_revisions WHEN new.chiffrement = 1
BEGIN
UPDATE wiki_recherche SET contenu = '' WHERE id = new.id_page;
END;
--
-- COMPTA
--
CREATE TABLE IF NOT EXISTS acc_charts
-- Plans comptables : il peut y en avoir plusieurs
(
id INTEGER NOT NULL PRIMARY KEY,
country TEXT NOT NULL,
code TEXT NULL, -- NULL = plan comptable créé par l'utilisateur
label TEXT NOT NULL,
archived INTEGER NOT NULL DEFAULT 0 -- 1 = archivé, non-modifiable
);
CREATE TABLE IF NOT EXISTS acc_accounts
-- Comptes des plans comptables
(
id INTEGER NOT NULL PRIMARY KEY,
id_chart INTEGER NOT NULL REFERENCES acc_charts ON DELETE CASCADE,
code TEXT NOT NULL, -- peut contenir des lettres, eg. 53A, 53B, etc.
label TEXT NOT NULL,
description TEXT NULL,
position INTEGER NOT NULL, -- position actif/passif/charge/produit
type INTEGER NOT NULL DEFAULT 0, -- Type de compte spécial : banque, caisse, en attente d'encaissement, etc.
user INTEGER NOT NULL DEFAULT 1 -- 1 = fait partie du plan comptable original, 0 = a été ajouté par l'utilisateur
);
CREATE UNIQUE INDEX IF NOT EXISTS acc_accounts_codes ON acc_accounts (code, id_chart);
CREATE INDEX IF NOT EXISTS acc_accounts_type ON acc_accounts (type);
CREATE INDEX IF NOT EXISTS acc_accounts_position ON acc_accounts (position);
CREATE TABLE IF NOT EXISTS acc_years
-- Exercices
(
id INTEGER NOT NULL PRIMARY KEY,
label TEXT NOT NULL,
start_date TEXT NOT NULL CHECK (date(start_date) IS NOT NULL AND date(start_date) = start_date),
end_date TEXT NOT NULL CHECK (date(end_date) IS NOT NULL AND date(end_date) = end_date),
closed INTEGER NOT NULL DEFAULT 0,
id_chart INTEGER NOT NULL REFERENCES acc_charts (id)
);
CREATE TRIGGER IF NOT EXISTS acc_years_delete BEFORE DELETE ON acc_years BEGIN
UPDATE services_fees SET id_account = NULL, id_year = NULL WHERE id_year = OLD.id;
END;
CREATE INDEX IF NOT EXISTS acc_years_closed ON acc_years (closed);
CREATE TABLE IF NOT EXISTS acc_transactions
-- Opérations comptables
(
id INTEGER PRIMARY KEY NOT NULL,
type INTEGER NOT NULL DEFAULT 0, -- Type d'écriture, 0 = avancée (normale)
status INTEGER NOT NULL DEFAULT 0, -- Statut (bitmask)
label TEXT NOT NULL,
notes TEXT NULL,
reference TEXT NULL, -- N° de pièce comptable
date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date),
validated INTEGER NOT NULL DEFAULT 0, -- 1 = écriture validée, non modifiable
hash TEXT NULL,
prev_hash TEXT NULL,
id_year INTEGER NOT NULL REFERENCES acc_years(id),
id_creator INTEGER NULL REFERENCES membres(id) ON DELETE SET NULL,
id_related INTEGER NULL REFERENCES acc_transactions(id) ON DELETE SET NULL -- écriture liée (par ex. remboursement d'une dette)
);
CREATE INDEX IF NOT EXISTS acc_transactions_year ON acc_transactions (id_year);
CREATE INDEX IF NOT EXISTS acc_transactions_date ON acc_transactions (date);
CREATE INDEX IF NOT EXISTS acc_transactions_related ON acc_transactions (id_related);
CREATE INDEX IF NOT EXISTS acc_transactions_type ON acc_transactions (type, id_year);
CREATE INDEX IF NOT EXISTS acc_transactions_status ON acc_transactions (status);
CREATE TABLE IF NOT EXISTS acc_transactions_lines
-- Lignes d'écritures d'une opération
(
id INTEGER PRIMARY KEY NOT NULL,
id_transaction INTEGER NOT NULL REFERENCES acc_transactions (id) ON DELETE CASCADE,
id_account INTEGER NOT NULL REFERENCES acc_accounts (id), -- N° du compte dans le plan comptable
credit INTEGER NOT NULL,
debit INTEGER NOT NULL,
reference TEXT NULL, -- Référence de paiement, eg. numéro de chèque
label TEXT NULL,
reconciled INTEGER NOT NULL DEFAULT 0,
id_analytical INTEGER NULL REFERENCES acc_accounts(id) ON DELETE SET NULL,
CONSTRAINT line_check1 CHECK ((credit * debit) = 0),
CONSTRAINT line_check2 CHECK ((credit + debit) > 0)
);
CREATE INDEX IF NOT EXISTS acc_transactions_lines_transaction ON acc_transactions_lines (id_transaction);
CREATE INDEX IF NOT EXISTS acc_transactions_lines_account ON acc_transactions_lines (id_account);
CREATE INDEX IF NOT EXISTS acc_transactions_lines_analytical ON acc_transactions_lines (id_analytical);
CREATE INDEX IF NOT EXISTS acc_transactions_lines_reconciled ON acc_transactions_lines (reconciled);
CREATE TABLE IF NOT EXISTS acc_transactions_users
-- Liaison des écritures et des membres
(
id_user INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
id_transaction INTEGER NOT NULL REFERENCES acc_transactions (id) ON DELETE CASCADE,
id_service_user INTEGER NULL REFERENCES services_users (id) ON DELETE SET NULL,
PRIMARY KEY (id_user, id_transaction)
);
CREATE INDEX IF NOT EXISTS acc_transactions_users_service ON acc_transactions_users (id_service_user);
CREATE TABLE IF NOT EXISTS plugins
(
id TEXT NOT NULL PRIMARY KEY,
officiel INTEGER NOT NULL DEFAULT 0,
nom TEXT NOT NULL,
description TEXT NULL,
auteur TEXT NULL,
url TEXT NULL,
version TEXT NOT NULL,
menu INTEGER NOT NULL DEFAULT 0,
menu_condition TEXT NULL,
config TEXT NULL
);
CREATE TABLE IF NOT EXISTS plugins_signaux
-- Association entre plugins et signaux (hooks)
(
signal TEXT NOT NULL,
plugin TEXT NOT NULL REFERENCES plugins (id),
callback TEXT NOT NULL,
PRIMARY KEY (signal, plugin)
);
CREATE TABLE IF NOT EXISTS fichiers
-- Données sur les fichiers
(
id INTEGER NOT NULL PRIMARY KEY,
nom TEXT NOT NULL, -- nom de fichier (par exemple image1234.jpeg)
type TEXT NULL, -- Type MIME
image INTEGER NOT NULL DEFAULT 0, -- 1 = image reconnue
datetime TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(datetime) IS NOT NULL AND datetime(datetime) = datetime), -- Date d'ajout ou mise à jour du fichier
id_contenu INTEGER NOT NULL REFERENCES fichiers_contenu (id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS fichiers_date ON fichiers (datetime);
CREATE TABLE IF NOT EXISTS fichiers_contenu
-- Contenu des fichiers
(
id INTEGER NOT NULL PRIMARY KEY,
hash TEXT NOT NULL, -- Hash SHA1 du contenu du fichier
taille INTEGER NOT NULL, -- Taille en octets
contenu BLOB NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS fichiers_hash ON fichiers_contenu (hash);
CREATE TABLE IF NOT EXISTS fichiers_membres
-- Associations entre fichiers et membres (photo de profil par exemple)
(
fichier INTEGER NOT NULL REFERENCES fichiers (id) ON DELETE CASCADE,
id INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
PRIMARY KEY(fichier, id)
);
CREATE TABLE IF NOT EXISTS fichiers_wiki_pages
-- Associations entre fichiers et pages du wiki
(
fichier INTEGER NOT NULL REFERENCES fichiers (id) ON DELETE CASCADE,
id INTEGER NOT NULL REFERENCES wiki_pages (id) ON DELETE CASCADE,
PRIMARY KEY(fichier, id)
);
CREATE TABLE IF NOT EXISTS fichiers_acc_transactions
-- Associations entre fichiers et journal de compta (pièce comptable par exemple)
(
fichier INTEGER NOT NULL REFERENCES fichiers (id) ON DELETE CASCADE,
id INTEGER NOT NULL REFERENCES acc_transactions (id) ON DELETE CASCADE,
PRIMARY KEY(fichier, id)
);
CREATE TABLE IF NOT EXISTS recherches
-- Recherches enregistrées
(
id INTEGER NOT NULL PRIMARY KEY,
id_membre INTEGER NULL REFERENCES membres (id) ON DELETE CASCADE, -- Si non NULL, alors la recherche ne sera visible que par le membre associé
intitule TEXT NOT NULL,
creation TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (datetime(creation) IS NOT NULL AND datetime(creation) = creation),
cible TEXT NOT NULL, -- "membres" ou "compta"
type TEXT NOT NULL, -- "json" ou "sql"
contenu TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS compromised_passwords_cache
-- Cache des hash de mots de passe compromis
(
hash TEXT NOT NULL PRIMARY KEY
);
CREATE TABLE IF NOT EXISTS compromised_passwords_cache_ranges
-- Cache des préfixes de mots de passe compromis
(
prefix TEXT NOT NULL PRIMARY KEY,
date INTEGER NOT NULL
);

1760
archives/plan_comptable.json Normal file

File diff suppressed because it is too large Load diff