From 38f832e8d810b6e3831cac5b85d5e6b12ac39199 Mon Sep 17 00:00:00 2001 From: Annika Backstrom Date: Tue, 17 Dec 2019 13:50:11 -0500 Subject: [PATCH] Add script to migrate from file to sqlite backend This is the script I used to convert all existing media from the file backend to the sqlite backend. I'm saving it for posterity. It outputs shell commands to stdout, and SQL commands to stderr. These can be piped to different files, examined, and run independently, e.g. $ ./file-to-sqlite.sh 1>files.sh 2>files.sql $ sh files.sh $ sqlite3 jukebox.sqlite3 files.sql --- archive/file-to-sqlite.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 archive/file-to-sqlite.sh diff --git a/archive/file-to-sqlite.sh b/archive/file-to-sqlite.sh new file mode 100755 index 0000000..d6736f1 --- /dev/null +++ b/archive/file-to-sqlite.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +ls media/*\ -\ *.mp3 | while read line ; do + UUID=$(./jukebox/node_modules/.bin/uuid v4) + echo "mv \"$line\" \"media/$UUID\"" + + FILE=$(basename "$line" ".mp3") + set -- $FILE + + TAG=${@:1:1} + LABEL=${@:3} + echo "INSERT INTO tags (tag) VALUES (\"$TAG\");" 1>>/dev/stderr; + echo "INSERT INTO library (tag, label, uuid) VALUES (\"$TAG\", \"$LABEL\", \"$UUID\");" 1>>/dev/stderr; +done