mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 11:09:18 +02:00
- Add idx_theses_pub_year composite index on theses(is_published, year DESC) to schema.sql; replaces the need for the query planner to pick between the two separate idx_theses_published / idx_theses_year indexes and sort with a temp B-tree. Every public query filters on is_published=1 and orders/filters by year, so this covering index eliminates the sort pass for those queries. - Create storage/migrations/006_add_composite_index.sql and apply to both posterg.db and test.db. - Fix storage/migrations/005_add_banner.sql: the view recreation in that file still referenced the pre-migration-001 table/column names (thesis_keywords, keywords.keyword). Updated to use thesis_tags / tags tg to match the canonical schema.sql. The live DB was unaffected (migration 001 ran before 005), but the file was misleading and would fail if ever re-run from scratch.
66 lines
2.1 KiB
SQL
66 lines
2.1 KiB
SQL
-- Migration 005: Add banner_path column to theses for home page card thumbnails
|
|
|
|
ALTER TABLE theses ADD COLUMN banner_path TEXT;
|
|
|
|
-- Recreate v_theses_full to include banner_path
|
|
DROP VIEW IF EXISTS v_theses_full;
|
|
|
|
CREATE VIEW 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.license_id,
|
|
t.jury_points,
|
|
t.submitted_at,
|
|
t.defense_date,
|
|
t.published_at,
|
|
t.is_published,
|
|
t.baiu_link,
|
|
t.banner_path,
|
|
GROUP_CONCAT(DISTINCT a.name) as authors,
|
|
GROUP_CONCAT(DISTINCT s.name) as supervisors,
|
|
GROUP_CONCAT(DISTINCT CASE WHEN ts.role = 'president' THEN s.name END) as jury_president,
|
|
GROUP_CONCAT(DISTINCT CASE WHEN ts.role = 'promoteur' THEN s.name END) as jury_promoteurs,
|
|
GROUP_CONCAT(DISTINCT CASE WHEN ts.role = 'lecteur' THEN s.name END) as jury_lecteurs,
|
|
GROUP_CONCAT(DISTINCT l.name) as languages,
|
|
GROUP_CONCAT(DISTINCT fmt.name) as formats,
|
|
GROUP_CONCAT(DISTINCT tg.name) 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_tags tt ON t.id = tt.thesis_id
|
|
LEFT JOIN tags tg ON tt.tag_id = tg.id
|
|
GROUP BY t.id;
|
|
|
|
-- Recreate public view
|
|
DROP VIEW IF EXISTS v_theses_public;
|
|
|
|
CREATE VIEW v_theses_public AS
|
|
SELECT * FROM v_theses_full
|
|
WHERE is_published = 1;
|