mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 11:09:18 +02:00
Phase 1: Consolidate shared infrastructure - Create shared/ directory for common code - Consolidate Database.php from front-backend and formulaire into unified shared/Database.php - Smart path detection for test.db vs posterg.db - Secure search with wildcard escaping and input validation - Support both singleton and direct instantiation patterns - Full CRUD methods for admin functionality - Move RateLimit.php to shared/ (30 requests/min) - Update all require paths across apps to use shared/ Phase 2: Reorganize directory structure - Rename front-backend/ → apps/public/ - Rename formulaire/ → apps/admin/ - Rename db/ → database/ - Update all file paths for new structure - Create root .gitignore excluding databases, cache, logs Implement secure search feature - Add apps/public/search.php with full-text search across theses - Search filters: query, year, orientation, AP program, keywords - Security features: - SQL injection prevention (prepared statements) - Wildcard injection prevention (escape % and _) - Input validation (max 200 chars, year range 1900-2100) - Rate limiting (30 req/min per IP) - Pagination limited to 100 results/page - XSS protection (htmlspecialchars on output) Add comprehensive test suite - Create apps/public/tests/ with proper structure - tests/Integration/SearchTest.php - 12 search scenarios - tests/Security/SecurityTest.php - vulnerability testing - tests/Unit/RateLimitTest.php - rate limit behavior - Create database/fixtures/CreateTestDatabase.php - Add apps/public/run-tests.php test runner - All tests passing (4/4 suites) Update deployment configuration - Rename justfile 'sync' recipe to 'deploy' - Create deploy group with separate deploy-public and deploy-admin - Add test-deploy recipe for test database - Exclude *.db, tests/, cache/, *.md from production deploy - Deploy shared/ to both public and admin locations Stats: +4482 insertions, -654 deletions across 72 files
386 lines
13 KiB
SQL
386 lines
13 KiB
SQL
-- Post-ERG Thesis Database Schema
|
|
-- SQLite Database for managing final thesis projects (TFE) and doctoral theses
|
|
|
|
-- ============================================================================
|
|
-- CORE ENTITIES
|
|
-- ============================================================================
|
|
|
|
-- Students/Authors table
|
|
CREATE TABLE IF NOT EXISTS authors (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL,
|
|
email TEXT,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- Supervisors/Promoters table
|
|
CREATE TABLE IF NOT EXISTS supervisors (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- ============================================================================
|
|
-- PREDEFINED REFERENCE DATA (lookup tables)
|
|
-- ============================================================================
|
|
|
|
-- Orientations (predefined list from specifications)
|
|
CREATE TABLE IF NOT EXISTS orientations (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL UNIQUE,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- Insert predefined orientations
|
|
INSERT OR IGNORE INTO orientations (name) VALUES
|
|
('Arts Numériques'),
|
|
('Dessin'),
|
|
('Cinéma d''animation'),
|
|
('Installation-Performance'),
|
|
('Peinture'),
|
|
('Photographie'),
|
|
('Sculpture'),
|
|
('Vidéographie'),
|
|
('Graphisme'),
|
|
('Typographie'),
|
|
('Design Numérique'),
|
|
('Illustration'),
|
|
('Bande-Dessinée'),
|
|
('Sérigraphie'),
|
|
('Gravure');
|
|
|
|
-- AP (Ateliers Pratiques) - predefined list
|
|
CREATE TABLE IF NOT EXISTS ap_programs (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL UNIQUE,
|
|
code TEXT,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- Insert predefined AP programs
|
|
INSERT OR IGNORE INTO ap_programs (name, code) VALUES
|
|
('Narration Spéculative', NULL),
|
|
('Design et Politique du Multiple', 'DPM'),
|
|
('Atelier Pratiques Situées', 'APS'),
|
|
('Lieux, Interdisciplinarités, Écologie, Nécessité, Systèmes', 'LIENS');
|
|
|
|
-- Master finality types
|
|
CREATE TABLE IF NOT EXISTS finality_types (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL UNIQUE,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
INSERT OR IGNORE INTO finality_types (name) VALUES
|
|
('Approfondi'),
|
|
('Enseignement'),
|
|
('Spécialisé');
|
|
|
|
-- Languages
|
|
CREATE TABLE IF NOT EXISTS languages (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL UNIQUE,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
INSERT OR IGNORE INTO languages (name) VALUES
|
|
('Français'),
|
|
('Anglais');
|
|
|
|
-- Format types (can select multiple)
|
|
CREATE TABLE IF NOT EXISTS format_types (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL UNIQUE,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
INSERT OR IGNORE INTO format_types (name) VALUES
|
|
('Site web'),
|
|
('Audio'),
|
|
('Vidéo'),
|
|
('Performance'),
|
|
('Objet éditorial'),
|
|
('Installation'),
|
|
('Autre');
|
|
|
|
-- Keywords (expandable list)
|
|
CREATE TABLE IF NOT EXISTS keywords (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
keyword TEXT NOT NULL UNIQUE,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- Access authorization types
|
|
CREATE TABLE IF NOT EXISTS access_types (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL UNIQUE,
|
|
description TEXT,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
INSERT OR IGNORE INTO access_types (name, description) VALUES
|
|
('Libre', 'TFE en libre accès à tout le monde sur la plateforme et en bibliothèque'),
|
|
('Interne', 'TFE accessible uniquement sur place en physique. Une note descriptive est disponible sur le site'),
|
|
('Interdit', 'TFE non disponible en physique ni sur le site. Une note descriptive est disponible sur le site');
|
|
|
|
-- License types
|
|
CREATE TABLE IF NOT EXISTS license_types (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL UNIQUE,
|
|
description TEXT,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- ============================================================================
|
|
-- MAIN THESIS TABLE
|
|
-- ============================================================================
|
|
|
|
CREATE TABLE IF NOT EXISTS theses (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
identifier TEXT UNIQUE, -- e.g., "2025-002"
|
|
|
|
-- Basic information
|
|
title TEXT NOT NULL,
|
|
subtitle TEXT,
|
|
year INTEGER NOT NULL,
|
|
|
|
-- Type of work
|
|
is_doctoral BOOLEAN DEFAULT 0, -- 0 for TFE, 1 for doctoral thesis
|
|
|
|
-- Academic details
|
|
orientation_id INTEGER,
|
|
ap_program_id INTEGER,
|
|
finality_id INTEGER,
|
|
|
|
-- Content
|
|
synopsis TEXT, -- ~200 words
|
|
context_note TEXT, -- Note added by jury president (max 150 words)
|
|
remarks TEXT, -- Internal remarks
|
|
|
|
-- Duration/size
|
|
duration_minutes INTEGER, -- For audio/video works
|
|
duration_pages INTEGER, -- For written works
|
|
file_size_info TEXT, -- e.g., "128 pages", "78 pages + ?? minutes"
|
|
|
|
-- Access and licensing
|
|
access_type_id INTEGER,
|
|
license_id INTEGER,
|
|
|
|
-- Jury information
|
|
jury_points DECIMAL(4,2), -- Points out of 20
|
|
jury_note_added BOOLEAN DEFAULT 0, -- Whether jury president added a note
|
|
|
|
-- Publication status
|
|
submitted_at DATETIME, -- When student submitted
|
|
defense_date DATETIME, -- Date of defense/soutenance
|
|
published_at DATETIME, -- When made public (after jury review)
|
|
is_published BOOLEAN DEFAULT 0,
|
|
|
|
-- External links
|
|
baiu_link TEXT, -- Link to institutional repository
|
|
|
|
-- Timestamps
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
-- Foreign keys
|
|
FOREIGN KEY (orientation_id) REFERENCES orientations(id),
|
|
FOREIGN KEY (ap_program_id) REFERENCES ap_programs(id),
|
|
FOREIGN KEY (finality_id) REFERENCES finality_types(id),
|
|
FOREIGN KEY (access_type_id) REFERENCES access_types(id),
|
|
FOREIGN KEY (license_id) REFERENCES license_types(id)
|
|
);
|
|
|
|
-- ============================================================================
|
|
-- JUNCTION TABLES (Many-to-Many relationships)
|
|
-- ============================================================================
|
|
|
|
-- Authors per thesis (can have multiple authors)
|
|
CREATE TABLE IF NOT EXISTS thesis_authors (
|
|
thesis_id INTEGER NOT NULL,
|
|
author_id INTEGER NOT NULL,
|
|
author_order INTEGER DEFAULT 1, -- Order of authors if multiple
|
|
PRIMARY KEY (thesis_id, author_id),
|
|
FOREIGN KEY (thesis_id) REFERENCES theses(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (author_id) REFERENCES authors(id) ON DELETE CASCADE
|
|
);
|
|
|
|
-- Supervisors per thesis (can have multiple promoters)
|
|
CREATE TABLE IF NOT EXISTS thesis_supervisors (
|
|
thesis_id INTEGER NOT NULL,
|
|
supervisor_id INTEGER NOT NULL,
|
|
supervisor_order INTEGER DEFAULT 1,
|
|
PRIMARY KEY (thesis_id, supervisor_id),
|
|
FOREIGN KEY (thesis_id) REFERENCES theses(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (supervisor_id) REFERENCES supervisors(id) ON DELETE CASCADE
|
|
);
|
|
|
|
-- Languages per thesis (can be multilingual)
|
|
CREATE TABLE IF NOT EXISTS thesis_languages (
|
|
thesis_id INTEGER NOT NULL,
|
|
language_id INTEGER NOT NULL,
|
|
PRIMARY KEY (thesis_id, language_id),
|
|
FOREIGN KEY (thesis_id) REFERENCES theses(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (language_id) REFERENCES languages(id) ON DELETE CASCADE
|
|
);
|
|
|
|
-- Formats per thesis (can have multiple formats)
|
|
CREATE TABLE IF NOT EXISTS thesis_formats (
|
|
thesis_id INTEGER NOT NULL,
|
|
format_id INTEGER NOT NULL,
|
|
PRIMARY KEY (thesis_id, format_id),
|
|
FOREIGN KEY (thesis_id) REFERENCES theses(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (format_id) REFERENCES format_types(id) ON DELETE CASCADE
|
|
);
|
|
|
|
-- Keywords per thesis (max 10 as per specs)
|
|
CREATE TABLE IF NOT EXISTS thesis_keywords (
|
|
thesis_id INTEGER NOT NULL,
|
|
keyword_id INTEGER NOT NULL,
|
|
PRIMARY KEY (thesis_id, keyword_id),
|
|
FOREIGN KEY (thesis_id) REFERENCES theses(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (keyword_id) REFERENCES keywords(id) ON DELETE CASCADE
|
|
);
|
|
|
|
-- ============================================================================
|
|
-- FILE ATTACHMENTS
|
|
-- ============================================================================
|
|
|
|
CREATE TABLE IF NOT EXISTS thesis_files (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
thesis_id INTEGER NOT NULL,
|
|
file_type TEXT NOT NULL, -- 'main', 'annex', 'written_part', 'other'
|
|
file_path TEXT NOT NULL,
|
|
file_name TEXT NOT NULL,
|
|
file_size INTEGER, -- in bytes
|
|
mime_type TEXT,
|
|
description TEXT,
|
|
uploaded_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (thesis_id) REFERENCES theses(id) ON DELETE CASCADE
|
|
);
|
|
|
|
-- ============================================================================
|
|
-- STATIC PAGES / CONTENT MANAGEMENT
|
|
-- ============================================================================
|
|
|
|
-- For managing editable static pages (charte, about, licenses, contact)
|
|
CREATE TABLE IF NOT EXISTS pages (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
slug TEXT NOT NULL UNIQUE, -- 'charte', 'about', 'licenses', 'contact'
|
|
title TEXT NOT NULL,
|
|
content TEXT, -- Markdown or HTML content
|
|
is_published BOOLEAN DEFAULT 1,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- Initialize default pages
|
|
INSERT OR IGNORE INTO pages (slug, title, content) VALUES
|
|
('charte', 'Charte', 'Contenu à venir'),
|
|
('about', 'À propos', 'Contenu à venir'),
|
|
('licenses', 'Licences', 'Contenu à venir'),
|
|
('contact', 'Contact', 'Contenu à venir');
|
|
|
|
-- ============================================================================
|
|
-- INDEXES for performance
|
|
-- ============================================================================
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_theses_year ON theses(year);
|
|
CREATE INDEX IF NOT EXISTS idx_theses_published ON theses(is_published);
|
|
CREATE INDEX IF NOT EXISTS idx_theses_identifier ON theses(identifier);
|
|
CREATE INDEX IF NOT EXISTS idx_theses_orientation ON theses(orientation_id);
|
|
CREATE INDEX IF NOT EXISTS idx_theses_ap_program ON theses(ap_program_id);
|
|
CREATE INDEX IF NOT EXISTS idx_theses_access_type ON theses(access_type_id);
|
|
CREATE INDEX IF NOT EXISTS idx_authors_email ON authors(email);
|
|
CREATE INDEX IF NOT EXISTS idx_thesis_authors_thesis ON thesis_authors(thesis_id);
|
|
CREATE INDEX IF NOT EXISTS idx_thesis_authors_author ON thesis_authors(author_id);
|
|
CREATE INDEX IF NOT EXISTS idx_thesis_keywords_thesis ON thesis_keywords(thesis_id);
|
|
CREATE INDEX IF NOT EXISTS idx_thesis_keywords_keyword ON thesis_keywords(keyword_id);
|
|
|
|
-- ============================================================================
|
|
-- TRIGGERS for automatic timestamp updates
|
|
-- ============================================================================
|
|
|
|
CREATE TRIGGER IF NOT EXISTS update_theses_timestamp
|
|
AFTER UPDATE ON theses
|
|
BEGIN
|
|
UPDATE theses SET updated_at = CURRENT_TIMESTAMP WHERE id = NEW.id;
|
|
END;
|
|
|
|
CREATE TRIGGER IF NOT EXISTS update_authors_timestamp
|
|
AFTER UPDATE ON authors
|
|
BEGIN
|
|
UPDATE authors SET updated_at = CURRENT_TIMESTAMP WHERE id = NEW.id;
|
|
END;
|
|
|
|
CREATE TRIGGER IF NOT EXISTS update_supervisors_timestamp
|
|
AFTER UPDATE ON supervisors
|
|
BEGIN
|
|
UPDATE supervisors SET updated_at = CURRENT_TIMESTAMP WHERE id = NEW.id;
|
|
END;
|
|
|
|
CREATE TRIGGER IF NOT EXISTS update_pages_timestamp
|
|
AFTER UPDATE ON pages
|
|
BEGIN
|
|
UPDATE pages SET updated_at = CURRENT_TIMESTAMP WHERE id = NEW.id;
|
|
END;
|
|
|
|
-- ============================================================================
|
|
-- VIEWS for common queries
|
|
-- ============================================================================
|
|
|
|
-- Full thesis information view
|
|
CREATE VIEW IF NOT EXISTS v_theses_full AS
|
|
SELECT
|
|
t.id,
|
|
t.identifier,
|
|
t.title,
|
|
t.subtitle,
|
|
t.year,
|
|
t.is_doctoral,
|
|
o.name as orientation,
|
|
ap.name as ap_program,
|
|
ft.name as finality_type,
|
|
t.synopsis,
|
|
t.context_note,
|
|
t.duration_minutes,
|
|
t.duration_pages,
|
|
t.file_size_info,
|
|
at.name as access_type,
|
|
lt.name as license_type,
|
|
t.jury_points,
|
|
t.submitted_at,
|
|
t.defense_date,
|
|
t.published_at,
|
|
t.is_published,
|
|
t.baiu_link,
|
|
GROUP_CONCAT(DISTINCT a.name) as authors,
|
|
GROUP_CONCAT(DISTINCT s.name) as supervisors,
|
|
GROUP_CONCAT(DISTINCT l.name) as languages,
|
|
GROUP_CONCAT(DISTINCT fmt.name) as formats,
|
|
GROUP_CONCAT(DISTINCT k.keyword) as keywords
|
|
FROM theses t
|
|
LEFT JOIN orientations o ON t.orientation_id = o.id
|
|
LEFT JOIN ap_programs ap ON t.ap_program_id = ap.id
|
|
LEFT JOIN finality_types ft ON t.finality_id = ft.id
|
|
LEFT JOIN access_types at ON t.access_type_id = at.id
|
|
LEFT JOIN license_types lt ON t.license_id = lt.id
|
|
LEFT JOIN thesis_authors ta ON t.id = ta.thesis_id
|
|
LEFT JOIN authors a ON ta.author_id = a.id
|
|
LEFT JOIN thesis_supervisors ts ON t.id = ts.thesis_id
|
|
LEFT JOIN supervisors s ON ts.supervisor_id = s.id
|
|
LEFT JOIN thesis_languages tl ON t.id = tl.thesis_id
|
|
LEFT JOIN languages l ON tl.language_id = l.id
|
|
LEFT JOIN thesis_formats tf ON t.id = tf.thesis_id
|
|
LEFT JOIN format_types fmt ON tf.format_id = fmt.id
|
|
LEFT JOIN thesis_keywords tk ON t.id = tk.thesis_id
|
|
LEFT JOIN keywords k ON tk.keyword_id = k.id
|
|
GROUP BY t.id;
|
|
|
|
-- Published theses only (for public view)
|
|
CREATE VIEW IF NOT EXISTS v_theses_public AS
|
|
SELECT * FROM v_theses_full
|
|
WHERE is_published = 1;
|