[Rt-commit] rt branch, 5.0/fulltextsearch-bigint-update, created. rt-5.0.0beta1-43-ge58d3d30f5

Aaron Trevena ast at bestpractical.com
Tue Jun 30 12:17:43 EDT 2020


The branch, 5.0/fulltextsearch-bigint-update has been created
        at  e58d3d30f59ce0c061e3fb441c90470d722d6735 (commit)

- Log -----------------------------------------------------------------
commit e58d3d30f59ce0c061e3fb441c90470d722d6735
Author: Aaron Trevena <ast at bestpractical.com>
Date:   Tue Jun 30 17:15:29 2020 +0100

    Update id column in fulltextsearch table to BIGINT
    
    Update id column in fulltextsearch index table to BIGINT for postgres
    and mysql when creating in fulltext search setup script and upgrade
    script.

diff --git a/docs/UPGRADING-5.0 b/docs/UPGRADING-5.0
index e82a5670d0..bbf7f175c8 100644
--- a/docs/UPGRADING-5.0
+++ b/docs/UPGRADING-5.0
@@ -58,6 +58,9 @@ while running because MySQL, MariaDB, and Postgres will create a
 temporary copy of the table while running. If you don't have sufficient
 space, it can cause this step to fail.
 
+You can skip this step by setting NoBigintUpgrade to 1 in the $FullTextSearch
+section of your RT configuration.
+
 =back
 
 =head2 Notable Changes
diff --git a/etc/upgrade/4.5.8/content b/etc/upgrade/4.5.8/content
new file mode 100644
index 0000000000..19ddfc9133
--- /dev/null
+++ b/etc/upgrade/4.5.8/content
@@ -0,0 +1,62 @@
+use strict;
+use warnings;
+
+our @Final;
+
+push @Final, sub {
+    # skip unless fulltextsearch is enabled
+    my $fts_config = RT->Config->Get('FullTextSearch');
+    return unless ($fts_config->{'Enable'});
+
+    # check config to see if db type is applicable
+    my $db_type = RT->Config->Get('DatabaseType');
+    return unless ($db_type eq 'Pg' or $db_type eq 'mysql');
+
+    # check we don't have a flag or config to not upgrade to bigint as the
+    # size of tables could be large and users may want to do this as a seperate step
+    return if ($fts_config->{'NoBigintUpgrade'} or $ENV{NO_BIGINT_UPGRADE});
+
+    my $dbh = RT->DatabaseHandle->dbh;
+
+    # get tablename from config, fall back to default tablename
+    my $table = $fts_config->{'Table'} || 'AttachmentsIndex';
+    if (table_exists($dbh, $table)) {
+        my $query = ($db_type eq 'Pg') ? get_pg_ddl_query($table) : get_mysql_ddl_query($table) ;
+        my $rv;
+        eval { $rv = $dbh->do($query); };
+        # check dbh err string
+        if ($@) {
+            warn "failed to update fulltext search table $table key to bigint : $@ : " . $dbh->errstr
+        }
+    }
+};
+
+###
+
+sub get_pg_ddl_query {
+    my ($table) = @_;
+    return "ALTER TABLE $table ALTER COLUMN id SET DATA TYPE BIGINT;";
+}
+
+sub get_mysql_ddl_query {
+    my ($table) = @_;
+    return "ALTER TABLE $table MODIFY id BIGINT NOT NULL AUTO_INCREMENT;";
+}
+
+sub table_exists {
+    my ($dbh,$table) = @_;
+    my $schema = RT->Config->Get('DatabaseName');
+    if (RT->Config->Get('DatabaseType') eq 'Pg') {
+        $table = lc($table);
+        $schema = 'public';
+    }
+    my $exists = 0;
+    eval {
+        my $sth = $dbh->table_info('%', $schema, $table, 'TABLE');
+        $sth->execute or die $dbh->errstr;
+        my @info = $sth->fetchrow_array;
+        $exists = scalar @info;
+    };
+    warn "couldn't get table $@" if $@;
+    return $exists;
+}
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}"

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


More information about the rt-commit mailing list