[Rt-commit] rt branch, 5.0/convert-fulltextsearch-utf8mb4, updated. rt-5.0.0beta1-46-gf335b08279

Aaron Trevena ast at bestpractical.com
Thu Jul 2 09:23:09 EDT 2020


The branch, 5.0/convert-fulltextsearch-utf8mb4 has been updated
       via  f335b0827905d015436a63dd395d5d7261a7e4d5 (commit)
       via  e1dbfce4c671fb679002e01b5c52229ed840969a (commit)
      from  fb59da120ce967900fb4be1e14e643082a7beb15 (commit)

Summary of changes:
 etc/upgrade/4.5.8/{content => ddl} | 10 +++---
 sbin/rt-setup-database.in          | 74 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 4 deletions(-)
 rename etc/upgrade/4.5.8/{content => ddl} (87%)

- Log -----------------------------------------------------------------
commit e1dbfce4c671fb679002e01b5c52229ed840969a
Author: Aaron Trevena <ast at bestpractical.com>
Date:   Thu Jul 2 14:19:27 2020 +0100

    Add support for ddl upgrade perl scripts
    
    Add new alter action to rt-setup-database that will run perl require
    on upgrade scripts named ddl in etc/upgrade/v/

diff --git a/sbin/rt-setup-database.in b/sbin/rt-setup-database.in
index c3391f0445..627997f90f 100644
--- a/sbin/rt-setup-database.in
+++ b/sbin/rt-setup-database.in
@@ -348,6 +348,76 @@ sub action_coredata {
     return $RT::Handle->InsertInitialData;
 }
 
+sub action_alter {
+    my %args = @_;
+
+    $log_actions = 1;
+    print "Now altering database.\n";
+
+    my $file = $args{'datafile'};
+    $file ||= $args{'datadir'}."/ddl";
+
+    my $individual_id = Data::GUID->new->as_string();
+    my %upgrade_data = (
+        action   => 'alter',
+        filename => Cwd::abs_path($file),
+        stage    => 'before',
+        full_id  => $full_id,
+        individual_id => $individual_id
+    );
+    $upgrade_data{'ext_version'} = $ext_version if $ext_version;
+
+    open my $handle, '<', $file or warn "Unable to open $file: $!";
+    $upgrade_data{content} = do {local $/; <$handle>} if $handle;
+
+    RT->System->AddUpgradeHistory($package => \%upgrade_data);
+
+    our ( @Initial, @Final );
+    local ( @Initial, @Final );
+
+    local $@;
+
+    my ($ok, $message);
+  ALTER: {
+        $ok = eval { require $file };
+        unless ($ok) {
+            ($ok, $message) = (0, "Couldn't load ddl script '$file':\nERROR:" . $@);
+            last ALTER;
+        }
+
+        my %phases = (
+            initial => \@Initial,
+            final => \@Final
+        );
+        my $dbh = get_admin_dbh();
+        foreach my $phase (keys %phases) {
+            if (scalar @{$phases{$phase}}) {
+                $RT::Logger->debug("Running $phase actions...");
+                foreach ( @{$phases{$phase}} ) {
+                    local $@;
+                    $ok = eval { $_->(dbh => $dbh) };
+                    unless ($ok) {
+                        warn "One of $phase functions failed: $@";
+                        ($ok, $message) = (0, "One of $phase functions failed: $@");
+                        last ALTER;
+                    }
+                }
+                $RT::Logger->debug("Done.");
+            }
+        }
+        ($ok, $message) = (1, 'Done altering schema');
+    }
+
+    %upgrade_data = (
+        stage         => 'after',
+        individual_id => $individual_id,
+        return_value  => [ $ok, $message ]
+    );
+    RT->System->AddUpgradeHistory($package => \%upgrade_data);
+
+    return ( $ok, $message );
+}
+
 sub action_insert {
     state $RAN_INIT;
     my %args = @_;
@@ -565,6 +635,10 @@ sub action_upgrade {
             ( $ret, $msg ) = action_indexes( %tmp );
             return ( $ret, $msg ) unless $ret;
         }
+        if ( -e "$base_dir/$v/ddl" ) {
+            ( $ret, $msg ) = action_alter(%tmp);
+            return ( $ret, $msg ) unless $ret;
+        }
         if ( -e "$base_dir/$v/content" ) {
             ( $ret, $msg ) = action_insert( %tmp );
             return ( $ret, $msg ) unless $ret;

commit f335b0827905d015436a63dd395d5d7261a7e4d5
Author: Aaron Trevena <ast at bestpractical.com>
Date:   Thu Jul 2 14:22:13 2020 +0100

    Updated upgrade script for fulltextsearch tables

diff --git a/etc/upgrade/4.5.8/content b/etc/upgrade/4.5.8/ddl
similarity index 87%
rename from etc/upgrade/4.5.8/content
rename to etc/upgrade/4.5.8/ddl
index 6bedd6a907..4bee078730 100644
--- a/etc/upgrade/4.5.8/content
+++ b/etc/upgrade/4.5.8/ddl
@@ -4,19 +4,20 @@ use warnings;
 our @Final;
 
 push @Final, sub {
+    my %args = @_;
     # skip unless fulltextsearch is enabled
     my $fts_config = RT->Config->Get('FullTextSearch');
-    return unless ($fts_config->{'Enable'});
+    return 1 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');
+    return 1 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->{'NoFulltextsearchTableUpgrade'});
+    return 1 if ($fts_config->{'NoFulltextsearchTableUpgrade'});
 
-    my $dbh = RT->DatabaseHandle->dbh;
+    my $dbh = $args{dbh};
 
     # get tablename from config, fall back to default tablename
     my $table = $fts_config->{'Table'} || 'AttachmentsIndex';
@@ -29,6 +30,7 @@ push @Final, sub {
             warn "failed to update fulltext search table $table key to bigint : $@ : " . $dbh->errstr
         }
     }
+    return 1;
 };
 
 ###

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


More information about the rt-commit mailing list