From ad8055748572f986869a61042af0fc43b3eb75d3 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 3 Jul 2025 12:55:25 +0100 Subject: [PATCH] Bug 40292: (follow-up) Add xt test to prevent future occurences Signed-off-by: Martin Renvoize --- xt/check_db_revs_sql_syntax.t | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 xt/check_db_revs_sql_syntax.t diff --git a/xt/check_db_revs_sql_syntax.t b/xt/check_db_revs_sql_syntax.t new file mode 100755 index 00000000000..b229803e2fc --- /dev/null +++ b/xt/check_db_revs_sql_syntax.t @@ -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 . + +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"); + } +} \ No newline at end of file -- 2.50.0