From 98c7202d2654b5ce453a4465005bd06683f9f2de Mon Sep 17 00:00:00 2001 From: sunnavy Date: Wed, 3 May 2023 22:54:34 +0800 Subject: [PATCH] Fix the partially quoted index name for MariaDB/MySQL Previously the index name was generated with quoted table name and a number suffix like "`attachments`1", which MariaDB/MySQL does not support. As index names(table name + number suffix) probably will never be reserved words, this commit simply removes the quote of the table name part. This is initially to fix upgrade steps that create indexes via "indexes" file. --- lib/RT/Handle.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm index c8732a980f..f9dc58fd88 100644 --- a/lib/RT/Handle.pm +++ b/lib/RT/Handle.pm @@ -2249,8 +2249,13 @@ sub CreateIndex { my $self = shift; my %args = ( Table => undef, Name => undef, Columns => [], CaseInsensitive => {}, @_ ); + my $quoted_table; # Quoted table only for mysql. if (RT->Config->Get('DatabaseType') eq 'mysql') { - $args{'Table'} = $self->QuoteName( $self->_CanonicTableNameMysql( $args{'Table'} )); + $args{'Table'} = $self->_CanonicTableNameMysql( $args{'Table'} ); + $quoted_table = $self->QuoteName($args{'Table'}); + } + else { + $quoted_table = $args{'Table'}; } my $name = $args{'Name'}; @@ -2270,9 +2275,10 @@ sub CreateIndex { } } + my $sql = "CREATE" . ($args{'Unique'}? ' UNIQUE' : '') - ." INDEX $name ON $args{'Table'}" + ." INDEX $name ON $quoted_table" ."(". join( ', ', @columns ) .")" ;