MythTV  master
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
SchemaUpgradeWizard Class Reference

Provides UI and helper functions for DB Schema updates. More...

#include <libmyth/schemawizard.h>

Inheritance diagram for SchemaUpgradeWizard:
[legend]
Collaboration diagram for SchemaUpgradeWizard:
[legend]

Public Member Functions

 SchemaUpgradeWizard (QString DBSchemaSetting, QString appName, QString upgradeSchemaVal)
 
 ~SchemaUpgradeWizard () override
 
MythDBBackupStatus BackupDB (void)
 Call DBUtil::BackupDB(), and store results. More...
 
int Compare (void)
 How many schema versions old is the DB? More...
 
enum MythSchemaUpgrade PromptForUpgrade (const char *name, bool upgradeAllowed, bool upgradeIfNoUI, int minDBMSmajor=0, int minDBMSminor=0, int minDBMSpoint=0)
 Query user, to prevent silent, automatic database upgrades. More...
 
- Public Member Functions inherited from DBUtil
 DBUtil ()=default
 Constructs the DBUtil object. More...
 
 ~DBUtil ()=default
 
QString GetDBMSVersion (void)
 Returns the QString version name of the DBMS or QString() in the event of an error. More...
 
int CompareDBMSVersion (int major, int minor=0, int point=0)
 Compares the version of the active DBMS with the provided version. More...
 

Static Public Member Functions

static SchemaUpgradeWizardGet (const QString &DBSchemaSetting, const QString &appName, const QString &upgradeSchemaVal)
 Instead of creating a new wizard, use the existing one for its DB backup file & results and expert settings. More...
 
- Static Public Member Functions inherited from DBUtil
static MythDBBackupStatus BackupDB (QString &filename, bool disableRotation=false)
 Requests a backup of the database. More...
 
static bool CheckTables (bool repair=false, const QString &options="QUICK")
 Checks database tables. More...
 
static bool RepairTables (const QStringList &tables)
 Repairs database tables. More...
 
static bool IsNewDatabase (void)
 Returns true for a new (empty) database. More...
 
static bool IsBackupInProgress (void)
 Test to see if a DB backup is in progress. More...
 
static int CountClients (void)
 Estimate the number of MythTV programs using the database. More...
 
static bool TryLockSchema (MSqlQuery &query, uint timeout_secs)
 Try to get a lock on the table schemalock. More...
 
static void UnlockSchema (MSqlQuery &query)
 
static bool CheckTimeZoneSupport (void)
 Check if MySQL has working timz zone support. More...
 
static bool CheckTableColumnExists (const QString &tableName, const QString &columnName)
 Checks for the presence of a column in a table in the current database. More...
 

Public Attributes

QString m_DBver
 Schema version in the database. More...
 
bool m_emptyDB {false}
 Is the database currently empty? More...
 
int m_versionsBehind {-1}
 How many schema versions old is the DB? More...
 
MythDBBackupStatus m_backupStatus {kDB_Backup_Unknown}
 BackupDB() status. More...
 

Private Member Functions

void BusyPopup (const QString &message)
 Delete any current "busy" popup, create new one. More...
 

Static Private Member Functions

static MythSchemaUpgrade GuiPrompt (const QString &message, bool upgradable, bool expert)
 

Private Attributes

bool m_autoUpgrade {false}
 If no UI, always upgrade. More...
 
QString m_backupResult
 File path, or FAILED More...
 
MythUIBusyDialogm_busyPopup {nullptr}
 Displayed during long pauses. More...
 
bool m_expertMode {false}
 Also allow newer DB schema. More...
 
QString m_schemaSetting
 To lookup the schema version. More...
 
QString m_schemaName
 Shown to user in logs. More...
 
QString m_newSchemaVer
 What we need to upgrade to. More...
 

Additional Inherited Members

- Static Public Attributes inherited from DBUtil
static const int kUnknownVersionNumber = INT_MIN
 
- Static Protected Member Functions inherited from DBUtil
static bool CreateTemporaryDBConf (const QString &privateinfo, QString &filename)
 Creates temporary file containing sensitive DB info. More...
 

Detailed Description

Provides UI and helper functions for DB Schema updates.

See dbcheck.cpp's UpgradeTVDatabaseSchema() for usage.

Definition at line 25 of file schemawizard.h.

Constructor & Destructor Documentation

◆ SchemaUpgradeWizard()

SchemaUpgradeWizard::SchemaUpgradeWizard ( QString  DBSchemaSetting,
QString  appName,
QString  upgradeSchemaVal 
)

Definition at line 26 of file schemawizard.cpp.

Referenced by Get().

◆ ~SchemaUpgradeWizard()

SchemaUpgradeWizard::~SchemaUpgradeWizard ( )
override

Definition at line 48 of file schemawizard.cpp.

Member Function Documentation

◆ BackupDB()

MythDBBackupStatus SchemaUpgradeWizard::BackupDB ( void  )

Call DBUtil::BackupDB(), and store results.

Definition at line 86 of file schemawizard.cpp.

Referenced by PromptForUpgrade().

◆ Compare()

int SchemaUpgradeWizard::Compare ( void  )

How many schema versions old is the DB?

Definition at line 100 of file schemawizard.cpp.

Referenced by PromptForUpgrade(), tryUpgradeMusicDatabaseSchema(), and tryUpgradeTVDatabaseSchema().

◆ Get()

SchemaUpgradeWizard * SchemaUpgradeWizard::Get ( const QString &  DBSchemaSetting,
const QString &  appName,
const QString &  upgradeSchemaVal 
)
static

Instead of creating a new wizard, use the existing one for its DB backup file & results and expert settings.

Definition at line 54 of file schemawizard.cpp.

Referenced by tryUpgradeMusicDatabaseSchema(), and tryUpgradeTVDatabaseSchema().

◆ PromptForUpgrade()

enum MythSchemaUpgrade SchemaUpgradeWizard::PromptForUpgrade ( const char *  name,
bool  upgradeAllowed,
bool  upgradeIfNoUI,
int  minDBMSmajor = 0,
int  minDBMSminor = 0,
int  minDBMSpoint = 0 
)

Query user, to prevent silent, automatic database upgrades.

Tell the user that a schema needs to be upgraded, ask if that's OK, remind them about backups, et c.

The GUI buttons default to Exit. The shell command prompting requires an explicit "yes".

Parameters
nameWhat schema are we planning to upgrade? (TV? Music?)
upgradeAllowedIn not true, and DBSchemaAutoUpgrade isn't set for expert mode, this is just a few information messages
upgradeIfNoUIDefault for non-interactive shells
minDBMSmajorRequired minimum major version of mysql/mariadb.
minDBMSminorRequired minimum minor version of mysql/mariadb.
minDBMSpointRequired minimum point version of mysql/mariadb.
Todo:
Clarify whether the minDBMS stuff is just for upgrading, or if it is a runtime requirement too. If the latter, then this possibly should be called even if the schema match, to ensure the user is informed of the MySQL upgrade requirement.
Todo:
This uses GetMythUI()->IsScreenSetup() to work out if this program's context is a GUI, but GetMythUI() might create a MythUIHelper. Having a static bool MythUIHelper::ValidMythUI() would be much tidier?

Definition at line 224 of file schemawizard.cpp.

Referenced by tryUpgradeMusicDatabaseSchema(), and tryUpgradeTVDatabaseSchema().

◆ BusyPopup()

void SchemaUpgradeWizard::BusyPopup ( const QString &  message)
private

Delete any current "busy" popup, create new one.

Definition at line 78 of file schemawizard.cpp.

◆ GuiPrompt()

MythSchemaUpgrade SchemaUpgradeWizard::GuiPrompt ( const QString &  message,
bool  upgradable,
bool  expert 
)
staticprivate

Definition at line 147 of file schemawizard.cpp.

Referenced by PromptForUpgrade().

Member Data Documentation

◆ m_DBver

QString SchemaUpgradeWizard::m_DBver

Schema version in the database.

Definition at line 55 of file schemawizard.h.

Referenced by Compare(), Get(), PromptForUpgrade(), and tryUpgradeMusicDatabaseSchema().

◆ m_emptyDB

bool SchemaUpgradeWizard::m_emptyDB {false}

Is the database currently empty?

Definition at line 56 of file schemawizard.h.

Referenced by BackupDB(), Compare(), and PromptForUpgrade().

◆ m_versionsBehind

int SchemaUpgradeWizard::m_versionsBehind {-1}

How many schema versions old is the DB?

Definition at line 57 of file schemawizard.h.

Referenced by Compare(), Get(), and PromptForUpgrade().

◆ m_backupStatus

MythDBBackupStatus SchemaUpgradeWizard::m_backupStatus {kDB_Backup_Unknown}

BackupDB() status.

Definition at line 59 of file schemawizard.h.

Referenced by BackupDB(), and PromptForUpgrade().

◆ m_autoUpgrade

bool SchemaUpgradeWizard::m_autoUpgrade {false}
private

If no UI, always upgrade.

Definition at line 66 of file schemawizard.h.

Referenced by PromptForUpgrade(), and SchemaUpgradeWizard().

◆ m_backupResult

QString SchemaUpgradeWizard::m_backupResult
private

File path, or FAILED

Definition at line 67 of file schemawizard.h.

Referenced by BackupDB(), and PromptForUpgrade().

◆ m_busyPopup

MythUIBusyDialog* SchemaUpgradeWizard::m_busyPopup {nullptr}
private

Displayed during long pauses.

Definition at line 68 of file schemawizard.h.

Referenced by BusyPopup().

◆ m_expertMode

bool SchemaUpgradeWizard::m_expertMode {false}
private

Also allow newer DB schema.

Definition at line 69 of file schemawizard.h.

Referenced by PromptForUpgrade(), and SchemaUpgradeWizard().

◆ m_schemaSetting

QString SchemaUpgradeWizard::m_schemaSetting
private

To lookup the schema version.

Definition at line 70 of file schemawizard.h.

Referenced by Compare(), and Get().

◆ m_schemaName

QString SchemaUpgradeWizard::m_schemaName
private

Shown to user in logs.

Definition at line 71 of file schemawizard.h.

Referenced by Compare(), and Get().

◆ m_newSchemaVer

QString SchemaUpgradeWizard::m_newSchemaVer
private

What we need to upgrade to.

Definition at line 72 of file schemawizard.h.

Referenced by Compare(), Get(), and PromptForUpgrade().


The documentation for this class was generated from the following files: