[Rt-commit] r7169 - in rt/branches/3.7-EXPERIMENTAL-TUNIS: lib/RT
clkao at bestpractical.com
clkao at bestpractical.com
Mon Mar 5 18:50:29 EST 2007
Author: clkao
Date: Mon Mar 5 18:50:29 2007
New Revision: 7169
Modified:
rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Handle.pm
rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Test.pm
rt/branches/3.7-EXPERIMENTAL-TUNIS/sbin/rt-setup-database.in
Log:
various things to allow pg init to work.
Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Handle.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Handle.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Handle.pm Mon Mar 5 18:50:29 2007
@@ -695,6 +695,47 @@
+=head2 get_system_dsn
+
+Returns a DSN suitable for database creates and drops
+and user creates and drops.
+
+=cut
+
+sub get_system_dsn {
+ my $db_name = RT->Config->Get('DatabaseName');
+ my $db_type = RT->Config->Get('DatabaseType');
+ my $dsn = get_rt_dsn();
+
+ if ( $db_type eq 'mysql' ) {
+ # with mysql, you want to connect sans database to funge things
+ $dsn =~ s/dbname=\Q$db_name//;
+ }
+ elsif ( $db_type eq 'Pg' ) {
+ # with postgres, you want to connect to template1 database
+ $dsn =~ s/dbname=\Q$db_name/dbname=template1/;
+ }
+ elsif ( $db_type eq 'Informix' ) {
+ # with Informix, you want to connect sans database:
+ $dsn =~ s/Informix:\Q$db_name/Informix:/;
+ }
+ return $dsn;
+}
+
+=head2 get_rt_dsn
+
+Returns DSN according to RT config.
+
+=cut
+
+sub get_rt_dsn {
+ my $rt_handle = RT::Handle->new;
+ $rt_handle->BuildDSN;
+ return $rt_handle->DSN;
+}
+
+
+
eval "require RT::Handle_Vendor";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/Handle_Vendor.pm});
eval "require RT::Handle_Local";
Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Test.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Test.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Test.pm Mon Mar 5 18:50:29 2007
@@ -1,4 +1,5 @@
package RT::Test;
+use strict;
use Test::More;
@@ -35,11 +36,20 @@
sub import {
my $class = shift;
require RT::Handle;
- RT::Handle->drop_db( undef, { force => 1 } );
- RT::Handle->create_db;
+ # bootstrap with dba cred
+ my $dbh = _get_dbh(RT::Handle->get_system_dsn,
+ $ENV{DB_DBA}, $ENV{DB_DBA_PASS});
+ my $db_type = RT->Config->Get('DatabaseType');
+
+ RT::Handle->drop_db( $dbh, { force => 1 } );
+ RT::Handle->create_db( $dbh );
+
+ my $dbh = _get_dbh(RT::Handle->get_rt_dsn,
+ $ENV{DB_DBA}, $ENV{DB_DBA_PASS});
RT->ConnectToDatabase;
$RT::Handle->insert_schema($dbh);
+ $RT::Handle->insert_acl($dbh) unless $db_type eq 'Oracle';
$RT::Handle->insert_initial_data();
unless ( ($_[0] || '') eq 'nodata' ) {
@@ -54,5 +64,18 @@
return ($s->started_ok, Test::WWW::Mechanize->new);
}
+sub _get_dbh {
+ my ($dsn, $user, $pass) = @_;
+ my $dbh = DBI->connect(
+ $dsn, $user, $pass,
+ { RaiseError => 0, PrintError => 0 },
+ );
+ unless ( $dbh ) {
+ my $msg = "Failed to connect to $dsn as user '$user': ". $DBI::errstr;
+ print STDERR $msg; exit -1;
+ }
+ return $dbh;
+}
+
1;
Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/sbin/rt-setup-database.in
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/sbin/rt-setup-database.in (original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/sbin/rt-setup-database.in Mon Mar 5 18:50:29 2007
@@ -213,32 +213,6 @@
return ($password);
}
-=head2 get_system_dsn
-
-Returns a DSN suitable for database creates and drops
-and user creates and drops.
-
-=cut
-
-sub get_system_dsn {
-
- my $dsn = get_rt_dsn();
-
- if ( $db_type eq 'mysql' ) {
- # with mysql, you want to connect sans database to funge things
- $dsn =~ s/dbname=\Q$db_name//;
- }
- elsif ( $db_type eq 'Pg' ) {
- # with postgres, you want to connect to template1 database
- $dsn =~ s/dbname=\Q$db_name/dbname=template1/;
- }
- elsif ( $db_type eq 'Informix' ) {
- # with Informix, you want to connect sans database:
- $dsn =~ s/Informix:\Q$db_name/Informix:/;
- }
- return $dsn;
-}
-
=head2 get_system_dbh
Returns L<DBI> database handle connected to B<system> with DBA credentials.
@@ -248,19 +222,7 @@
=cut
sub get_system_dbh {
- return _get_dbh( get_system_dsn(), $args{'dba'}, $args{'dba-password'} );
-}
-
-=head2 get_rt_dsn
-
-Returns DSN according to RT config.
-
-=cut
-
-sub get_rt_dsn {
- my $rt_handle = RT::Handle->new;
- $rt_handle->BuildDSN;
- return $rt_handle->DSN;
+ return _get_dbh( RT::Handle->get_system_dsn(), $args{'dba'}, $args{'dba-password'} );
}
=head2 get_rt_dbh [USER, PASSWORD]
@@ -276,7 +238,7 @@
unless ( @_ ) {
($user, $pass) = ($db_user, $db_pass);
}
- return _get_dbh( get_rt_dsn, $user, $pass );
+ return _get_dbh( RT::Handle->get_rt_dsn, $user, $pass );
}
sub _get_dbh {
More information about the Rt-commit
mailing list