On Tue Mar 30 16:24:49 2010, ECARROLL wrote:
Show quoted text> I think my patch offers a better method of adding this functionality
>
>
http://github.com/EvanCarroll/Fey-
> Loader/compare/0b9f9125ecb4a0f8ed63864d9d039a2f73da85a1...HEAD
>
> Prime difference being it adds the functionality to the DBI base class
> and leaves the default schema intact, it also includes doc patches. It
> also works (adds the schema to the table objects). And, applies
> cleanly
> to 0.11
Ah - they mentioned someone else asking about Pg support on IRC.
Your patch certainly looks more thorough than mine. The tests in my
patch specifically check populating and checking against an actual Pg
schema - might be useful.
Patches should apply to 0.11 with -p0 if I've done this right...
diff -r -c Fey-Test-0.07/lib/Fey/Test/Pg.pm ../Fey-Test-0.07/lib/Fey/Test/Pg.pm
*** Fey-Test-0.07/lib/Fey/Test/Pg.pm 2009-11-17 19:27:31.000000000 +0000
--- ../Fey-Test-0.07/lib/Fey/Test/Pg.pm 2010-03-31 11:07:16.000000000 +0100
***************
*** 26,31 ****
--- 26,34 ----
use File::Temp ();
+ our @Schema_Names_To_Test = ('public', 'TestSchema');
+
+
{
my $DBH;
sub dbh
***************
*** 47,67 ****
# Shuts up "NOTICE" warnings from Pg.
local $dbh->{PrintWarn} = 0;
! $class->_run_ddl($dbh);
return $DBH = $dbh;
}
}
! sub _run_ddl
{
my $class = shift;
my $dbh = shift;
for my $ddl ( $class->_sql() )
{
$dbh->do($ddl);
}
}
sub _sql
--- 50,82 ----
# Shuts up "NOTICE" warnings from Pg.
local $dbh->{PrintWarn} = 0;
! for my $s (@Schema_Names_To_Test) {
! $class->_run_ddl_in_schema($s, $dbh);
! }
return $DBH = $dbh;
}
}
! sub _run_ddl_in_schema
{
my $class = shift;
+ my $schema= shift;
my $dbh = shift;
+ # Build our tables in the correct schema
+ if ($schema ne 'public') {
+ $dbh->do(qq(CREATE SCHEMA "$schema"));
+ }
+ $dbh->do(qq(SET search_path = "$schema"));
+
for my $ddl ( $class->_sql() )
{
$dbh->do($ddl);
}
+
+ # Tidy up behind ourselves
+ $dbh->do('RESET search_path');
}
sub _sql
diff -r -c Fey-Loader-0.11/lib/Fey/Loader/Pg.pm ../Fey-Loader-0.11/lib/Fey/Loader/Pg.pm
*** Fey-Loader-0.11/lib/Fey/Loader/Pg.pm 2009-11-17 19:35:52.000000000 +0000
--- ../Fey-Loader-0.11/lib/Fey/Loader/Pg.pm 2010-03-31 10:12:08.000000000 +0100
***************
*** 14,19 ****
--- 14,22 ----
use Scalar::Util qw( looks_like_number );
+ has 'schema_name' => ( is => 'ro', isa => 'Str', reader => '_schema_name', default => 'public' );
+
+
sub _build_dbh_name
{
my $self = shift;
***************
*** 21,28 ****
return $self->dbh()->selectrow_arrayref('SELECT CURRENT_DATABASE()')->[0];
}
- sub _schema_name { 'public' }
-
sub _column_params
{
my $self = shift;
--- 24,29 ----
diff -r -c Fey-Loader-0.11/t/Loader/Pg.t ../Fey-Loader-0.11/t/Loader/Pg.t
*** Fey-Loader-0.11/t/Loader/Pg.t 2009-11-17 19:35:52.000000000 +0000
--- ../Fey-Loader-0.11/t/Loader/Pg.t 2010-03-31 11:06:40.000000000 +0100
***************
*** 5,17 ****
use Fey::Test::Loader;
use Fey::Test::Pg;
! use Test::More tests => 156;
use Fey::Loader;
{
! my $loader = Fey::Loader->new( dbh => Fey::Test::Pg->dbh() );
my $schema1 = $loader->make_schema( name => 'Test' );
my $schema2 = Fey::Test->mock_test_schema_with_fks();
--- 5,47 ----
use Fey::Test::Loader;
use Fey::Test::Pg;
! use Test::More tests => 155 * scalar(@Fey::Test::Pg::Schema_Names_To_Test) + 1 + 1;
use Fey::Loader;
+ use Data::Dumper;
+
+
+ {
+ for my $s (@Fey::Test::Pg::Schema_Names_To_Test) {
+ compare_schemas($s);
+ }
+ }
+
+ {
+ my $loader = Fey::Loader->new(
+ dbh => Fey::Test::Pg->dbh(),
+ schema_name => 'missing_schema'
+ );
+ my $schema = $loader->make_schema( name => 'ShouldBeEmpty' );
+ my $num_tables = $schema->tables;
+ is( $num_tables, 0, "Shouldn't be any tables if schema isn't in database" );
+ }
{
! my $def = Fey::Loader::Pg->_default('NULL');
! isa_ok( $def, 'Fey::Literal::Null');
! }
!
! exit;
!
! sub compare_schemas
! {
! my $schema_name = shift;
!
! my %loader_params = ( dbh => Fey::Test::Pg->dbh() );
! if ($schema_name) { $loader_params{schema_name} = $schema_name; }
! my $loader = Fey::Loader->new( %loader_params );
my $schema1 = $loader->make_schema( name => 'Test' );
my $schema2 = Fey::Test->mock_test_schema_with_fks();
***************
*** 34,41 ****
is( $loader->_build_dbh_name(), 'test_fey',
'database name is test_fey' );
}
-
- {
- my $def = Fey::Loader::Pg->_default('NULL');
- isa_ok( $def, 'Fey::Literal::Null');
- }
--- 64,66 ----