Avoid RENAME COLUMN to make db migration more robust

RENAME COLUMN was only introduced in sqlite 3.25.  So it's probably
better to avoid it for the time being to increase compatibility with
older versions.
This commit is contained in:
Bart De Vries 2021-06-27 10:32:48 +02:00
parent e0154355aa
commit 3a24ea6f65
1 changed files with 4 additions and 2 deletions

View File

@ -80,9 +80,11 @@ bool Database::migrateTo2()
bool Database::migrateTo3()
{
qDebug() << "Migrating database to version 3";
TRUE_OR_RETURN(execute(QStringLiteral("ALTER TABLE Enclosures RENAME COLUMN downloaded TO downloaded_temp;")));
TRUE_OR_RETURN(execute(QStringLiteral("ALTER TABLE Enclosures ADD COLUMN downloaded_temp BOOL DEFAULT 0;")));
TRUE_OR_RETURN(execute(QStringLiteral("UPDATE Enclosures SET downloaded_temp=1 WHERE downloaded=1;")));
TRUE_OR_RETURN(execute(QStringLiteral("ALTER TABLE Enclosures DROP COLUMN downloaded;")));
TRUE_OR_RETURN(execute(QStringLiteral("ALTER TABLE Enclosures ADD COLUMN downloaded INTEGER DEFAULT 0;")));
TRUE_OR_RETURN(execute(QStringLiteral("UPDATE Enclosures SET downloaded=3 where downloaded_temp=1;")));
TRUE_OR_RETURN(execute(QStringLiteral("UPDATE Enclosures SET downloaded=3 WHERE downloaded_temp=1;")));
TRUE_OR_RETURN(execute(QStringLiteral("ALTER TABLE Enclosures DROP COLUMN downloaded_temp;")));
TRUE_OR_RETURN(execute(QStringLiteral("PRAGMA user_version = 3;")));
return true;