[Rt-commit] rt branch, 4.4/mysql8, created. rt-4.4.4-203-g797c2b89ae

? sunnavy sunnavy at bestpractical.com
Thu Jan 21 07:40:34 EST 2021


The branch, 4.4/mysql8 has been created
        at  797c2b89aef1035360cf9f2f4bd1d7cac053ecfd (commit)

- Log -----------------------------------------------------------------
commit 6c783c40537918dd4c906ca3b46549b91348ddcb
Author: Aaron Trevena <ast at bestpractical.com>
Date:   Tue Sep 1 16:19:56 2020 +0100

    Make RT work with MySQL 8
    
    Update code for the following changes in MySQL 8:
    
    * "Groups" is a reversed word
    
    We need to quote it accordingly.
    
    * Can't create user using GRANT any more
    
    We need to create user first and then grant privileges.

diff --git a/etc/acl.mysql b/etc/acl.mysql
index 26e27fbfbc..da148bde66 100644
--- a/etc/acl.mysql
+++ b/etc/acl.mysql
@@ -1,5 +1,6 @@
 
 sub acl {
+    my $dbh = shift;
     my $db_name = RT->Config->Get('DatabaseName');
     my $db_rthost = RT->Config->Get('DatabaseRTHost');
     my $db_user = RT->Config->Get('DatabaseUser');
@@ -13,6 +14,19 @@ sub acl {
         return;
     }
     $db_name =~ s/([_%\\])/\\$1/g;
+
+    if ( my $version = ( $dbh->selectrow_array("show variables like 'version'") )[1] ) {
+        if ( $version !~ /mariadb/i && $version =~ /^(\d+)\./ ) {
+            # run 2 part acl update for mysql 8 or higher
+            if ( $1 >= 8 ) {
+                return (
+                    "CREATE USER IF NOT EXISTS '$db_user'\@'$db_rthost' IDENTIFIED BY '$db_pass';",
+                    "GRANT SELECT,INSERT,CREATE,INDEX,UPDATE,DELETE ON `$db_name`.* TO '$db_user'\@'$db_rthost';",
+                );
+            }
+        }
+    }
+
     return (
         "GRANT SELECT,INSERT,CREATE,INDEX,UPDATE,DELETE
                ON `$db_name`.*
diff --git a/etc/schema.mysql b/etc/schema.mysql
index eefc145ca4..f33f180be3 100644
--- a/etc/schema.mysql
+++ b/etc/schema.mysql
@@ -70,7 +70,7 @@ CREATE TABLE Principals (
 ) ENGINE=InnoDB CHARACTER SET ascii;
 
 
-CREATE TABLE Groups (
+CREATE TABLE `Groups` (
   id INTEGER NOT NULL  AUTO_INCREMENT,
   Name varchar(200) NULL  ,
   Description varchar(255) NULL  ,
@@ -83,8 +83,8 @@ CREATE TABLE Groups (
   PRIMARY KEY (id)
 ) ENGINE=InnoDB CHARACTER SET utf8;
 
-CREATE INDEX Groups1 ON Groups (Domain, Name, Instance);
-CREATE INDEX Groups2 On Groups (Instance);
+CREATE INDEX Groups1 ON `Groups` (Domain, Name, Instance);
+CREATE INDEX Groups2 On `Groups` (Instance);
 
 CREATE TABLE ScripConditions (
   id INTEGER NOT NULL  AUTO_INCREMENT,
diff --git a/etc/upgrade/3.9.5/schema.mysql b/etc/upgrade/3.9.5/schema.mysql
index 83f2f4087f..2a40f46414 100644
--- a/etc/upgrade/3.9.5/schema.mysql
+++ b/etc/upgrade/3.9.5/schema.mysql
@@ -6,7 +6,7 @@ AND CustomFieldValues.id = Attributes.ObjectId);
 
 DELETE FROM Attributes WHERE Name = 'Category' AND ObjectType = 'RT::CustomFieldValue';
 
-ALTER TABLE Groups
+ALTER TABLE `Groups`
     ADD COLUMN Creator integer NOT NULL DEFAULT 0,
     ADD COLUMN Created DATETIME NULL,
     ADD COLUMN LastUpdatedBy integer NOT NULL DEFAULT 0,
diff --git a/etc/upgrade/4.1.13/backcompat b/etc/upgrade/4.1.13/backcompat
index 0dc53d224f..1126995277 100644
--- a/etc/upgrade/4.1.13/backcompat
+++ b/etc/upgrade/4.1.13/backcompat
@@ -22,6 +22,12 @@ if ( $groups->Next ) {
             WHERE LOWER(Domain) IN ('aclequivalence', 'systeminternal')
                 OR LOWER(Domain) LIKE '%-role'"
         );
+    } elsif ( $db_type eq 'mysql' ) {
+        $dbh->do(
+            "UPDATE `Groups` SET Name = Type
+            WHERE Domain IN ('ACLEquivalence', 'SystemInternal')
+                OR Domain LIKE '%-Role'"
+        );
     } else {
         $dbh->do(
             "UPDATE Groups SET Name = Type
diff --git a/etc/upgrade/4.1.13/schema.mysql b/etc/upgrade/4.1.13/schema.mysql
index a429007e30..33e162fca2 100644
--- a/etc/upgrade/4.1.13/schema.mysql
+++ b/etc/upgrade/4.1.13/schema.mysql
@@ -1,2 +1,2 @@
-UPDATE Groups SET Name = Type
-WHERE Domain IN ('ACLEquivalence', 'SystemInternal') OR Domain LIKE '%-Role';
\ No newline at end of file
+UPDATE `Groups` SET Name = Type
+WHERE Domain IN ('ACLEquivalence', 'SystemInternal') OR Domain LIKE '%-Role';
diff --git a/etc/upgrade/4.1.4/schema.mysql b/etc/upgrade/4.1.4/schema.mysql
index e530ede81d..8a727b5eef 100644
--- a/etc/upgrade/4.1.4/schema.mysql
+++ b/etc/upgrade/4.1.4/schema.mysql
@@ -1 +1 @@
-UPDATE Groups SET Instance = 1 WHERE Domain = 'RT::System-Role' AND Instance = 0;
+UPDATE `Groups` SET Instance = 1 WHERE Domain = 'RT::System-Role' AND Instance = 0;
diff --git a/etc/upgrade/4.3.13/schema.mysql b/etc/upgrade/4.3.13/schema.mysql
index 31328a030b..d7ade7e2a7 100644
--- a/etc/upgrade/4.3.13/schema.mysql
+++ b/etc/upgrade/4.3.13/schema.mysql
@@ -15,6 +15,6 @@ ALTER TABLE Users
 ALTER TABLE Principals
   DROP COLUMN ObjectId;
 
-ALTER TABLE Groups
+ALTER TABLE `Groups`
    DROP COLUMN Type;
 
diff --git a/etc/upgrade/4.4.2/content b/etc/upgrade/4.4.2/content
index 790342ddf8..e9998e54f1 100644
--- a/etc/upgrade/4.4.2/content
+++ b/etc/upgrade/4.4.2/content
@@ -22,9 +22,10 @@ our @Initial = (
 
     # fix up inconsistent denormalized owner vs owner-role group members (#32381)
     sub {
-        my $sth = RT->DatabaseHandle->dbh->prepare(q[
+        my $groups_table = RT->Config->Get('DatabaseType') eq 'mysql' ? '`Groups`' : 'Groups';
+        my $sth = RT->DatabaseHandle->dbh->prepare(qq[
             SELECT Tickets.Id, Tickets.Owner, GroupMembers.MemberId
-            FROM Groups
+            FROM $groups_table
             JOIN GroupMembers ON Groups.Id = GroupMembers.GroupId
             JOIN Tickets ON Tickets.Id = Groups.Instance
             WHERE Groups.Name = 'Owner'
diff --git a/etc/upgrade/upgrade-mysql-schema.pl b/etc/upgrade/upgrade-mysql-schema.pl
index af29a1b56f..d484ff63b6 100755
--- a/etc/upgrade/upgrade-mysql-schema.pl
+++ b/etc/upgrade/upgrade-mysql-schema.pl
@@ -306,7 +306,7 @@ sub convert_table {
     }
     for my $conversiontype (qw(char_to_binary binary_to_char)) {
         next unless @{$alter_aggregator{$conversiontype}};
-        push @sql_commands, qq{ALTER TABLE $table\n   }.
+        push @sql_commands, qq{ALTER TABLE `$table`\n   }.
             join(",\n   ",@{$alter_aggregator{$conversiontype}});
     }
 }
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 29e929e7b7..82e2b6d951 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -1760,7 +1760,7 @@ sub DropIndex {
     if ( $db_type eq 'mysql' ) {
         $args{'Table'} = $self->_CanonicTableNameMysql( $args{'Table'} );
         $res = $dbh->do(
-            'drop index '. $dbh->quote_identifier($args{'Name'}) ." on $args{'Table'}",
+            'drop index '. $dbh->quote_identifier($args{'Name'}) ." on ". $dbh->quote_identifier($args{'Table'}),
         );
     }
     elsif ( $db_type eq 'Pg' ) {
@@ -1839,9 +1839,10 @@ sub CreateIndex {
         }
     }
 
+    my $table = $self->can('QuoteName') ? $self->QuoteName( $args{'Table'} ) : $args{'Table'};
     my $sql = "CREATE"
         . ($args{'Unique'}? ' UNIQUE' : '')
-        ." INDEX $name ON $args{'Table'}"
+        ." INDEX $name ON $table"
         ."(". join( ', ', @columns ) .")"
     ;
 
diff --git a/lib/RT/Principal.pm b/lib/RT/Principal.pm
index 3f0c8416c8..a747ec4802 100644
--- a/lib/RT/Principal.pm
+++ b/lib/RT/Principal.pm
@@ -574,8 +574,9 @@ sub _HasRoleRightQuery {
                  @_
                );
 
+    my $groups_table = $self->can('QuotedTableName') ? $self->QuotedTableName('Groups') : 'Groups';
     my $query =
-        " FROM Groups, Principals, CachedGroupMembers WHERE "
+        " FROM $groups_table, Principals, CachedGroupMembers WHERE "
 
         # Never find disabled things
         . "Principals.Disabled = 0 " . "AND CachedGroupMembers.Disabled = 0 "
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 3503f67f30..15e0753596 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -1600,6 +1600,7 @@ entire database.
 sub LockForUpdate {
     my $self = shift;
 
+    my $table = $self->can('QuotedTableName') ? $self->QuotedTableName($self->Table) : $self->Table;
     my $pk = $self->_PrimaryKey;
     my $id = @_ ? $_[0] : $self->$pk;
     $self->_expire if $self->isa("DBIx::SearchBuilder::Record::Cachable");
@@ -1608,12 +1609,11 @@ sub LockForUpdate {
         # "RESERVED" on the first UPDATE/INSERT/DELETE.  Do a no-op
         # UPDATE to force the upgade.
         return RT->DatabaseHandle->dbh->do(
-            "UPDATE " .$self->Table.
-                " SET $pk = $pk WHERE 1 = 0");
+            "UPDATE $table SET $pk = $pk WHERE 1 = 0"
+        );
     } else {
         return $self->_LoadFromSQL(
-            "SELECT * FROM ".$self->Table
-                ." WHERE $pk = ? FOR UPDATE",
+            "SELECT * FROM $table WHERE $pk = ? FOR UPDATE",
             $id,
         );
     }
diff --git a/sbin/rt-validator.in b/sbin/rt-validator.in
index 33767827f1..85f8fab764 100644
--- a/sbin/rt-validator.in
+++ b/sbin/rt-validator.in
@@ -97,6 +97,7 @@ END
 
 my $dbh = $RT::Handle->dbh;
 my $db_type = RT->Config->Get('DatabaseType');
+my $groups_table = $db_type eq 'mysql' ? '`Groups`' : 'Groups' ;
 
 my %TYPE = (
     'Transactions.Field'    => 'text',
@@ -641,7 +642,7 @@ push @CHECKS, 'Tickets -> other' => sub {
     {
         my $query = <<END;
 SELECT Tickets.Id, Tickets.Owner
-FROM Groups
+FROM $groups_table
 JOIN Tickets ON Tickets.Id = Groups.Instance
 LEFT JOIN GroupMembers ON Groups.Id = GroupMembers.GroupId
 WHERE Groups.Name = 'Owner'
@@ -678,7 +679,7 @@ END
     {
         my $query = <<END;
 SELECT Tickets.Id, Tickets.Owner, GroupMembers.MemberId
-FROM Groups
+FROM $groups_table
 JOIN GroupMembers ON Groups.Id = GroupMembers.GroupId
 JOIN Tickets ON Tickets.Id = Groups.Instance
 WHERE Groups.Name = 'Owner'
@@ -967,10 +968,11 @@ push @CHECKS, 'FIX: LastUpdatedBy and Creator' => sub {
             next unless $object->_Accessible( $column, 'auto' );
 
             my $table = m2t($model);
+            $table = "`$table`" if $db_type eq 'mysql';
             my $query = <<END;
 SELECT m.id, g.id, g.Instance
 FROM
-    Groups g JOIN $table m ON g.id = m.$column
+    $groups_table g JOIN $table m ON g.id = m.$column
 WHERE
     g.Domain = ?
     AND g.Name = ?
@@ -1191,17 +1193,18 @@ push @CHECKS, 'Links: missing object' => sub {
 
         foreach my $use ( @URI_USES ) {
             my $stable = m2t( $use->{'model'} );
+            my $stablename = $db_type eq 'mysql' ? "`$stable`" : $stable;
             my $scolumn = $use->{'column'};
 
             foreach my $tmodel ( @models ) {
                 my $tclass = 'RT::'. $tmodel;
                 my $ttable = m2t($tmodel);
-
+                my $ttablename = ($db_type eq 'mysql') ? "`$ttable`" : $ttable;
                 my $tprefix = $prefix .'/'. ($tclass eq 'RT::Ticket'? 'ticket' : $tclass) .'/';
 
                 $tprefix = $prefix . '/article/' if $tclass eq 'RT::Article';
 
-                my $query = "SELECT s.id FROM $stable s LEFT JOIN $ttable t "
+                my $query = "SELECT s.id FROM $stablename s LEFT JOIN $ttablename t "
                   ." ON t.id = ". sql_str2int("SUBSTR(s.$scolumn, ?)")
                     ." WHERE s.$scolumn LIKE ? AND t.id IS NULL";
                 my @binds = (length($tprefix) + 1, sql_escape_like($tprefix).'%');
@@ -1271,6 +1274,9 @@ sub check_integrity {
     my ($ttable, @tcols) = (shift, shift);
     my %args = @_;
 
+    my $stablename = $db_type eq 'mysql' ? "`$stable`" : $stable;
+    my $ttablename = $db_type eq 'mysql' ? "`$ttable`" : $ttable;
+
     @scols = @{ $scols[0] } if ref $scols[0];
     @tcols = @{ $tcols[0] } if ref $tcols[0];
 
@@ -1278,7 +1284,7 @@ sub check_integrity {
         if $opt{'verbose'};
 
     my $query = "SELECT s.id, ". join(', ', map "s.$_", @scols)
-        ." FROM $stable s LEFT JOIN $ttable t"
+        ." FROM $stablename s LEFT JOIN $ttablename t"
         ." ON (". join(
             ' AND ', map columns_eq_cond('s', $stable, $scols[$_] => 't', $ttable, $tcols[$_]), (0..(@scols-1))
         ) .")"
@@ -1348,6 +1354,7 @@ sub check_uniqueness {
     my $on = shift;
     my %args = @_;
 
+    $on = "`$on`" if $db_type eq 'mysql';
     my @columns = @{ $args{'columns'} };
 
     print "Checking uniqueness of ( ", join(', ', map "'$_'", @columns )," ) in table '$on'\n"
@@ -1388,14 +1395,16 @@ sub check_uniqueness {
 
 sub load_record {
     my ($table, $id) = @_;
-    my $sth = execute_query( "SELECT * FROM $table WHERE id = ?", $id );
+    my $tablename = $db_type eq 'mysql' ? "`$table`" : $table;
+    my $sth = execute_query( "SELECT * FROM $tablename WHERE id = ?", $id );
     return $sth->fetchrow_hashref('NAME_lc');
 }
 
 sub delete_record {
     my ($table, $id) = (@_);
     print "Deleting record #$id in $table\n" if $opt{'verbose'};
-    my $query = "DELETE FROM $table WHERE id = ?";
+    my $tablename = $db_type eq 'mysql' ? "`$table`" : $table;
+    my $query = "DELETE FROM $tablename WHERE id = ?";
     $redo_check{ $_ } = 1 foreach @{ $redo_on{'Delete'}{ $table } || [] };
     return execute_query( $query, $id );
 }
@@ -1411,6 +1420,8 @@ sub update_records {
     my $where = shift;
     my $what = shift;
 
+    my $tablename = $db_type eq 'mysql' ? "`$table`" : $table;
+
     my (@where_cols, @where_binds);
     while ( my ($k, $v) = each %$where ) { push @where_cols, $k; push @where_binds, $v; }
 
@@ -1418,7 +1429,7 @@ sub update_records {
     while ( my ($k, $v) = each %$what ) { push @what_cols, $k; push @what_binds, $v; }
 
     print "Updating record(s) in $table\n" if $opt{'verbose'};
-    my $query = "UPDATE $table SET ". join(', ', map "$_ = ?", @what_cols)
+    my $query = "UPDATE $tablename SET ". join(', ', map "$_ = ?", @what_cols)
         ." WHERE ". join(' AND ', map "$_ = ?", @where_cols);
     $redo_check{ $_ } = 1 foreach @{ $redo_on{'Update'}{ $table } || [] };
     return execute_query( $query, @what_binds, @where_binds );
diff --git a/t/web/query_log.t b/t/web/query_log.t
index cfb4d81d71..4d9ac87eb7 100644
--- a/t/web/query_log.t
+++ b/t/web/query_log.t
@@ -15,4 +15,6 @@ $m->get_ok("/Admin/Tools/Queries.html");
 $m->text_contains("/index.html", "we include info about a page we hit while logging in");
 $m->text_contains("Stack:", "stack traces");
 $m->text_like(qr{/autohandler:\d+}, "stack trace includes mason components");
-$m->text_contains("SELECT * FROM Principals WHERE id = '".$root->id."'", "we interpolate bind params");
+
+my $id = $root->id;
+$m->text_like(qr/SELECT \* FROM .?Principals.? WHERE id = '$id'/, "we interpolate bind params");

commit 797c2b89aef1035360cf9f2f4bd1d7cac053ecfd
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jan 21 05:19:42 2021 +0800

    Update DBIx::SearchBuilder to 1.69 to work with MySQL 8

diff --git a/sbin/rt-test-dependencies.in b/sbin/rt-test-dependencies.in
index 159d729d32..ecbf0ad910 100644
--- a/sbin/rt-test-dependencies.in
+++ b/sbin/rt-test-dependencies.in
@@ -252,7 +252,7 @@ Apache::Request
 .
 
 $deps{'MYSQL'} = [ text_to_hash( << '.') ];
-DBIx::SearchBuilder 1.68
+DBIx::SearchBuilder 1.69
 DBD::mysql 2.1018
 .
 

-----------------------------------------------------------------------


More information about the rt-commit mailing list