From c3807a9548de54d30fe9355857bce955f652c29e Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 15 Oct 2025 15:52:17 +0100 Subject: [PATCH] Bug 38489: (follow-up) Make old db_rev more idempotent In the unit test system we reset the database version to 21.11 after having upgraded a long way past that. The 221200041 update appears not to be fully idempotent, so we fail running through the upgrade. --- installer/data/mysql/db_revs/221200041.pl | 34 +++++++++++++---------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/installer/data/mysql/db_revs/221200041.pl b/installer/data/mysql/db_revs/221200041.pl index 5687b1f08a3..3a7fd02db98 100755 --- a/installer/data/mysql/db_revs/221200041.pl +++ b/installer/data/mysql/db_revs/221200041.pl @@ -6,22 +6,26 @@ return { up => sub { my ($args) = @_; my ( $dbh, $out ) = @$args{qw(dbh out)}; - $dbh->do( - q{ - ALTER TABLE vendor_edi_accounts CHANGE COLUMN `password` `password` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL - } - ); + if ( column_exists( 'vendor_edi_accounts', 'password' ) ) { + $dbh->do( + q{ + ALTER TABLE vendor_edi_accounts CHANGE COLUMN `password` `password` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL + } + ); - my $edi_vendors = - $dbh->selectall_arrayref( "SELECT * FROM vendor_edi_accounts", { Slice => {} } ); - if (@$edi_vendors) { - require Koha::Encryption; - my $e = Koha::Encryption->new; - for my $edi_vendor (@$edi_vendors) { - my $id = $edi_vendor->{id}; - my $password = $edi_vendor->{password}; - $password = $e->encrypt_hex($password); - $dbh->do("UPDATE vendor_edi_accounts SET password = '$password' WHERE id = $id"); + my $edi_vendors = $dbh->selectall_arrayref( + "SELECT * FROM vendor_edi_accounts", + { Slice => {} } + ); + if (@$edi_vendors) { + require Koha::Encryption; + my $e = Koha::Encryption->new; + for my $edi_vendor (@$edi_vendors) { + my $id = $edi_vendor->{id}; + my $password = $edi_vendor->{password}; + $password = $e->encrypt_hex($password); + $dbh->do("UPDATE vendor_edi_accounts SET password = '$password' WHERE id = $id"); + } } } }, -- 2.51.0