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

Bump DB model to 10

To recover from different encoding without removing all files
parent 6c25998d
......@@ -54,6 +54,7 @@
#include "database/SqliteTools.h"
#include "database/SqliteConnection.h"
#include "utils/Filename.h"
#include "utils/Url.h"
#include "VideoTrack.h"
// Discoverers:
......@@ -809,6 +810,11 @@ InitializeResult MediaLibrary::updateDatabaseModel( unsigned int previousVersion
migrateModel8to9();
previousVersion = 9;
}
if ( previousVersion == 9 )
{
migrateModel9to10();
previousVersion = 10;
}
// To be continued in the future!
// Safety check: ensure we didn't forget a migration along the way
......@@ -944,6 +950,22 @@ void MediaLibrary::migrateModel8to9()
forceRescan();
}
void MediaLibrary::migrateModel9to10()
{
const std::string req = "SELECT * FROM " + policy::FileTable::Name +
" WHERE mrl LIKE '%#%%' ESCAPE '#'";
auto files = File::fetchAll<File>( this, req );
auto t = getConn()->newTransaction();
for ( const auto& f : files )
{
auto newMrl = utils::url::encode( utils::url::decode( f->mrl() ) );
LOG_INFO( "Converting ", f->mrl(), " to ", newMrl );
f->setMrl( newMrl );
}
t->commit();
forceRescan();
}
void MediaLibrary::reload()
{
if ( m_discovererWorker != nullptr )
......
......@@ -172,6 +172,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
bool migrateModel5to6();
void migrateModel7to8();
void migrateModel8to9();
void migrateModel9to10();
void createAllTables();
void createAllTriggers();
void registerEntityHooks();
......
......@@ -32,7 +32,7 @@
namespace medialibrary
{
const uint32_t Settings::DbModelVersion = 9u;
const uint32_t Settings::DbModelVersion = 10u;
Settings::Settings( MediaLibrary* ml )
: m_ml( ml )
......
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