Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2025 Koha Development Team |
4 |
# |
5 |
# This file is part of Koha. |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use Test::More; |
23 |
use File::Find; |
24 |
use File::Slurp; |
25 |
|
26 |
# Test for Bug 40292: Prevent SQL syntax error when upgrading to 25.05 on MariaDB 10.3 |
27 |
# This test ensures that database revision files don't use SQL syntax that is incompatible |
28 |
# with older MariaDB versions (specifically MariaDB 10.3) |
29 |
|
30 |
my @db_rev_files; |
31 |
my $db_revs_dir = 'installer/data/mysql/db_revs'; |
32 |
|
33 |
# Skip test if db_revs directory doesn't exist |
34 |
if ( !-d $db_revs_dir ) { |
35 |
plan skip_all => "Database revisions directory ($db_revs_dir) not found"; |
36 |
} |
37 |
|
38 |
# Find all .pl files in the db_revs directory |
39 |
find( |
40 |
sub { |
41 |
push @db_rev_files, $File::Find::name if /\.pl$/; |
42 |
}, |
43 |
$db_revs_dir |
44 |
); |
45 |
|
46 |
# Skip test if no database revision files found |
47 |
if ( !@db_rev_files ) { |
48 |
plan skip_all => "No database revision files found in $db_revs_dir"; |
49 |
} |
50 |
|
51 |
plan tests => scalar @db_rev_files; |
52 |
|
53 |
foreach my $file (@db_rev_files) { |
54 |
my $content = read_file($file); |
55 |
|
56 |
# Check for incompatible RENAME COLUMN syntax |
57 |
# MariaDB 10.3 doesn't support "RENAME COLUMN old_name TO new_name" |
58 |
# but does support "CHANGE COLUMN old_name new_name datatype" |
59 |
my $has_incompatible_syntax = 0; |
60 |
my @problem_lines; |
61 |
|
62 |
my @lines = split /\n/, $content; |
63 |
for my $line_num (0..$#lines) { |
64 |
my $line = $lines[$line_num]; |
65 |
|
66 |
# Look for RENAME COLUMN syntax (case insensitive) |
67 |
# This regex matches: RENAME COLUMN old_name TO new_name |
68 |
if ( $line =~ /\bRENAME\s+COLUMN\s+\w+\s+TO\s+\w+/i ) { |
69 |
$has_incompatible_syntax = 1; |
70 |
push @problem_lines, sprintf("Line %d: %s", $line_num + 1, $line); |
71 |
} |
72 |
} |
73 |
|
74 |
if ($has_incompatible_syntax) { |
75 |
fail("$file contains incompatible RENAME COLUMN syntax"); |
76 |
diag("Found incompatible SQL syntax in $file:"); |
77 |
diag($_) for @problem_lines; |
78 |
diag("Use 'CHANGE COLUMN old_name new_name datatype' instead of 'RENAME COLUMN old_name TO new_name'"); |
79 |
diag("This syntax is required for MariaDB 10.3 compatibility (Bug 40292)"); |
80 |
} else { |
81 |
pass("$file uses compatible SQL syntax"); |
82 |
} |
83 |
} |