Skip Menu |

This queue is for tickets about the Fey-Loader CPAN distribution.

Report information
The Basics
Id: 41915
Status: open
Priority: 0/
Queue: Fey-Loader

People
Owner: Nobody in particular
Requestors: edl [...] aweber.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.06
Fixed in: (no value)



Subject: Fey::Loader feature request w/patch for Pg Databases
This patch includes the following: * support non-default pg search path * support tables that use OIDs as the PK Patch For: Fey::Loader v0.06 Other Version Information: perl, v5.8.8 built for i486-linux-gnu-thread-multi Fey::ORM v0.15 Fey v0.18 Moose v0.63 DBD::Pg v2.11.7 OS: Ubuntu Linux localhost 2.6.24-19-server #1 SMP Sat Jul 12 00:40:01 UTC 2008 i686 GNU/Linux
Subject: fey_loader_0.06_pg_dbi_patch.patch
diff -ur Pg.pm patched-Pg.pm --- Pg.pm 2008-12-23 13:39:04.000000000 -0500 +++ /patched-Pg.pm 2008-12-23 13:36:34.000000000 -0500 @@ -11,8 +11,13 @@ use Fey::Literal; use Scalar::Util qw( looks_like_number ); - -sub _schema_name { 'public' } +has '_schema_name' => ( + is => 'ro', + isa => 'Str', + required => 1, + default => 'public', + init_arg => 'schema', +); sub _column_params { diff -ur DBI.pm patched-DBI.pm --- DBI.pm 2008-12-23 13:39:04.000000000 -0500 +++ /patched-DBI.pm 2008-12-23 13:37:42.000000000 -0500 @@ -200,13 +200,17 @@ { # KEY_SEQ refers to the "position" of the column in the table, # not in the key, and so may start at any random number. + + # ignore OID as pkey + next if $pk_col->{KEY_SEQ} == -2; $pk{ $pk_col->{KEY_SEQ} } = $self->_unquote_identifier( $pk_col->{COLUMN_NAME} ); } my @pk = @pk{ sort keys %pk }; - $table->add_candidate_key(@pk) + # The defined check is another Pg workaround. + $table->add_candidate_key(grep { defined } @pk) if @pk; } @@ -229,6 +233,8 @@ my %ck; while ( my $ck_col = $key_info->fetchrow_hashref() ) { + # ignore OID as a candidate key + next if $ck_col->{COLUMN_NAME} eq 'oid'; $ck{ $ck_col->{INDEX_NAME} } ||= []; $ck{ $ck_col->{INDEX_NAME} }[ $ck_col->{ORDINAL_POSITION} - 1 ] =
On Tue Dec 23 14:29:32 2008, pianoman19403 wrote: Show quoted text
> This patch includes the following: > * support non-default pg search path > * support tables that use OIDs as the PK > > Patch For: > Fey::Loader v0.06 > > Other Version Information: > perl, v5.8.8 built for i486-linux-gnu-thread-multi > Fey::ORM v0.15 > Fey v0.18 > Moose v0.63 > DBD::Pg v2.11.7 > > OS: > Ubuntu > Linux localhost 2.6.24-19-server #1 SMP Sat Jul 12 00:40:01 UTC 2008 > i686 GNU/Linux
Woah, I just realized this has been sitting here forever. I'd like to include this, but it really needs some tests, I think.
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 -- Evan Carroll System Lord of the Internets http://www.evancarroll.com
From: dev [...] archonet.com
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...
Subject: fey_test.patch
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
Subject: fey_loader.patch
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 ----