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

Aaron Trevena ast at bestpractical.com
Thu Jul 9 07:26:52 EDT 2020


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

- Log -----------------------------------------------------------------
commit 35a91a127694e411c3f04dcfb8fd3ae2dad342ac
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/etc/upgrade/4.5.8/content b/etc/upgrade/4.5.8/content
new file mode 100644
index 0000000000..3b9ba9f040
--- /dev/null
+++ b/etc/upgrade/4.5.8/content
@@ -0,0 +1,58 @@
+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');
+
+    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