Skip to content

Commit

Permalink
Fix the partially quoted index name for MariaDB/MySQL
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sunnavy committed May 3, 2023
1 parent a1ac2e0 commit 98c7202
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/RT/Handle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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'};
Expand All @@ -2270,9 +2275,10 @@ sub CreateIndex {
}
}


my $sql = "CREATE"
. ($args{'Unique'}? ' UNIQUE' : '')
." INDEX $name ON $args{'Table'}"
." INDEX $name ON $quoted_table"
."(". join( ', ', @columns ) .")"
;

Expand Down

0 comments on commit 98c7202

Please sign in to comment.