From 1076582fb461ddf127af16280938f8843385c378 Mon Sep 17 00:00:00 2001 From: Glenn Thompson Date: Thu, 11 Sep 2025 08:54:12 +0300 Subject: [PATCH] Implement RADIANCE database integration - Add database collections for tracks and playlists - Configure proper RADIANCE field types (:text, :integer) - Add r-data-model dependency for database backend - Fix build-executable.lisp RADIANCE environment handling - Update admin dashboard to show real database connection status - Database now initializes successfully on server startup --- asteroid.asd | 3 ++- asteroid.lisp | 30 +++++++++++++++++++++++++++++- build-executable.lisp | 11 +++++++++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/asteroid.asd b/asteroid.asd index c3b2630..59d02b0 100644 --- a/asteroid.asd +++ b/asteroid.asd @@ -14,7 +14,8 @@ :spinneret :cl-json :dexador - :lass) + :lass + :r-data-model) :pathname "./" :components ((:file "app-utils") (:file "module") diff --git a/asteroid.lisp b/asteroid.lisp index 7a32ad1..3fd3665 100644 --- a/asteroid.lisp +++ b/asteroid.lisp @@ -14,6 +14,32 @@ ;; Configuration (defparameter *server-port* 8080) +(defparameter *music-library-path* + (merge-pathnames "music/library/" + (asdf:system-source-directory :asteroid))) +(defparameter *supported-formats* '("mp3" "flac" "ogg" "wav")) + +;; Database initialization - must be in db:connected trigger +(define-trigger db:connected () + "Initialize database collections when database connects" + (unless (db:collection-exists-p "tracks") + (db:create "tracks" '((title :text) + (artist :text) + (album :text) + (duration :integer) + (file-path :text) + (format :text) + (bitrate :integer) + (added-date :integer) + (play-count :integer)))) + + (unless (db:collection-exists-p "playlists") + (db:create "playlists" '((name :text) + (description :text) + (created-date :integer) + (track-ids :text)))) + + (format t "Database collections initialized~%")) ;; Define CLIP attribute processor for data-text (clip:define-attribute-processor data-text (node value) @@ -67,7 +93,9 @@ (plump:parse (alexandria:read-file-into-string template-path)) :title "Asteroid Radio - Admin Dashboard" :server-status "🟢 Running" - :database-status "🟡 Not Connected" + :database-status (handler-case + (if (db:connected-p) "🟢 Connected" "🔴 Disconnected") + (error () "🔴 No Database Backend")) :liquidsoap-status "🔴 Not Running" :icecast-status "🔴 Not Running"))) diff --git a/build-executable.lisp b/build-executable.lisp index 48172a4..38a85c0 100755 --- a/build-executable.lisp +++ b/build-executable.lisp @@ -6,8 +6,15 @@ ;; Build script for creating asteroid executable using save-lisp-and-die ;; ASDF will automatically find the project via source-registry.conf -;; Load the system -(ql:quickload :asteroid) +;; Load RADIANCE first, then handle environment +(ql:quickload :radiance) + +;; Load the system with RADIANCE environment handling +(handler-bind ((radiance-core:environment-not-set + (lambda (c) + (declare (ignore c)) + (invoke-restart 'continue)))) + (ql:quickload :asteroid)) ;; Define the main function for the executable (defun main ()