[Rt-commit] r15384 - in rt/3.8/branches/parallel-testing: lib/RT

ruz at bestpractical.com ruz at bestpractical.com
Fri Aug 22 18:49:43 EDT 2008


Author: ruz
Date: Fri Aug 22 18:49:43 2008
New Revision: 15384

Modified:
   rt/3.8/branches/parallel-testing/etc/acl.Oracle
   rt/3.8/branches/parallel-testing/lib/RT/Handle.pm

Log:
* in oracle each user has a schema with various objects (tables and other).
  if you drop a user, all objects are dropped as well.
  So it will be our DropDatabase.
* Now we don't skip create step, but instead create a user
  then we set default schema to the user's. All objects are created
  in schema of rt_user. rt_user automatically gets all
  INSERT/SELECT/UPDATE/DELETE.

Modified: rt/3.8/branches/parallel-testing/etc/acl.Oracle
==============================================================================
--- rt/3.8/branches/parallel-testing/etc/acl.Oracle	(original)
+++ rt/3.8/branches/parallel-testing/etc/acl.Oracle	Fri Aug 22 18:49:43 2008
@@ -1,15 +1,4 @@
 
-sub acl {
-    my $db_user = RT->Config->Get('DatabaseUser');
-    my $db_pass = RT->Config->Get('DatabasePassword');
-
-    return (
-        "CREATE USER $db_user IDENTIFIED BY $db_pass"
-            . " default tablespace USERS"
-            . " temporary tablespace TEMP"
-            . " quota unlimited on USERS",
-        "grant connect, resource to $db_user",
-    );
-}
+sub acl { return () }
 
 1;

Modified: rt/3.8/branches/parallel-testing/lib/RT/Handle.pm
==============================================================================
--- rt/3.8/branches/parallel-testing/lib/RT/Handle.pm	(original)
+++ rt/3.8/branches/parallel-testing/lib/RT/Handle.pm	Fri Aug 22 18:49:43 2008
@@ -314,7 +314,24 @@
         return (1, 'Skipped as SQLite doesn\'t need any action');
     }
     elsif ( $db_type eq 'Oracle' ) {
-        return (1, 'Skipped as we\'re working with Oracle');
+        my $db_user = RT->Config->Get('DatabaseUser');
+        my $db_pass = RT->Config->Get('DatabasePassword');
+        $status = $dbh->do(
+            "CREATE USER $db_user IDENTIFIED BY $db_pass"
+            ." default tablespace USERS"
+            ." temporary tablespace TEMP"
+            ." quota unlimited on USERS"
+        );
+        unless ( $status ) {
+            return $status, "Couldn't create user $db_user identified by $db_pass."
+                ."\nError: ". $dbh->errstr;
+        }
+        $status = $dbh->do( "GRANT connect, resource TO $db_user" );
+        unless ( $status ) {
+            return $status, "Couldn't grant connect and resource to $db_user."
+                ."\nError: ". $dbh->errstr;
+        }
+        return (1, "Created user $db_user. All RT's objects should be in his schema.");
     }
     elsif ( $db_type eq 'Pg' ) {
         # XXX: as we get external DBH we don't know if RaiseError or PrintError
@@ -352,7 +369,13 @@
     my $db_name = RT->Config->Get('DatabaseName');
 
     if ( $db_type eq 'Oracle' || $db_type eq 'Informix' ) {
-        return (0, "Use etc/drop.$db_type to drop database");
+        my $db_user = RT->Config->Get('DatabaseUser');
+        my $status = $dbh->do( "DROP USER $db_user CASCADE" );
+        unless ( $status ) {
+            return 0, "Couldn't drop user $db_user."
+                ."\nError: ". $dbh->errstr;
+        }
+        return (1, "Successfully dropped user '$db_user' with his schema.");
     }
     elsif ( $db_type eq 'SQLite' ) {
         my $path = $db_name;
@@ -457,6 +480,15 @@
     }
     close $fh_schema; close $fh_schema_local;
 
+    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 $SIG{__WARN__} = sub {};
     my $is_local = 0;
     $dbh->begin_work or return (0, "Couldn't begin transaction: ". $dbh->errstr);


More information about the Rt-commit mailing list