Bug 18050: Add FK constraint on aqbudgets.budget_period_id
authorKatrin Fischer <katrin.fischer.83@web.de>
Sun, 13 Sep 2020 22:42:27 +0000 (22:42 +0000)
committerLucas Gass <lucas@bywatersolutions.com>
Fri, 13 Nov 2020 21:10:39 +0000 (21:10 +0000)
commitfee8aa2b1cf4c90c37e55d7286bafe8a8b0307de
tree0de3e5947df88bdb1245106afe7c05e71a5b59c9
parent7485f479fafb1b04d7681432c5cc421ab3f2afae
Bug 18050: Add FK constraint on aqbudgets.budget_period_id

This adds a FK constraint on aqbudgets.budget_period_id so that
a fund cannot be added with an invalid aqbudget.budget_period_id.

We should not have funds that belong to no budget. In case we have, the
update will be skipped and a note displayed.

Part1:
- Before applying the patch
- Make sure you have a budget with some funds linked to it
- You will have to change one of the funds to link to an invalid
  budget with SQL:
  UPDATE aqbudgets SET budget_period_id = 999 WHERE budget_id = max(budget_id);
- Apply patch
- Run updatedatabase - verify that you see the hint about 1 existing fund with invalid budget.
- Repair your fund with SQL
  UPDATE aqbudgets SET budget_period_id = ... WHERE budget_id = max(budget_id);
  (... needs to be your existing budget_period_id)
- Run updatedatabase again - verify it runs successfully now.
- If you try to change the budget_period_id to a non-existing now with SQL, you will
  get a database error. The new FK doesn't permit it.
Part 2:
- Start fresh with the web installer, verify there are no errors on
  creating the database tables

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit 0ce62b29bf5ebe30125eb4c631de11391134f109)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
installer/data/mysql/atomicupdate/bug_18050_aqbudget_constraint.perl [new file with mode: 0644]
installer/data/mysql/kohastructure.sql