[Rt-commit] rt branch, 4.2/oracle-upgrade, created. rt-4.2.0-48-g5ea0b17

Alex Vandiver alexmv at bestpractical.com
Thu Nov 7 17:22:16 EST 2013


The branch, 4.2/oracle-upgrade has been created
        at  5ea0b17df6f407eb54f53b81f797860c3e988b5f (commit)

- Log -----------------------------------------------------------------
commit d939930e3df739f8d781e010b50f9c635b2ab7e1
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Nov 1 16:11:05 2013 -0400

    Fix format of ALTER TABLE statements for Oracle

diff --git a/etc/upgrade/4.1.1/schema.Oracle b/etc/upgrade/4.1.1/schema.Oracle
index 180cf0c..4590585 100644
--- a/etc/upgrade/4.1.1/schema.Oracle
+++ b/etc/upgrade/4.1.1/schema.Oracle
@@ -11,7 +11,7 @@ CREATE TABLE ObjectScrips (
         LastUpdatedBy   NUMBER(11,0) DEFAULT 0 NOT NULL,
         LastUpdated     DATE
 );
-ALTER TABLE Scrips ADD COLUMN Disabled int2 NOT NULL DEFAULT 0;
+ALTER TABLE Scrips ADD Disabled NUMBER(11,0) DEFAULT 0 NOT NULL;
 
 INSERT INTO ObjectScrips(
     id, Scrip, Stage, ObjectId,
diff --git a/etc/upgrade/4.1.22/schema.Oracle b/etc/upgrade/4.1.22/schema.Oracle
index 6ce5646..273779b 100644
--- a/etc/upgrade/4.1.22/schema.Oracle
+++ b/etc/upgrade/4.1.22/schema.Oracle
@@ -1 +1 @@
-ALTER TABLE Users ADD COLUMN SMIMECertificate CLOB;
+ALTER TABLE Users ADD SMIMECertificate CLOB;
diff --git a/etc/upgrade/4.1.5/schema.Oracle b/etc/upgrade/4.1.5/schema.Oracle
index b0b4d4c..648784d 100644
--- a/etc/upgrade/4.1.5/schema.Oracle
+++ b/etc/upgrade/4.1.5/schema.Oracle
@@ -1,5 +1,6 @@
 # Template column
 ALTER TABLE Scrips RENAME COLUMN Template TO TemplateOld;
-ALTER TABLE Scrips ADD COLUMN Template VARCHAR2(200) NOT NULL;
-UPDATE TABLE Scrips SET Template = CAST(TemplateOld AS varchar2);
-ALTER TABLE Scrips DROP COLUMN TemplateOld;
\ No newline at end of file
+ALTER TABLE Scrips ADD Template VARCHAR2(200);
+UPDATE Scrips SET Template = CAST(TemplateOld AS varchar2(200));
+ALTER TABLE Scrips MODIFY Template VARCHAR2(200) NOT NULL;
+ALTER TABLE Scrips DROP COLUMN TemplateOld;

commit a256a691c036b37890a4e1dc196f85fc570aedd7
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Nov 1 16:11:33 2013 -0400

    Fix backcompat detection on Oracle, where NULL != 'string' is false
    
    The 4.1.13 backcomapt file is meant to run for all earlier upgrade steps
    where the code assumes that limits on groups can be done on Name.
    Before it runs, it checks if there are SystemInternal rows where the
    Name is different from the Type, to ensure it does not run more than is
    necessary.
    
    Unfortunately, this does not work on Oracle, where Name is NULL on
    SystemInternal groups -- and Oracle's treatment of NULL means that the
    rows thus do not match, and thus the back-compat step does not run.
    Because of this, the upgrade process runs into trouble, for instance in
    the 4.1.4 upgrade step:
    
        [error]: Can't load role group AdminCc: Couldn't find row
        [error]: Can't load role group Cc: Couldn't find row
        [error]: Can't load role group Owner: Couldn't find row
        [error]: Can't load role group Requestor: Couldn't find row
    
    Resolve this by alternately checking if the Name of the SystemInternal
    groups IS NULL; this is also still a correct alternate condition to
    check on other, non-Oracle, databases.

diff --git a/etc/upgrade/4.1.13/backcompat b/etc/upgrade/4.1.13/backcompat
index b4e69a3..0dc53d2 100644
--- a/etc/upgrade/4.1.13/backcompat
+++ b/etc/upgrade/4.1.13/backcompat
@@ -5,6 +5,9 @@ $groups->Limit(
     FIELD => 'Name', OPERATOR => '!=', VALUE => 'main.Type', QUOTEVALUE => 0
 );
 $groups->Limit(
+    FIELD => 'Name', OPERATOR => 'IS', VALUE => 'NULL',
+);
+$groups->Limit(
     FIELD => 'Domain',
     VALUE => 'SystemInternal',
     CASESENSITIVE => 0,

commit 69569a07d88afb3e60f0c62689eb95cdb8c298d8
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Nov 7 15:44:29 2013 -0500

    Indexes, like schema, needs to set the CURRENT_SCHEMA on oracle
    
    Otherwise, attempts to create indexes result in "table or view does not
    exist" because the tables are not in the current schema.  Additionally,
    the created indexes would be in the wrong schema.

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 26fa427..b03e490 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -552,6 +552,15 @@ sub InsertIndexes {
         $path = $base_path;
     }
 
+    if ( $db_type eq 'Oracle' ) {
+        my $db_user = RT->Config->Get('DatabaseUser');
+        my $status = $dbh->do( "ALTER SESSION SET CURRENT_SCHEMA=$db_user" );
+        unless ( $status ) {
+            return $status, "Couldn't set current schema to $db_user."
+                ."\nError: ". $dbh->errstr;
+        }
+    }
+
     local $@;
     eval { require $path; 1 }
         or return (0, "Couldn't execute '$path': " . $@);

commit 41ce7877183f8712583befeca2380a22c96ffafb
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Nov 7 15:58:41 2013 -0500

    Switch to _arrayref so that case of returned columns is irrelevant
    
    Despite being asked for the 'uniqueness' colun, Oracle may return
    'UNIQUENESS' in the hashref.  Use array references instead, to step
    around this inconsistency -- as is already done for all other database
    types.

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index b03e490..ccb72b8 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -1429,14 +1429,14 @@ sub IndexInfo {
         $res{'Unique'} = (grep lc $_->[1] eq lc $args{'Name'}, @$list)[0][2]? 1 : 0;
     }
     elsif ( $db_type eq 'Oracle' ) {
-        my $index = $dbh->selectrow_hashref(
+        my $index = $dbh->selectrow_arrayref(
             'select uniqueness, funcidx_status from dba_indexes
             where lower(table_name) = ? AND lower(index_name) = ? AND LOWER(Owner) = ?',
             undef, lc $args{'Table'}, lc $args{'Name'}, lc RT->Config->Get('DatabaseUser'),
         );
-        return () unless $index && keys %$index;
-        $res{'Unique'} = $index->{'uniqueness'} eq 'UNIQUE'? 1 : 0;
-        $res{'Functional'} = $index->{'funcidx_status'}? 1 : 0;
+        return () unless $index && @$index;
+        $res{'Unique'} = $index->[0] eq 'UNIQUE'? 1 : 0;
+        $res{'Functional'} = $index->[1] ? 1 : 0;
 
         my %columns = map @$_, @{ $dbh->selectall_arrayref(
             'select column_position, column_name from dba_ind_columns

commit d89e39477f38df8b8955eb3ce3d7cd9f8a7552de
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Nov 7 16:52:02 2013 -0500

    Dropping an Oracle index may instead require dropping a constraint
    
    A couple columns in RT contain contraints, not just unique indexes.
    Attempting to drop such indexes results in the error "cannot drop index
    used for enforcement of unique/primary key".
    
    Look for the constraints in the DBA_CONSTRAINTS table, and make use of
    ALTER TABLE ... DROP CONSTRAINT to remove them, rather than DROP INDEX.

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index ccb72b8..4b3e5dc 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -1486,7 +1486,17 @@ sub DropIndex {
     }
     elsif ( $db_type eq 'Oracle' ) {
         my $user = RT->Config->Get('DatabaseUser');
-        $res = $dbh->do("drop index $user.$args{'Name'}");
+        # Check if it has constraints associated with it
+        my ($constraint) = $dbh->selectrow_arrayref(
+            'SELECT constraint_name, table_name FROM dba_constraints WHERE LOWER(owner) = ? AND LOWER(index_name) = ?',
+            undef, lc $user, lc $args{'Name'}
+        );
+        if ($constraint) {
+            my ($constraint_name, $table) = @{$constraint};
+            $res = $dbh->do("ALTER TABLE $user.$table DROP CONSTRAINT $constraint_name");
+        } else {
+            $res = $dbh->do("DROP INDEX $user.$args{'Name'}");
+        }
     }
     else {
         die "Not implemented";

commit 5d1f922ceeda30d6a37ad01aa1c311d3e82703e6
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Nov 7 16:55:22 2013 -0500

    There may be more than one index that begins the way we are looking for
    
    Specifically, on Oracle, 4.0 contains both Queues_Name_Unique and
    Queues1, as well as Users_Name_Unique and Users2.

diff --git a/etc/upgrade/4.1.23/indexes b/etc/upgrade/4.1.23/indexes
index d76264f..498dd3c 100644
--- a/etc/upgrade/4.1.23/indexes
+++ b/etc/upgrade/4.1.23/indexes
@@ -94,13 +94,11 @@ my $dedup = sub {
     );
     foreach my $e (@list) {
         RT->Logger->debug("Checking index on ". $e->{'Column'} ." in ". $e->{'Table'} );
-        my ($index) = $RT::Handle->IndexesThatBeginWith(
+        my (@indexes) = $RT::Handle->IndexesThatBeginWith(
             Table => $e->{'Table'}, Columns => [$e->{'Column'}]
         );
-        $index = undef if $index && @{$index->{'Columns'}}>1;
-        if (
-            $index && $index->{'Unique'}
-            && ($RT::Handle->CaseSensitive? $index->{'CaseInsensitive'}{ lc $e->{'Column'} } : 1 )
+        @indexes = grep {@{$_->{'Columns'}} == 1} @indexes;
+        if (grep {$_->{Unique} && ($RT::Handle->CaseSensitive? $_->{'CaseInsensitive'}{ lc $e->{'Column'} } : 1 ) } @indexes
         ) {
             RT->Logger->debug("Required index exists. Skipping.");
             next;
@@ -108,7 +106,7 @@ my $dedup = sub {
 
         $dedup->( $e->{'Table'}, $e->{'Column'} );
 
-        if ( $index ) {
+        for my $index ( @indexes ) {
             my ($status, $msg) = $RT::Handle->DropIndex(
                 Table => $e->{'Table'}, Name => $index->{'Name'},
             );

commit 5ea0b17df6f407eb54f53b81f797860c3e988b5f
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Nov 7 17:00:02 2013 -0500

    Adjust log levels for consistency with 5d75726

diff --git a/etc/upgrade/4.1.23/indexes b/etc/upgrade/4.1.23/indexes
index 498dd3c..78db4ae 100644
--- a/etc/upgrade/4.1.23/indexes
+++ b/etc/upgrade/4.1.23/indexes
@@ -160,7 +160,8 @@ foreach my $table ('Users', 'Tickets') {
         my ($status, $msg) = $RT::Handle->DropIndex(
             Table => $table, Name => $index->{'Name'},
         );
-        RT->Logger->info($msg);
+        my $method = $status ? 'debug' : 'warning';
+        RT->Logger->$method($msg);
     }
 }
 

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


More information about the Rt-commit mailing list