[Rt-commit] rt branch, 3.8-trunk, updated. rt-3.8.8-50-gf2d703a

Emannuel Lacour elacour at bestpractical.com
Fri May 14 12:25:02 EDT 2010


The branch, 3.8-trunk has been updated
       via  f2d703a52c80de640c89d495caed39bbd1175fe8 (commit)
      from  185751a6544342ef7b696fee410f84c192acd454 (commit)

Summary of changes:
 UPGRADING                                          |    8 +++
 ...k_cgm_table.pl => shrink_transactions_table.pl} |   46 ++++++++++----------
 2 files changed, 31 insertions(+), 23 deletions(-)
 copy etc/upgrade/{shrink_cgm_table.pl => shrink_transactions_table.pl} (56%)

- Log -----------------------------------------------------------------
commit f2d703a52c80de640c89d495caed39bbd1175fe8
Author: Emmanuel Lacour <elacour at easter-eggs.com>
Date:   Fri May 14 18:23:55 2010 +0200

    Setup script and instruction to shrink transactions table from useless records
    created in the past by Group::_CreateACLEquivialenceGroup

diff --git a/UPGRADING b/UPGRADING
index 150a7e9..8f18073 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -18,6 +18,14 @@ If you are using MySQL, please read the instructions in UPGRADING.mysql as
 well.
 
 *******
+UPGRADING FROM 3.8.8 and earlier - Changes:
+
+We've proved that it's possible to delete set of records
+from Transactions table without losing functionality. To delete
+record run the following script:
+
+    perl -I /opt/rt3/local/lib -I /opt/rt3/lib etc/upgrade/shrink_transactions_table.pl
+
 UPGRADING FROM 3.8.7 and earlier - Changes:
 
 RT's ChartFont option has been changed from a string to a hash which
diff --git a/etc/upgrade/shrink_transactions_table.pl b/etc/upgrade/shrink_transactions_table.pl
new file mode 100644
index 0000000..c5dc4b6
--- /dev/null
+++ b/etc/upgrade/shrink_transactions_table.pl
@@ -0,0 +1,72 @@
+#!/usr/bin/perl
+
+use 5.8.3;
+use strict;
+use warnings;
+
+use RT;
+RT::LoadConfig();
+RT->Config->Set('LogToScreen' => 'debug');
+RT::Init();
+
+use RT::Transactions;
+my $txns = RT::Transactions->new( $RT::SystemUser );
+$txns->Limit(
+    FIELD => 'ObjectType',
+    OPERATOR => '=',
+    VALUE => 'RT::Group',
+    QUOTEVALUE => 1,
+    ENTRYAGGREGATOR => 'AND',
+);
+
+my $alias = $txns->Join(
+    TYPE   => 'LEFT',
+    FIELD1 => 'ObjectId',
+    TABLE2 => 'Groups',
+    FIELD2 => 'Id',
+);
+$txns->Limit(
+    ALIAS => $alias,
+    FIELD => 'Domain',
+    OPERATOR => '=',
+    VALUE => 'ACLEquivalence',
+    QUOTEVALUE => 1,
+    ENTRYAGGREGATOR => 'AND',
+);
+
+$txns->Limit(
+    ALIAS => $alias,
+    FIELD => 'Type',
+    OPERATOR => '=',
+    VALUE => 'UserEquiv',
+    QUOTEVALUE => 1,
+    ENTRYAGGREGATOR => 'AND',
+);
+
+FetchNext( $txns, 'init' );
+while ( my $rec = FetchNext( $txns ) ) {
+    $RT::Handle->BeginTransaction;
+    my ($status) = $rec->Delete;
+    unless ($status) {
+        print STDERR "Couldn't delete TXN #". $rec->id;
+        exit 1;
+    }
+    $RT::Handle->Commit;
+}
+
+use constant PAGE_SIZE => 1000;
+sub FetchNext {
+    my ($objs, $init) = @_;
+    if ( $init ) {
+        $objs->RowsPerPage( PAGE_SIZE );
+        $objs->FirstPage;
+        return;
+    }
+
+    my $obj = $objs->Next;
+    return $obj if $obj;
+    $objs->RedoSearch;
+    $objs->FirstPage;
+    return $objs->Next;
+}
+

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


More information about the Rt-commit mailing list