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

Fix migration to model 11

That makes it 2 forgotten tables...
parent a2c3c9d3
......@@ -299,6 +299,26 @@ const std::string& Folder::mrl() const
return m_fullPath;
}
const std::string& Folder::rawMrl() const
{
return m_path;
}
void Folder::setMrl( std::string mrl )
{
if ( m_path == mrl )
return;
static const std::string req = "UPDATE " + policy::FolderTable::Name + " SET "
"path = ? WHERE id_folder = ?";
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, mrl, m_id ) == false )
return;
// We shouldn't use this if any full path/mrl has been cached.
// This is meant for migration only, so there is no need to have cached this
// information so far.
assert( m_isRemovable == false || m_fullPath.empty() == true );
m_path = std::move( mrl );
}
std::vector<std::shared_ptr<File>> Folder::files()
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name +
......
......@@ -72,6 +72,8 @@ public:
virtual int64_t id() const override;
virtual const std::string& mrl() const override;
const std::string& rawMrl() const;
void setMrl( std::string mrl );
std::vector<std::shared_ptr<File>> files();
std::vector<std::shared_ptr<Folder>> folders();
std::shared_ptr<Folder> parent();
......
......@@ -974,21 +974,28 @@ void MediaLibrary::migrateModel9to10()
t->commit();
}
// Guess who forgot to migrate a table in version 10?
void MediaLibrary::migrateModel10to11()
{
const std::string req = "SELECT * FROM " + policy::TaskTable::Name +
" WHERE mrl LIKE '%#%%' ESCAPE '#'";
const std::string folderReq = "SELECT * FROM " + policy::FolderTable::Name +
" WHERE path LIKE '%#%%' ESCAPE '#'";
auto tasks = parser::Task::fetchAll<parser::Task>( this, req );
auto folders = Folder::fetchAll<Folder>( this, folderReq );
auto t = getConn()->newTransaction();
for ( const auto& t : tasks )
{
// We must not call mrl() from here. We might not have all devices yet,
// and calling mrl would crash for files stored on removable devices.
auto newMrl = utils::url::encode( utils::url::decode( t->mrl ) );
LOG_INFO( "Converting task mrl: ", t->mrl, " to ", newMrl );
t->setMrl( std::move( newMrl ) );
}
for ( const auto &f : folders )
{
// We must not call mrl() from here. We might not have all devices yet,
// and calling mrl would crash for files stored on removable devices.
auto newMrl = utils::url::encode( utils::url::decode( f->rawMrl() ) );
f->setMrl( std::move( newMrl ) );
}
t->commit();
}
......
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