Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bugs with brewday step numbering (and database version update) #97

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/DatabaseSchemaHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <QDebug>
#include <QSqlError>

const int DatabaseSchemaHelper::dbVersion = 4;
const int DatabaseSchemaHelper::dbVersion = 5;

// Commands and keywords
QString DatabaseSchemaHelper::CREATETABLE("CREATE TABLE");
Expand Down Expand Up @@ -885,7 +885,7 @@ bool DatabaseSchemaHelper::create(QSqlDatabase db)
"CREATE TRIGGER dec_ins_num AFTER DELETE ON instruction_in_recipe " +
"BEGIN "
"UPDATE instruction_in_recipe SET instruction_number = instruction_number - 1 " +
"WHERE recipe_id = old.recipe_id AND instruction_id > old.instruction_id; " +
"WHERE recipe_id = old.recipe_id AND instruction_number > old.instruction_number; " +
"END"
);

Expand Down Expand Up @@ -1272,6 +1272,25 @@ bool DatabaseSchemaHelper::migrateNext(int oldVersion, QSqlDatabase db)
);

break;

case 4:

// Drop the previous bugged TRIGGER
ret &= q.exec( QString() +
"DROP TRIGGER dec_ins_num"
);

// Create the good trigger
ret &= q.exec( QString() +
"CREATE TRIGGER dec_ins_num AFTER DELETE ON instruction_in_recipe " +
"BEGIN "
"UPDATE instruction_in_recipe SET instruction_number = instruction_number - 1 " +
"WHERE recipe_id = old.recipe_id AND instruction_number > old.instruction_number; " +
"END"
);

break;


default:
Brewtarget::logE(QString("Unknown version %1").arg(oldVersion));
Expand All @@ -1283,7 +1302,7 @@ bool DatabaseSchemaHelper::migrateNext(int oldVersion, QSqlDatabase db)
{
ret &= q.exec(
UPDATE + SEP + tableSettings +
" SET " + colSettingsVersion + "=" + (oldVersion+1) + " WHERE id=1"
" SET " + colSettingsVersion + "=" + QString::number(oldVersion+1) + " WHERE id=1"
);
}

Expand Down Expand Up @@ -1355,4 +1374,4 @@ int DatabaseSchemaHelper::currentVersion(QSqlDatabase db)

Brewtarget::logE("Could not find database version");
return -1;
}
}