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

Aaron Trevena ast at bestpractical.com
Fri Jul 10 02:44:33 EDT 2020


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

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

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

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 4c3398055e75fdfbcb81ec9ef08f19f8f7a55a1c
Author: Aaron Trevena <ast at bestpractical.com>
Date:   Fri Jul 10 07:32:58 2020 +0100

    Update id column in fulltextsearch table to BIGINT on upgrade
    
    Update id column in fulltextsearch index table to BIGINT for postgres
    and mysql in 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;
+}

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


More information about the rt-commit mailing list