Ticket #4625: mythtv-verify_schema_version.patch

File mythtv-verify_schema_version.patch, 6.1 KB (added by sphery <mtdean@…>, 12 years ago)
  • libs/libmythtv/dbcheck.h

     
    33
    44#include "mythexp.h"
    55
     6// Used to compare the TV Database schema version against the expected version
     7MPUBLIC int CompareTVDatabaseSchemaVersion(void);
    68// Call after initialing the main db connection.
    79MPUBLIC bool UpgradeTVDatabaseSchema(void);
    810
  • libs/libmythtv/dbcheck.cpp

     
    435435    return true;
    436436}
    437437
     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 */
     449int 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
    438461/** \fn UpgradeTVDatabaseSchema(void)
    439462 *  \brief Called from outside dbcheck.cpp to update the schema.
    440463 *
  • programs/mythtv-setup/main.cpp

     
    276276        return -1;
    277277    }
    278278
     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    }
    279290    if (!UpgradeTVDatabaseSchema())
    280291    {
    281292        VERBOSE(VB_IMPORTANT, "Couldn't upgrade database to new schema.");
  • programs/mythbackend/main.cpp

     
    795795    }
    796796
    797797    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    }
    798809    if (!UpgradeTVDatabaseSchema())
    799810    {
    800811        VERBOSE(VB_IMPORTANT, "Couldn't upgrade database to new schema");
  • programs/mythfrontend/main.cpp

     
    934934            "-p or --prompt                 Always prompt for Mythbackend selection." << endl <<
    935935            "-d or --disable-autodiscovery  Never prompt for Mythbackend selection." << endl <<
    936936
     937            "-u or --upgrade-schema         Allow mythfrontend to upgrade the database schema" << endl <<
    937938            "--version                      Version information" << endl <<
    938939            "<plugin>                       Initialize and run this plugin" << endl <<
    939940            endl <<
     
    978979{
    979980    bool bPromptForBackend    = false;
    980981    bool bBypassAutoDiscovery = false;
     982    bool upgradeAllowed = false;
    981983
    982984    QString geometry = QString::null;
    983985    QString display  = QString::null;
     
    12311233                 !strcmp(a.argv()[argpos],"-d" ))
    12321234        {
    12331235        }
     1236        else if (!strcmp(a.argv()[argpos],"--upgrade-schema") ||
     1237                 !strcmp(a.argv()[argpos],"-u" ))
     1238        {
     1239            upgradeAllowed = true;
     1240        }
    12341241        else if ((argpos + 1 == a.argc()) &&
    12351242                    !QString(a.argv()[argpos]).startsWith("-"))
    12361243        {
     
    13141321    setuid(getuid());
    13151322
    13161323    gContext->ActivateSettingsCache(false);
    1317     if (!UpgradeTVDatabaseSchema())
     1324    int versionCheck = CompareTVDatabaseSchemaVersion();
     1325    bool notExpertMode = (gContext->GetNumSetting("DBSchemaAutoUpgrade") != -1);
     1326    if (versionCheck < 0 && !upgradeAllowed && notExpertMode)
    13181327    {
     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    {
    13191344        VERBOSE(VB_IMPORTANT,
    13201345                "Couldn't upgrade database to new schema, exiting.");
    13211346        return FRONTEND_EXIT_DB_OUTOFDATE;