[mythtv] [PATCH] prompt before upgrading database
Andrew Dennison
andrew-lists at optusnet.com.au
Sun Oct 17 12:15:04 UTC 2004
I recnetly had an "incident" where I ran a cvs version of setup on my
main system. The database schema was upgraded a few levels before I had
realised what I'd done:0
Attached patch (dbcheck0.diff) makes setup prompt before it starts the
upgrade.
dbcheck1.diff prevents mythbackend and mythfrontend from also updating
the db - forces you to run setup if db isn't up to date. This may? not
be acceptable so it's split into a separate patch.
Maybe this will help others who start upgrades late at night too.
Andrew
-------------- next part --------------
Index: setup/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/setup/main.cpp,v
retrieving revision 1.46
diff -u -b -B -w -p -r1.46 main.cpp
--- setup/main.cpp 8 May 2004 19:58:31 -0000 1.46
+++ setup/main.cpp 17 Oct 2004 11:59:32 -0000
@@ -134,6 +134,13 @@ int main(int argc, char *argv[])
return -1;
}
+ if (CheckTVDatabaseSchema() == dbOld) {
+ QString response = getResponse("Database needs updating, continue?",
+ "yes");
+ if (response.left(1).lower() != "y")
+ return -1;
+ }
+
UpgradeTVDatabaseSchema();
translator->load(PREFIX + QString("/share/mythtv/i18n/mythfrontend_") +
Index: libs/libmythtv/dbcheck.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/dbcheck.cpp,v
retrieving revision 1.67
diff -u -b -B -w -p -r1.67 dbcheck.cpp
--- libs/libmythtv/dbcheck.cpp 13 Oct 2004 01:49:55 -0000 1.67
+++ libs/libmythtv/dbcheck.cpp 17 Oct 2004 11:59:35 -0000
@@ -52,6 +52,17 @@ void performActualUpdate(const QString u
dbver = version;
}
+enum dbState CheckTVDatabaseSchema(void)
+{
+ QString dbver = gContext->GetSetting("DBSchemaVer");
+
+ if (dbver == "")
+ return dbUninitialised;
+ if (dbver == currentDatabaseVersion)
+ return dbCurrent;
+ return dbOld;
+}
+
void InitializeDatabase(void);
void UpgradeTVDatabaseSchema(void)
Index: libs/libmythtv/dbcheck.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/dbcheck.h,v
retrieving revision 1.1
diff -u -b -B -w -p -r1.1 dbcheck.h
--- libs/libmythtv/dbcheck.h 17 Sep 2003 16:53:55 -0000 1.1
+++ libs/libmythtv/dbcheck.h 17 Oct 2004 11:59:35 -0000
@@ -4,5 +4,8 @@
// Call after initialing the main db connection.
void UpgradeTVDatabaseSchema(void);
+enum dbState { dbCurrent, dbOld, dbUninitialised };
+enum dbState CheckTVDatabaseSchema(void);
+
#endif
-------------- next part --------------
Index: programs/mythbackend/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/main.cpp,v
retrieving revision 1.76
diff -u -b -B -w -p -r1.76 main.cpp
--- programs/mythbackend/main.cpp 13 Oct 2004 01:49:55 -0000 1.76
+++ programs/mythbackend/main.cpp 17 Oct 2004 12:00:13 -0000
@@ -470,7 +470,10 @@ int main(int argc, char **argv)
return -1;
}
- UpgradeTVDatabaseSchema();
+ if (CheckTVDatabaseSchema() != dbCurrent) {
+ cerr << "Database needs updating, run setup\n";
+ return -1;
+ }
if (printsched || testsched)
{
Index: programs/mythfrontend/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/main.cpp,v
retrieving revision 1.167
diff -u -b -B -w -p -r1.167 main.cpp
--- programs/mythfrontend/main.cpp 10 Oct 2004 22:56:57 -0000 1.167
+++ programs/mythfrontend/main.cpp 17 Oct 2004 12:00:14 -0000
@@ -933,7 +933,10 @@ int main(int argc, char **argv)
return -1;
}
- UpgradeTVDatabaseSchema();
+ if (CheckTVDatabaseSchema() != dbCurrent) {
+ cerr << "Database needs updating, run setup\n";
+ return -1;
+ }
VERBOSE(VB_ALL, QString("%1 version: %2 www.mythtv.org")
.arg(binname).arg(MYTH_BINARY_VERSION));
More information about the mythtv-dev
mailing list