Ticket #4625: mythtv-verify_schema_version.patch
File mythtv-verify_schema_version.patch, 6.1 KB (added by , 16 years ago) |
---|
-
libs/libmythtv/dbcheck.h
3 3 4 4 #include "mythexp.h" 5 5 6 // Used to compare the TV Database schema version against the expected version 7 MPUBLIC int CompareTVDatabaseSchemaVersion(void); 6 8 // Call after initialing the main db connection. 7 9 MPUBLIC bool UpgradeTVDatabaseSchema(void); 8 10 -
libs/libmythtv/dbcheck.cpp
435 435 return true; 436 436 } 437 437 438 /** \fn CompareTVDatabaseSchemaVersion(void) 439 * \brief Called from outside dbcheck.cpp to compare the database schema 440 * version with the expected version. 441 * 442 * If the "DBSchemaVer" property is not found (i.e. the schema has not been 443 * initialized, the function returns negative, as if the schema simply needed 444 * upgrading, so InitializeDatabase() can do its job. 445 * 446 * \return negative, 0, or positive if the schema version is less than, equal 447 * to, or greater than the expected version 448 */ 449 int CompareTVDatabaseSchemaVersion(void) 450 { 451 bool ok; 452 int databaseVersion = gContext->GetNumSetting("DBSchemaVer"); 453 int expectedVersion = currentDatabaseVersion.toInt(&ok); 454 455 if (!ok) 456 return -1; 457 458 return databaseVersion - expectedVersion; 459 } 460 438 461 /** \fn UpgradeTVDatabaseSchema(void) 439 462 * \brief Called from outside dbcheck.cpp to update the schema. 440 463 * -
programs/mythtv-setup/main.cpp
276 276 return -1; 277 277 } 278 278 279 if ((CompareTVDatabaseSchemaVersion() > 0) && 280 // MythContext::PromptForSchemaUpgrade() expertMode 281 (gContext->GetNumSetting("DBSchemaAutoUpgrade") != -1)) 282 { 283 VERBOSE(VB_IMPORTANT, "The schema version of your existing database " 284 "is newer than this version of MythTV understands. Please " 285 "ensure that you have selected the proper database server or " 286 "upgrade this and all other frontends and backends to the " 287 "same MythTV version and revision."); 288 return BACKEND_EXIT_DB_OUTOFDATE; 289 } 279 290 if (!UpgradeTVDatabaseSchema()) 280 291 { 281 292 VERBOSE(VB_IMPORTANT, "Couldn't upgrade database to new schema."); -
programs/mythbackend/main.cpp
795 795 } 796 796 797 797 gContext->ActivateSettingsCache(false); 798 if ((CompareTVDatabaseSchemaVersion() > 0) && 799 // MythContext::PromptForSchemaUpgrade() expertMode 800 (gContext->GetNumSetting("DBSchemaAutoUpgrade") != -1)) 801 { 802 VERBOSE(VB_IMPORTANT, "The schema version of your existing database " 803 "is newer than this version of MythTV understands. Please " 804 "ensure that you have selected the proper database server or " 805 "upgrade this and all other frontends and backends to the " 806 "same MythTV version and revision."); 807 return BACKEND_EXIT_DB_OUTOFDATE; 808 } 798 809 if (!UpgradeTVDatabaseSchema()) 799 810 { 800 811 VERBOSE(VB_IMPORTANT, "Couldn't upgrade database to new schema"); -
programs/mythfrontend/main.cpp
934 934 "-p or --prompt Always prompt for Mythbackend selection." << endl << 935 935 "-d or --disable-autodiscovery Never prompt for Mythbackend selection." << endl << 936 936 937 "-u or --upgrade-schema Allow mythfrontend to upgrade the database schema" << endl << 937 938 "--version Version information" << endl << 938 939 "<plugin> Initialize and run this plugin" << endl << 939 940 endl << … … 978 979 { 979 980 bool bPromptForBackend = false; 980 981 bool bBypassAutoDiscovery = false; 982 bool upgradeAllowed = false; 981 983 982 984 QString geometry = QString::null; 983 985 QString display = QString::null; … … 1231 1233 !strcmp(a.argv()[argpos],"-d" )) 1232 1234 { 1233 1235 } 1236 else if (!strcmp(a.argv()[argpos],"--upgrade-schema") || 1237 !strcmp(a.argv()[argpos],"-u" )) 1238 { 1239 upgradeAllowed = true; 1240 } 1234 1241 else if ((argpos + 1 == a.argc()) && 1235 1242 !QString(a.argv()[argpos]).startsWith("-")) 1236 1243 { … … 1314 1321 setuid(getuid()); 1315 1322 1316 1323 gContext->ActivateSettingsCache(false); 1317 if (!UpgradeTVDatabaseSchema()) 1324 int versionCheck = CompareTVDatabaseSchemaVersion(); 1325 bool notExpertMode = (gContext->GetNumSetting("DBSchemaAutoUpgrade") != -1); 1326 if (versionCheck < 0 && !upgradeAllowed && notExpertMode) 1318 1327 { 1328 VERBOSE(VB_IMPORTANT, "This version of MythTV requires an updated " 1329 "database schema. Please run mythtv-setup or mythbackend " 1330 "to update your database."); 1331 return FRONTEND_EXIT_DB_OUTOFDATE; 1332 } 1333 else if ((versionCheck > 0) && notExpertMode) 1334 { 1335 VERBOSE(VB_IMPORTANT, "The schema version of your existing database " 1336 "is newer than this version of MythTV understands. Please " 1337 "ensure that you have selected the proper database server or " 1338 "upgrade this and all other frontends and backends to the " 1339 "same MythTV version and revision."); 1340 return FRONTEND_EXIT_DB_OUTOFDATE; 1341 } 1342 if ((upgradeAllowed || !notExpertMode) && !UpgradeTVDatabaseSchema()) 1343 { 1319 1344 VERBOSE(VB_IMPORTANT, 1320 1345 "Couldn't upgrade database to new schema, exiting."); 1321 1346 return FRONTEND_EXIT_DB_OUTOFDATE;