Bug 19963 - ethnicity and ethnicity tables and columns survived update
Summary: ethnicity and ethnicity tables and columns survived update
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Database (show other bugs)
Version: Main
Hardware: All All
: P5 - low minor (vote)
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-12 11:44 UTC by Katrin Fischer
Modified: 2022-12-06 23:32 UTC (History)
2 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 19963: Update 3.21.00.033 to drop ethnicity data if '' (1.37 KB, patch)
2018-01-22 19:33 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Katrin Fischer 2018-01-12 11:44:04 UTC
The database update for 3.21.00.033 should have removed the ethnicity table and the ethnicity and ethnotes columns from borrowers, deletedborrowers and borrower_modifications. This didn't work right in all cases. I just noticed that all those survived in our older databases. The reason is that the database update only checked for NULL when counting existing data, but not for "":

11054 $DBversion = "3.21.00.033";
11055 if ( CheckVersion($DBversion) ) {
11056 
11057     my $done = 0;
11058     my $count_ethnicity = $dbh->selectrow_arrayref(q|
11059         SELECT COUNT(*) FROM ethnicity
11060     |);
11061     my $count_borrower_modifications = $dbh->selectrow_arrayref(q|
11062         SELECT COUNT(*)
11063         FROM borrower_modifications
11064         WHERE ethnicity IS NOT NULL
11065             OR ethnotes IS NOT NULL
11066     |);
11067     my $count_borrowers = $dbh->selectrow_arrayref(q|
11068         SELECT COUNT(*)
11069         FROM borrowers
11070         WHERE ethnicity IS NOT NULL
11071             OR ethnotes IS NOT NULL
11072     |);
11073     # We don't care about the ethnicity of the deleted borrowers, right?
11074     if ( $count_ethnicity->[0] == 0
11075             and $count_borrower_modifications->[0] == 0
11076             and $count_borrowers->[0] == 0
11077     ) {
11078         $dbh->do(q|
11079             DROP TABLE ethnicity
11080         |);
11081         $dbh->do(q|
11082             ALTER TABLE borrower_modifications
11083             DROP COLUMN ethnicity,
11084             DROP COLUMN ethnotes
11085         |);
11086         $dbh->do(q|
11087             ALTER TABLE borrowers
11088             DROP COLUMN ethnicity,
11089             DROP COLUMN ethnotes
11090         |);
11091         $dbh->do(q|
11092             ALTER TABLE deletedborrowers
11093             DROP COLUMN ethnicity,
11094             DROP COLUMN ethnotes
11095         |);
11096         $done = 1;
11097     }
11098     if ( $done ) {
11099         print "Upgrade to $DBversion done (Bug 10020: Drop table ethnicity and columns ethnicity and ethnotes)\n";
11100     }
11101     else {
11102         print "Upgrade to $DBversion done (Bug 10020: This database contains data related to 'ethnicity'. No change will be done on the DB structure but note that the Koha codebase does not use it)\n";
11103     }
11104 
11105     SetVersion ($DBversion);
Comment 1 Jonathan Druart 2018-01-22 19:32:55 UTC
I guess this change could fix it, but do not have more time to spend on that.
There is the warning that is displayed anyway.
Comment 2 Jonathan Druart 2018-01-22 19:33:40 UTC
Created attachment 70806 [details] [review]
Bug 19963: Update 3.21.00.033 to drop ethnicity data if ''
Comment 3 David Cook 2022-12-06 05:55:32 UTC
I'm guessing this is still valid?

Doesn't appear in new databases but guessing it still affects old ones?
Comment 4 Katrin Fischer 2022-12-06 23:32:07 UTC
Yes it would, we probably missed Jobou's patch because the status wasn't changed?