Permalink
Browse files

Auto DB stuff for mythmusic.

git-svn-id: http://svn.mythtv.org/svn/trunk@2457 7dbf422c-18fa-0310-86e9-fd20926502f2
  • Loading branch information...
1 parent f6ca48b commit 751be04c635882cee17fc5c36cd8809b37521dab Isaac Richards committed Oct 30, 2003
@@ -69,9 +69,6 @@ Follow this by a 'make install'. It'll put a 'libmythmusic.so' plugin in your
MythMusic will also read the mysql.txt settings file used by MythTV, so any
changes you made to those will be carried over into this.
-The final thing to do is add the musicdb/metadata.sql file to your existing
-database setup from MythTV.
-
You'll want to go into the Music Settings section of the Setup item from
mythfrontend and set at least the path where your music is stored.
@@ -1,25 +1,25 @@
-UPGRADING FROM RELEASE 0.9 - 0.11
---------------------------
+UPGRADING FROM RELEASE 0.9 on up
+--------------------------------
No changes.
UPGRADING FROM RELEASE 0.8
--------------------------
-You need to run musicdb/0.8-to-0.9.sql to your database after reading the
+You need to run musicdb/old/0.8-to-0.9.sql to your database after reading the
contents of that file and editing it appropriately. Also a good idea to
delete .cddb and .cdserverrc from the home directory of whatever user
myth/mythmusic runs as on your system.
UPGRADING FROM RELEASE 0.7
--------------------------
-You need to add musicdb/0-7-to-0-8.sql to your database.
+You need to add musicdb/old/0-7-to-0-8.sql to your database.
UPGRADING FROM RELEASE 0.6
--------------------------
Nothing important has changed.
UPGRADING FROM RELEASE 0.5
--------------------------
-You need to add musicdb/0-5-to-0-6.sql to your database.
+You need to add musicdb/old/0-5-to-0-6.sql to your database.
UPGRADING FROM RELEASE 0.4
--------------------------
@@ -1,3 +0,0 @@
-#
-# No DB changes in CVS at this time
-#
@@ -1,28 +0,0 @@
-USE mythconverg;
-CREATE TABLE musicmetadata
-(
- intid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
- artist VARCHAR(128) NOT NULL,
- album VARCHAR(128) NOT NULL,
- title VARCHAR(128) NOT NULL,
- genre VARCHAR(128) NOT NULL,
- year INT UNSIGNED NOT NULL,
- tracknum INT UNSIGNED NOT NULL,
- length INT UNSIGNED NOT NULL,
- filename TEXT NOT NULL,
- rating INT UNSIGNED NOT NULL DEFAULT 5,
- lastplay TIMESTAMP NOT NULL,
- playcount INT UNSIGNED NOT NULL DEFAULT 0,
- INDEX (artist),
- INDEX (album),
- INDEX (title),
- INDEX (genre)
-);
-CREATE TABLE musicplaylist
-(
- playlistid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
- name VARCHAR(128) NOT NULL,
- hostname VARCHAR(255),
- songlist TEXT NOT NULL
-);
-
@@ -0,0 +1,86 @@
+#include <qsqldatabase.h>
+#include <qstring.h>
+
+#include <iostream>
+using namespace std;
+
+#include "dbcheck.h"
+
+#include "mythtv/mythcontext.h"
+
+const QString currentDatabaseVersion = "1000";
+
+static void UpdateDBVersionNumber(const QString &newnumber)
+{
+ QSqlDatabase *db_conn = QSqlDatabase::database();
+
+ db_conn->exec("DELETE FROM settings WHERE value='MusicDBSchemaVer';");
+ db_conn->exec(QString("INSERT INTO settings (value, data, hostname) "
+ "VALUES ('MusicDBSchemaVer', %1, NULL);")
+ .arg(newnumber));
+}
+
+static void performActualUpdate(const QString updates[], QString version,
+ QString &dbver)
+{
+ QSqlDatabase *db_conn = QSqlDatabase::database();
+
+ VERBOSE(VB_ALL, QString("Upgrading to MythMusic schema version ") +
+ version);
+
+ int counter = 0;
+ QString thequery = updates[counter];
+
+ while (thequery != "")
+ {
+ db_conn->exec(thequery);
+ counter++;
+ thequery = updates[counter];
+ }
+
+ UpdateDBVersionNumber(version);
+ dbver = version;
+}
+
+void UpgradeMusicDatabaseSchema(void)
+{
+ QString dbver = gContext->GetSetting("MusicDBSchemaVer");
+
+ if (dbver == currentDatabaseVersion)
+ return;
+
+ if (dbver == "")
+ {
+ VERBOSE(VB_ALL, "Inserting MythMusic initial database information.");
+
+ const QString updates[] = {
+"CREATE TABLE IF NOT EXISTS musicmetadata ("
+" intid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,"
+" artist VARCHAR(128) NOT NULL,"
+" album VARCHAR(128) NOT NULL,"
+" title VARCHAR(128) NOT NULL,"
+" genre VARCHAR(128) NOT NULL,"
+" year INT UNSIGNED NOT NULL,"
+" tracknum INT UNSIGNED NOT NULL,"
+" length INT UNSIGNED NOT NULL,"
+" filename TEXT NOT NULL,"
+" rating INT UNSIGNED NOT NULL DEFAULT 5,"
+" lastplay TIMESTAMP NOT NULL,"
+" playcount INT UNSIGNED NOT NULL DEFAULT 0,"
+" INDEX (artist),"
+" INDEX (album),"
+" INDEX (title),"
+" INDEX (genre)"
+");",
+"CREATE TABLE IF NOT EXISTS musicplaylist ("
+" playlistid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,"
+" name VARCHAR(128) NOT NULL,"
+" hostname VARCHAR(255),"
+" songlist TEXT NOT NULL"
+");",
+""
+};
+ performActualUpdate(updates, "1000", dbver);
+ }
+}
+
@@ -0,0 +1,7 @@
+#ifndef DBCHECK_H_
+#define DBCHECK_H_
+
+void UpgradeMusicDatabaseSchema(void);
+
+#endif
+
@@ -19,6 +19,7 @@ using namespace std;
#include "cdrip.h"
#include "playlist.h"
#include "globalsettings.h"
+#include "dbcheck.h"
#include <mythtv/themedmenu.h>
#include <mythtv/mythcontext.h>
@@ -365,6 +366,7 @@ int mythplugin_init(const char *libversion)
MYTH_BINARY_VERSION))
return -1;
+ UpgradeMusicDatabaseSchema();
GeneralSettings general;
general.load(QSqlDatabase::database());
@@ -31,15 +31,15 @@ HEADERS += decoder.h flacdecoder.h flacencoder.h maddecoder.h mainvisual.h
HEADERS += metadata.h playbackbox.h playlist.h polygon.h output.h recycler.h
HEADERS += streaminput.h synaesthesia.h encoder.h visualize.h
HEADERS += treecheckitem.h visual.h vorbisdecoder.h vorbisencoder.h polygon.h
-HEADERS += bumpscope.h globalsettings.h lameencoder.h
+HEADERS += bumpscope.h globalsettings.h lameencoder.h dbcheck.h
HEADERS += goom/filters.h goom/goomconfig.h goom/goom_core.h goom/graphic.h
HEADERS += goom/ifs.h goom/lines.h goom/mythgoom.h goom/drawmethods.h
HEADERS += goom/mmx.h goom/mathtools.h goom/tentacle3d.h goom/v3d.h
SOURCES += audiooutput.cpp cddecoder.cpp cdrip.cpp databasebox.cpp decoder.cpp
SOURCES += flacdecoder.cpp flacencoder.cpp maddecoder.cpp main.cpp
SOURCES += mainvisual.cpp metadata.cpp playbackbox.cpp playlist.cpp output.cpp
-SOURCES += recycler.cpp streaminput.cpp encoder.cpp resample.c
+SOURCES += recycler.cpp streaminput.cpp encoder.cpp resample.c dbcheck.cpp
SOURCES += synaesthesia.cpp treecheckitem.cpp vorbisdecoder.cpp lameencoder.cpp
SOURCES += vorbisencoder.cpp visualize.cpp bumpscope.cpp globalsettings.cpp
SOURCES += goom/filters.c goom/goom_core.c goom/graphic.c goom/tentacle3d.c

0 comments on commit 751be04

Please sign in to comment.