Commit d1b147bf authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Settings: Store the expected DB model in the settings class

parent 461d87a6
......@@ -84,8 +84,6 @@ const char* const MediaLibrary::supportedExtensions[] = {
const size_t MediaLibrary::NbSupportedExtensions = sizeof(supportedExtensions) / sizeof(supportedExtensions[0]);
const uint32_t MediaLibrary::DbModelVersion = 2;
MediaLibrary::MediaLibrary()
: m_callback( nullptr )
, m_verbosity( LogLevel::Error )
......@@ -270,7 +268,7 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& thu
LOG_ERROR( "Failed to load settings" );
return false;
}
if ( m_settings.dbModelVersion() != DbModelVersion )
if ( m_settings.dbModelVersion() != Settings::DbModelVersion )
{
if ( updateDatabaseModel( m_settings.dbModelVersion() ) == false )
{
......@@ -667,8 +665,8 @@ bool MediaLibrary::updateDatabaseModel( unsigned int previousVersion )
// To be continued in the future!
// Safety check: ensure we didn't forget a migration along the way
assert( previousVersion == DbModelVersion );
m_settings.setDbModelVersion( DbModelVersion );
assert( previousVersion == Settings::DbModelVersion );
m_settings.setDbModelVersion( Settings::DbModelVersion );
m_settings.save();
return true;
}
......
......@@ -142,9 +142,6 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
void refreshDevices(factory::IFileSystem& fsFactory);
public:
static const uint32_t DbModelVersion;
protected:
// Allow access to unit test MediaLibrary implementations
static const char* const supportedExtensions[];
......
......@@ -32,6 +32,8 @@
namespace medialibrary
{
const uint32_t Settings::DbModelVersion = 2u;
Settings::Settings()
: m_dbConn( nullptr )
, m_dbModelVersion( 0 )
......@@ -47,9 +49,9 @@ bool Settings::load( DBConnection dbConn )
// First launch: no settings
if ( row == nullptr )
{
if ( sqlite::Tools::executeInsert( m_dbConn, "INSERT INTO Settings VALUES(?)", MediaLibrary::DbModelVersion ) == false )
if ( sqlite::Tools::executeInsert( m_dbConn, "INSERT INTO Settings VALUES(?)", DbModelVersion ) == false )
return false;
m_dbModelVersion = MediaLibrary::DbModelVersion;
m_dbModelVersion = DbModelVersion;
}
else
{
......
......@@ -34,12 +34,19 @@ class Settings
public:
Settings();
bool load( DBConnection dbConn );
/**
* @brief dbModelVersion returns the current database model version.
*
* This can be different from the \ref DbModelVersion when upgrading the model
*/
uint32_t dbModelVersion() const;
bool save();
void setDbModelVersion( uint32_t dbModelVersion );
static bool createTable(DBConnection dbConn);
static const uint32_t DbModelVersion;
private:
DBConnection m_dbConn;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment