playlist edition

This commit is contained in:
Gabriel Radureau
2025-10-13 16:53:15 +02:00
parent 0fa5a30809
commit 65d63ec828
15 changed files with 550 additions and 137 deletions

View File

@@ -1,17 +1,30 @@
-- Table des playlists
-- =========================================================
-- Table principale des playlists
-- =========================================================
CREATE TABLE IF NOT EXISTS playlists (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(100) UNIQUE NOT NULL,
name TEXT UNIQUE NOT NULL,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
type TEXT CHECK (type IN ('manual', 'dynamic')) NOT NULL DEFAULT 'manual',
rules_json TEXT, -- JSON décrivant les règles pour les playlists dynamiques
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Table d'association entre vidéos et playlists (relation many-to-many)
-- =========================================================
-- Table dassociation vidéos ↔ playlists (manuelles uniquement)
-- =========================================================
CREATE TABLE IF NOT EXISTS video_playlists (
video_file_name VARCHAR(255),
playlist_id INTEGER,
position INTEGER, -- pour gérer lordre dans la playlist
video_file_name TEXT NOT NULL,
playlist_id INTEGER NOT NULL,
position INTEGER DEFAULT 0, -- ordre dans la playlist
PRIMARY KEY (video_file_name, playlist_id),
FOREIGN KEY (video_file_name) REFERENCES videos(file_name) ON DELETE CASCADE,
FOREIGN KEY (playlist_id) REFERENCES playlists(id) ON DELETE CASCADE
);
);
-- =========================================================
-- Index pour accélérer les recherches
-- =========================================================
CREATE INDEX IF NOT EXISTS idx_playlist_type ON playlists(type);
CREATE INDEX IF NOT EXISTS idx_video_playlists_playlist ON video_playlists(playlist_id);

10
model/videos_summary.sql Normal file
View File

@@ -0,0 +1,10 @@
CREATE TABLE IF NOT EXISTS video_summary AS
SELECT v.file_name,
GROUP_CONCAT(DISTINCT l.name) AS labels,
GROUP_CONCAT(DISTINCT p.name) AS playlists
FROM videos v
LEFT JOIN video_labels vl ON vl.video_file_name = v.file_name
LEFT JOIN labels l ON l.id = vl.label_id
LEFT JOIN video_playlists vp ON vp.video_file_name = v.file_name
LEFT JOIN playlists p ON p.id = vp.playlist_id
GROUP BY v.file_name;