Bug 40292: (follow-up) Add xt test to prevent future occurences
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit ec66781149)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
parent
3e05f735ae
commit
8cbdc7815e
|
|
@ -0,0 +1,83 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# Copyright 2025 Koha Development Team
|
||||
#
|
||||
# This file is part of Koha.
|
||||
#
|
||||
# Koha is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Koha is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More;
|
||||
use File::Find;
|
||||
use File::Slurp;
|
||||
|
||||
# Test for Bug 40292: Prevent SQL syntax error when upgrading to 25.05 on MariaDB 10.3
|
||||
# This test ensures that database revision files don't use SQL syntax that is incompatible
|
||||
# with older MariaDB versions (specifically MariaDB 10.3)
|
||||
|
||||
my @db_rev_files;
|
||||
my $db_revs_dir = 'installer/data/mysql/db_revs';
|
||||
|
||||
# Skip test if db_revs directory doesn't exist
|
||||
if ( !-d $db_revs_dir ) {
|
||||
plan skip_all => "Database revisions directory ($db_revs_dir) not found";
|
||||
}
|
||||
|
||||
# Find all .pl files in the db_revs directory
|
||||
find(
|
||||
sub {
|
||||
push @db_rev_files, $File::Find::name if /\.pl$/;
|
||||
},
|
||||
$db_revs_dir
|
||||
);
|
||||
|
||||
# Skip test if no database revision files found
|
||||
if ( !@db_rev_files ) {
|
||||
plan skip_all => "No database revision files found in $db_revs_dir";
|
||||
}
|
||||
|
||||
plan tests => scalar @db_rev_files;
|
||||
|
||||
foreach my $file (@db_rev_files) {
|
||||
my $content = read_file($file);
|
||||
|
||||
# Check for incompatible RENAME COLUMN syntax
|
||||
# MariaDB 10.3 doesn't support "RENAME COLUMN old_name TO new_name"
|
||||
# but does support "CHANGE COLUMN old_name new_name datatype"
|
||||
my $has_incompatible_syntax = 0;
|
||||
my @problem_lines;
|
||||
|
||||
my @lines = split /\n/, $content;
|
||||
for my $line_num ( 0 .. $#lines ) {
|
||||
my $line = $lines[$line_num];
|
||||
|
||||
# Look for RENAME COLUMN syntax (case insensitive)
|
||||
# This regex matches: RENAME COLUMN old_name TO new_name
|
||||
if ( $line =~ /\bRENAME\s+COLUMN\s+\w+\s+TO\s+\w+/i ) {
|
||||
$has_incompatible_syntax = 1;
|
||||
push @problem_lines, sprintf( "Line %d: %s", $line_num + 1, $line );
|
||||
}
|
||||
}
|
||||
|
||||
if ($has_incompatible_syntax) {
|
||||
fail("$file contains incompatible RENAME COLUMN syntax");
|
||||
diag("Found incompatible SQL syntax in $file:");
|
||||
diag($_) for @problem_lines;
|
||||
diag("Use 'CHANGE COLUMN old_name new_name datatype' instead of 'RENAME COLUMN old_name TO new_name'");
|
||||
diag("This syntax is required for MariaDB 10.3 compatibility (Bug 40292)");
|
||||
} else {
|
||||
pass("$file uses compatible SQL syntax");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue