Skip to content

Commit

Permalink
Merge pull request #113 from rocketman768/feature/pick-brewday-step
Browse files Browse the repository at this point in the history
Fixes bugs with brewday step numbering
  • Loading branch information
rocketman768 committed Nov 8, 2015
2 parents 78592a2 + ad4f5a3 commit 42c0c7d
Showing 1 changed file with 23 additions and 4 deletions.
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;
}
}

0 comments on commit 42c0c7d

Please sign in to comment.