Bug 40725 - DBRev 23.12.00.053 should be made more resilient
Summary: DBRev 23.12.00.053 should be made more resilient
Status: Pushed to main
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Lucas Gass (lukeg)
QA Contact: Tomás Cohen Arazi (tcohen)
URL:
Keywords:
Depends on: 37901 36755
Blocks:
  Show dependency treegraph
 
Reported: 2025-08-28 17:55 UTC by Lucas Gass (lukeg)
Modified: 2025-08-28 21:32 UTC (History)
1 user (show)

See Also:
GIT URL:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
25.11.00
Circulation function:


Attachments
Bug 40725: Add TableExists check to db_revs/231200053.pl (8.68 KB, patch)
2025-08-28 19:06 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 40725: Add TableExists check to db_revs/231200053.pl (9.51 KB, patch)
2025-08-28 19:39 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Lucas Gass (lukeg) 2025-08-28 17:55:33 UTC
DBRev 23.12.00.003 can causes problems if the table we are checking the FK for does not exist, or has gotten a name change. 

We can make the DBRev more resilient by checking if the tables exist first.
Comment 1 Lucas Gass (lukeg) 2025-08-28 17:59:19 UTC
The DBRev is DBRev 23.12.00.053 not DBRev 23.12.00.003
Comment 2 Lucas Gass (lukeg) 2025-08-28 19:06:09 UTC
Created attachment 185856 [details] [review]
Bug 40725: Add TableExists check to db_revs/231200053.pl
Comment 3 Tomás Cohen Arazi (tcohen) 2025-08-28 19:39:57 UTC
Created attachment 185857 [details] [review]
Bug 40725: Add TableExists check to db_revs/231200053.pl

This patch makes the DB revision idempotent.

To test:
1. Fix the Koha version right before the broken upgrade:
   $ ktd --shell
  k$ koha-mysql kohadev
   > UPDATE systempreferences SET value="23.1200052" WHERE
variable="version"; \q
2. Restart everything (memcached should be enough)
  k$ restart_all
3. Run:
  k$ updatedatabase
=> FAIL: You get:

```shell
Upgrade to 23.12.00.053  [19:34:35]: Bug 36755 - Increase length of 'code' column in borrower_attribute_types
	ERROR: C4::Installer::foreign_key_exists(): DBI Exception: DBD::mysql::db selectrow_array failed: Table 'koha_kohadev.pseudonymized_borrower_attributes' doesn't exist at /kohadevbox/koha/installer/data/mysql/db_revs/231200053.pl line 11
```

4. Apply this patch
5. Repeat 3
=> SUCCESS: Update runs smoothly!
6. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 4 Lucas Gass (lukeg) 2025-08-28 19:53:16 UTC
Thank you Tomas for testing and for the test plan!
Comment 5 Lucas Gass (lukeg) 2025-08-28 19:56:01 UTC
Thanks all! 

Pushed to main for 25.11.x