[Rt-commit] rt branch, 4.0/pg-9.2-comptibility, created. rt-4.0.13-54-g5ab920e

Ruslan Zakirov ruz at bestpractical.com
Tue Jun 4 10:00:57 EDT 2013


The branch, 4.0/pg-9.2-comptibility has been created
        at  5ab920ec6ac613a61ea607fefad2b773c4ccdf40 (commit)

- Log -----------------------------------------------------------------
commit 7e7dc4e305d7237c6256bac6d196efd1976526c7
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon Jun 3 17:45:01 2013 +0400

    extract our code that fetches table names
    
    keep function private, so far we use it in upgrade
    scripts and tests.

diff --git a/etc/upgrade/3.9.8/content b/etc/upgrade/3.9.8/content
index db717cd..e10d42f 100644
--- a/etc/upgrade/3.9.8/content
+++ b/etc/upgrade/3.9.8/content
@@ -1,9 +1,6 @@
 @Initial = sub {
-    my $dbh = $RT::Handle->dbh;
-    my $sth = $dbh->table_info( '', undef, undef, "'TABLE'");
     my $found_fm_tables = {};
-    while ( my $table = $sth->fetchrow_hashref ) {
-        my $name = $table->{TABLE_NAME} || $table->{table_name};
+    foreach my $name ( $RT::Handle->_TableNames ) {
         next unless $name =~ /^fm_/i;
         $found_fm_tables->{lc $name}++;
     }
diff --git a/etc/upgrade/upgrade-articles.in b/etc/upgrade/upgrade-articles.in
index 6e8d1d7..9fdecb3 100644
--- a/etc/upgrade/upgrade-articles.in
+++ b/etc/upgrade/upgrade-articles.in
@@ -64,10 +64,8 @@ my $db_type = RT->Config->Get('DatabaseType');
 
 my $dbh = $RT::Handle->dbh;
 
-my $sth = $dbh->table_info( '', undef, undef, "'TABLE'");
 my $found_fm_tables;
-while ( my $table = $sth->fetchrow_hashref ) {
-    my $name = $table->{TABLE_NAME} || $table->{'table_name'}; # Oracle's table_info affected by NAME_lc
+foreach my $name ( $RT::Handle->_TableNames ) {
     next unless $name =~ /^fm_/i;
     $found_fm_tables->{lc $name}++;
 }
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 95919ed..a611b0f 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -1203,6 +1203,21 @@ sub _LogSQLStatement {
     push @{$self->{'StatementLog'}} , ([Time::HiRes::time(), $statement, [@bind], $duration, HTML::Mason::Exception->new->as_string]);
 }
 
+
+sub _TableNames {
+    my $self = shift;
+    my $dbh = shift || $self->dbh;
+
+    my @res;
+
+    my $sth = $dbh->table_info( '', undef, undef, "'TABLE'");
+    while ( my $table = $sth->fetchrow_hashref ) {
+        push @res, $table->{TABLE_NAME} || $table->{table_name};
+    }
+
+    return @res;
+}
+
 __PACKAGE__->FinalizeDatabaseType;
 
 RT::Base->_ImportOverlays();
diff --git a/t/shredder/utils.pl b/t/shredder/utils.pl
index 7be9513..358500a 100644
--- a/t/shredder/utils.pl
+++ b/t/shredder/utils.pl
@@ -279,11 +279,7 @@ sub dump_sqlite
     my $dbh = shift;
     my %args = ( CleanDates => 1, @_ );
 
-    my $old_fhkn = $dbh->{'FetchHashKeyName'};
-    $dbh->{'FetchHashKeyName'} = 'NAME_lc';
-
-    my $sth = $dbh->table_info( '', '%', '%', 'TABLE' ) || die $DBI::err;
-    my @tables = keys %{$sth->fetchall_hashref( 'table_name' )};
+    my @tables = $RT::Handle->_TableNames( $dbh );
 
     my $res = {};
     foreach my $t( @tables ) {
@@ -293,7 +289,6 @@ sub dump_sqlite
         die $DBI::err if $DBI::err;
     }
 
-    $dbh->{'FetchHashKeyName'} = $old_fhkn;
     return $res;
 }
 

commit 5ab920ec6ac613a61ea607fefad2b773c4ccdf40
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Jun 4 17:57:21 2013 +0400

    require newer DBD::Pg on Pg 9.2 for upgrade
    
    We use DBI's table_info method in upgrade scripts.
    It fails on Pg 9.2 with old DBD::Pg driver. We don't
    have to bump required version for all Pg users, but
    can help users of Pg 9.2 to solve the problem by
    providing better error message.

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index a611b0f..ca6f2e4 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -1208,6 +1208,17 @@ sub _TableNames {
     my $self = shift;
     my $dbh = shift || $self->dbh;
 
+    {
+        local $@;
+        if (
+            $dbh->{Driver}->{Name} eq 'Pg'
+            && $dbh->{'pg_server_version'} >= 90200
+            && !eval { DBD::Pg->VERSION('2.19.3'); 1 }
+        ) {
+            die "You're using PostgreSQL 9.2 or newer. You have to upgrade DBD::Pg module to 2.19.3 or newer: $@";
+        }
+    }
+
     my @res;
 
     my $sth = $dbh->table_info( '', undef, undef, "'TABLE'");

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


More information about the Rt-commit mailing list