[Rt-commit] rt branch, 5.0/update-full-text-search-table-schema, created. rt-5.0.0beta2-49-g6aef948a33

? sunnavy sunnavy at bestpractical.com
Fri Jul 10 10:50:11 EDT 2020


The branch, 5.0/update-full-text-search-table-schema has been created
        at  6aef948a33d8da6fd6cafe661f681716d08347d9 (commit)

- Log -----------------------------------------------------------------
commit 2cdc26cd740a68b626247ece4c838a7c57b4a40d
Author: Aaron Trevena <ast at bestpractical.com>
Date:   Fri Jul 10 07:32:17 2020 +0100

    Update id column in full text search table to BIGINT
    
    It references to attachment id, which is BIGINT already.

diff --git a/sbin/rt-setup-fulltext-index.in b/sbin/rt-setup-fulltext-index.in
index bca79156b4..f12bc6b552 100644
--- a/sbin/rt-setup-fulltext-index.in
+++ b/sbin/rt-setup-fulltext-index.in
@@ -178,7 +178,7 @@ if ( $DB{'type'} eq 'mysql' ) {
 
     my $engine = $RT::Handle->dbh->{mysql_serverversion} < 50600 ? "MyISAM" : "InnoDB";
     my $schema = "CREATE TABLE $table ( "
-        ."id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,"
+        ."id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,"
         ."Content LONGTEXT ) ENGINE=$engine CHARACTER SET utf8mb4";
     insert_schema( $schema );
 
@@ -326,7 +326,7 @@ elsif ( $DB{'type'} eq 'Pg' ) {
         $drop = "DROP TABLE $table";
         push @schema, split /;\n+/, <<SCHEMA;
 CREATE TABLE $table (
-    id SERIAL,
+    id BIGSERIAL,
     $column tsvector
 );
 GRANT SELECT, INSERT, UPDATE, DELETE ON $table TO "$DB{user}"

commit 66675af5cb80d9d45a4b1771696c1f5998be58cb
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jul 9 21:18:15 2020 +0800

    Pass admin dbh to @Initial and @Final blocks for upgrade
    
    The initial reason is we want to alter fulltext search table for the
    bigint/utf8mb4 schema change, which requires admin database handle.

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 3fd9b52974..fc003ca594 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -846,6 +846,7 @@ sub InsertData {
     my $root_password = shift;
     my %args     = (
         disconnect_after => 1,
+        admin_dbh        => undef,
         @_
     );
 
@@ -925,7 +926,7 @@ sub InsertData {
         $RT::Logger->debug("Running initial actions...");
         foreach ( @Initial ) {
             local $@;
-            eval { $_->(); 1 } or return (0, "One of initial functions failed: $@");
+            eval { $_->( admin_dbh => $args{admin_dbh} ); 1 } or return (0, "One of initial functions failed: $@");
         }
         $RT::Logger->debug("Done.");
     }
@@ -1850,7 +1851,7 @@ sub InsertData {
         $RT::Logger->debug("Running final actions...");
         for ( @Final ) {
             local $@;
-            eval { $_->(); };
+            eval { $_->( admin_dbh => $args{admin_dbh} ); };
             $RT::Logger->error( "Failed to run one of final actions: $@" )
                 if $@;
         }
diff --git a/sbin/rt-setup-database.in b/sbin/rt-setup-database.in
index 38e658544e..18a27b2b6e 100644
--- a/sbin/rt-setup-database.in
+++ b/sbin/rt-setup-database.in
@@ -390,7 +390,7 @@ sub action_insert {
 
     my @ret;
 
-    my $upgrade = sub { @ret = $RT::Handle->InsertData( $file, $root_password ) };
+    my $upgrade = sub { @ret = $RT::Handle->InsertData( $file, $root_password, admin_dbh => get_admin_dbh() ) };
 
     for my $file (@{$args{backcompat} || []}) {
         my $lines = do {local $/; local @ARGV = ($file); <>};

commit 6aef948a33d8da6fd6cafe661f681716d08347d9
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jul 9 21:53:24 2020 +0800

    Add upgrade step to update full text search table schema for bigint/utf8mb4

diff --git a/etc/upgrade/4.5.8/content b/etc/upgrade/4.5.8/content
new file mode 100644
index 0000000000..c9d9a40ab5
--- /dev/null
+++ b/etc/upgrade/4.5.8/content
@@ -0,0 +1,20 @@
+use strict;
+use warnings;
+
+our @Final = sub {
+    my %args = @_;
+    my $db_type = RT->Config->Get('DatabaseType');
+    return unless $db_type =~ /Pg|mysql/;
+
+    my $fts_config = RT->Config->Get('FullTextSearch') or return;
+    return unless $fts_config->{'Enable'} && $fts_config->{'Indexed'};
+
+    my $sql;
+    if ( $db_type eq 'Pg' ) {
+        $sql = "ALTER TABLE $fts_config->{'Table'} ALTER COLUMN id SET DATA TYPE BIGINT";
+    }
+    else {
+        $sql = "ALTER TABLE $fts_config->{'Table'} MODIFY id BIGINT NOT NULL AUTO_INCREMENT, CONVERT TO CHARACTER SET utf8mb4";
+    }
+    $args{admin_dbh}->do($sql) or warn "Couldn't run SQL query: $sql: " . $args{admin_dbh}->errstr;
+};

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


More information about the rt-commit mailing list