[Rt-commit] rt branch, 4.2/upgrading-indexes-and-review, updated. rt-4.1.8-578-g6ff052f
Ruslan Zakirov
ruz at bestpractical.com
Thu Aug 22 09:47:42 EDT 2013
The branch, 4.2/upgrading-indexes-and-review has been updated
via 6ff052f7ab7de2dca7de1ea83af280df99b5e9bc (commit)
from a5a50b1262069f3863eb18602e09a6a7b14d08b1 (commit)
Summary of changes:
etc/upgrade/4.1.10/indexes | 70 ++++------------------------------------------
lib/RT/Handle.pm | 61 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 65 deletions(-)
- Log -----------------------------------------------------------------
commit 6ff052f7ab7de2dca7de1ea83af280df99b5e9bc
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Fri Jul 12 13:47:02 2013 +0300
move functions into RT::Handle from upgrade script
diff --git a/etc/upgrade/4.1.10/indexes b/etc/upgrade/4.1.10/indexes
index 8f0ce10..546a3bd 100644
--- a/etc/upgrade/4.1.10/indexes
+++ b/etc/upgrade/4.1.10/indexes
@@ -67,25 +67,25 @@ use warnings;
# cached group members
{
- MakeSureIndexExists(
+ $RT::Handle->MakeSureIndexExists(
Table => 'CachedGroupMembers',
Columns => ['MemberId', 'ImmediateParentId'],
);
- MakeSureIndexExists(
+ $RT::Handle->MakeSureIndexExists(
Table => 'CachedGroupMembers',
Columns => ['MemberId', 'GroupId'],
Optional => ['Disabled'],
);
- DropIndexesThatArePrefix(
+ $RT::Handle->DropIndexesThatArePrefix(
Table => 'CachedGroupMembers',
Columns => ['MemberId', 'GroupId', 'Disabled'],
);
- MakeSureIndexExists(
+ $RT::Handle->MakeSureIndexExists(
Table => 'CachedGroupMembers',
Columns => ['GroupId', 'MemberId'],
Optional => ['Disabled'],
);
- DropIndexesThatArePrefix(
+ $RT::Handle->DropIndexesThatArePrefix(
Table => 'CachedGroupMembers',
Columns => ['GroupId', 'MemberId', 'Disabled'],
);
@@ -106,64 +106,4 @@ foreach my $table ('Users', 'Tickets') {
}
}
-
-sub MakeSureIndexExists {
- my %args = ( Table => undef, Columns => [], Optional => [], @_ );
-
- my @list = $RT::Handle->IndexesThatBeginWith(
- Table => $args{'Table'}, Columns => [@{$args{'Columns'}}, @{$args{'Optional'}}],
- );
- if (@list) {
- RT->Logger->info( ucfirst $RT::Handle->IndexDescription(
- Table => $args{'Table'}, Columns => [@{$args{'Columns'}}, @{$args{'Optional'}}],
- ). ' exists.' );
- return;
- }
-
- @list = $RT::Handle->IndexesThatBeginWith(
- Table => $args{'Table'}, Columns => $args{'Columns'},
- );
- if ( !@list ) {
- my ($status, $msg) = $RT::Handle->CreateIndex(
- Table => $args{'Table'}, Columns => [@{$args{'Columns'}}, @{$args{'Optional'}}],
- );
- RT->Logger->info($msg);
- }
- else {
- RT->Logger->info(
- ucfirst $RT::Handle->IndexDescription(
- %{$list[0]}
- )
- .' exists, you may consider replacing it with '
- . $RT::Handle->IndexDescription(
- Table => $args{'Table'}, Columns => [@{$args{'Columns'}}, @{$args{'Optional'}}],
- )
- );
- }
-}
-
-sub DropIndexesThatArePrefix {
- my %args = ( Table => undef, Columns => [], @_ );
-
- my @list = $RT::Handle->IndexesThatBeginWith(
- Table => $args{'Table'}, Columns => [$args{'Columns'}[0]],
- );
-
- my $checking = join ',', map lc $_, @{ $args{'Columns'} }, '';
- foreach my $i ( splice @list ) {
- my $columns = join ',', @{ $i->{'Columns'} }, '';
- next unless $checking =~ /^\Q$columns/i;
-
- push @list, $i;
- }
- pop @list;
-
- foreach my $i ( @list ) {
- my ($status, $msg) = $RT::Handle->DropIndex(
- Table => $i->{'Table'}, Name => $i->{'Name'},
- );
- RT->Logger->info($msg);
- }
-}
-
1;
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 36769df..f7f9b41 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -1543,6 +1543,67 @@ sub IndexDescription {
return $desc;
}
+sub MakeSureIndexExists {
+ my $self = shift;
+ my %args = ( Table => undef, Columns => [], Optional => [], @_ );
+
+ my @list = $self->IndexesThatBeginWith(
+ Table => $args{'Table'}, Columns => [@{$args{'Columns'}}, @{$args{'Optional'}}],
+ );
+ if (@list) {
+ RT->Logger->info( ucfirst $self->IndexDescription(
+ Table => $args{'Table'}, Columns => [@{$args{'Columns'}}, @{$args{'Optional'}}],
+ ). ' exists.' );
+ return;
+ }
+
+ @list = $self->IndexesThatBeginWith(
+ Table => $args{'Table'}, Columns => $args{'Columns'},
+ );
+ if ( !@list ) {
+ my ($status, $msg) = $self->CreateIndex(
+ Table => $args{'Table'}, Columns => [@{$args{'Columns'}}, @{$args{'Optional'}}],
+ );
+ RT->Logger->info($msg);
+ }
+ else {
+ RT->Logger->info(
+ ucfirst $self->IndexDescription(
+ %{$list[0]}
+ )
+ .' exists, you may consider replacing it with '
+ . $self->IndexDescription(
+ Table => $args{'Table'}, Columns => [@{$args{'Columns'}}, @{$args{'Optional'}}],
+ )
+ );
+ }
+}
+
+sub DropIndexesThatArePrefix {
+ my $self = shift;
+ my %args = ( Table => undef, Columns => [], @_ );
+
+ my @list = $self->IndexesThatBeginWith(
+ Table => $args{'Table'}, Columns => [$args{'Columns'}[0]],
+ );
+
+ my $checking = join ',', map lc $_, @{ $args{'Columns'} }, '';
+ foreach my $i ( splice @list ) {
+ my $columns = join ',', @{ $i->{'Columns'} }, '';
+ next unless $checking =~ /^\Q$columns/i;
+
+ push @list, $i;
+ }
+ pop @list;
+
+ foreach my $i ( @list ) {
+ my ($status, $msg) = $self->DropIndex(
+ Table => $i->{'Table'}, Name => $i->{'Name'},
+ );
+ RT->Logger->info($msg);
+ }
+}
+
# log a mason stack trace instead of a Carp::longmess because it's less painful
# and uses mason component paths properly
sub _LogSQLStatement {
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list