db struktur

This commit is contained in:
2026-04-20 00:01:41 +02:00
parent efc30cdbb2
commit f92af40dd7
4 changed files with 90 additions and 40 deletions

View File

@@ -79,7 +79,7 @@ class LibraryManagerDialog(QDialog):
conn = sqlite3.connect(self._db_path)
conn.row_factory = sqlite3.Row
libs = conn.execute(
"SELECT id, path, last_full_scan FROM libraries "
"SELECT id, path FROM libraries "
"WHERE is_active=1 ORDER BY path"
).fetchall()
@@ -87,15 +87,16 @@ class LibraryManagerDialog(QDialog):
bpm_missing = {}
for lib in libs:
counts[lib["id"]] = conn.execute(
"SELECT COUNT(*) FROM songs "
"WHERE library_id=? AND file_missing=0",
(lib["id"],)
"SELECT COUNT(*) FROM files "
"WHERE file_missing=0 AND local_path LIKE ?",
(lib["path"] + "%",)
).fetchone()[0]
bpm_missing[lib["id"]] = conn.execute(
"SELECT COUNT(*) FROM songs "
"WHERE library_id=? AND file_missing=0 "
"AND (bpm IS NULL OR bpm=0)",
(lib["id"],)
"SELECT COUNT(*) FROM files f "
"JOIN songs s ON s.id = f.song_id "
"WHERE f.file_missing=0 AND f.local_path LIKE ? "
"AND (s.bpm IS NULL OR s.bpm=0)",
(lib["path"] + "%",)
).fetchone()[0]
conn.close()
@@ -122,9 +123,7 @@ class LibraryManagerDialog(QDialog):
lib_id = lib["id"]
path = lib["path"]
exists = Path(path).exists()
last = lib.get("last_full_scan") or "aldrig"
if isinstance(last, str) and len(last) > 16:
last = last[:16]
last = ""
frame = QFrame()
frame.setObjectName("track_display")
@@ -246,11 +245,12 @@ class LibraryManagerDialog(QDialog):
try:
conn = sqlite3.connect(self._db_path)
# Slet sange fra biblioteket
# Marker filer fra denne mappe som missing
conn.execute(
"DELETE FROM songs WHERE library_id=?", (lib["id"],)
"UPDATE files SET file_missing=1 WHERE local_path LIKE ?",
(lib["path"] + "%",)
)
# Slet selve biblioteks-rækken helt
# Slet selve biblioteks-rækken
conn.execute(
"DELETE FROM libraries WHERE id=?", (lib["id"],)
)
@@ -297,4 +297,4 @@ class LibraryManagerDialog(QDialog):
for w in list(self._workers.values()):
w.cancel()
w.wait(2000) # Vent max 2 sek på at tråden stopper
event.accept()
event.accept()

View File

@@ -505,19 +505,19 @@ class MainWindow(QMainWindow):
conn.row_factory = sqlite3.Row
rows = conn.execute("""
SELECT s.id, s.title, s.artist, s.album, s.bpm,
s.duration_sec, s.local_path, s.file_format,
s.file_missing,
s.duration_sec,
f.id as file_id, f.local_path, f.file_format, f.file_missing,
GROUP_CONCAT(d.name, ',') AS dance_names,
GROUP_CONCAT(COALESCE(dl.name,''), ',') AS dance_levels,
GROUP_CONCAT(COALESCE(d.choreographer,''), ',') AS dance_choreographers,
GROUP_CONCAT(DISTINCT ad.name) AS alt_dance_names
FROM songs s
JOIN files f ON f.song_id = s.id AND f.file_missing = 0
LEFT JOIN song_dances sd ON sd.song_id = s.id
LEFT JOIN dances d ON d.id = sd.dance_id
LEFT JOIN dance_levels dl ON dl.id = d.level_id
LEFT JOIN song_alt_dances sad ON sad.song_id = s.id
LEFT JOIN dances ad ON ad.id = sad.dance_id
WHERE s.file_missing = 0
GROUP BY s.id
ORDER BY s.artist, s.title
""").fetchall()
@@ -536,6 +536,7 @@ class MainWindow(QMainWindow):
"album": row["album"],
"bpm": row["bpm"],
"duration_sec": row["duration_sec"],
"file_id": row["file_id"],
"local_path": row["local_path"],
"file_format": row["file_format"],
"file_missing": bool(row["file_missing"]),
@@ -1476,4 +1477,4 @@ class MainWindow(QMainWindow):
self._watchdog_proc.terminate()
except Exception:
pass
event.accept()
event.accept()