From: Ash Berlin Date: Thu, 5 Feb 2009 23:04:13 +0000 (+0000) Subject: - Allow passing schema object to ->populate X-Git-Tag: v1.001002~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9e77162b41e85ec563738b5cd062fd75edc4f370;p=dbsrgits%2FDBIx-Class-Fixtures.git - Allow passing schema object to ->populate - Check that fixture population dir was created --- diff --git a/Changes b/Changes index e90666c..4479b0f 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for DBIx-Class-Fixtures +1.001002 +- Allow passing schema object to ->populate +- Check that fixture population dir was created + 1.001001 - debug defaults to 0 rather than undef - cleanup only deletes what's necessary diff --git a/lib/DBIx/Class/Fixtures.pm b/lib/DBIx/Class/Fixtures.pm index f4434a1..01c1e25 100644 --- a/lib/DBIx/Class/Fixtures.pm +++ b/lib/DBIx/Class/Fixtures.pm @@ -768,20 +768,32 @@ sub _read_sql { no_populate => 0, # optional, set to 1 to run ddl but not populate }); -In this case the database app_dev will be cleared of all tables, then the specified DDL deployed to it, -then finally all fixtures found in /home/me/app/fixtures will be added to it. populate will generate -its own DBIx::Class schema from the DDL rather than being passed one to use. This is better as -custom insert methods are avoided which can to get in the way. In some cases you might not -have a DDL, and so this method will eventually allow a $schema object to be passed instead. +In this case the database app_dev will be cleared of all tables, then the +specified DDL deployed to it, then finally all fixtures found in +/home/me/app/fixtures will be added to it. populate will generate its own +DBIx::Class schema from the DDL rather than being passed one to use. This is +better as custom insert methods are avoided which can to get in the way. In +some cases you might not have a DDL, and so this method will eventually allow a +$schema object to be passed instead. -If needed, you can specify a post_ddl attribute which is a DDL to be applied after all the fixtures -have been added to the database. A good use of this option would be to add foreign key constraints -since databases like Postgresql cannot disable foreign key checks. +If needed, you can specify a post_ddl attribute which is a DDL to be applied +after all the fixtures have been added to the database. A good use of this +option would be to add foreign key constraints since databases like Postgresql +cannot disable foreign key checks. -If your tables have foreign key constraints you may want to use the cascade attribute which will -make the drop table functionality cascade, ie 'DROP TABLE $table CASCADE'. +If your tables have foreign key constraints you may want to use the cascade +attribute which will make the drop table functionality cascade, ie 'DROP TABLE +$table CASCADE'. -directory, dll and connection_details are all required attributes. +C is a required attribute. + +If you wish for DBIx::Class::Fixtures to clear the database for you pass in +C (path to a DDL sql file) and C (array ref of DSN, +user and pass). + +If you wish to deal with cleaning the schema yourself, then pass in a C +attribute containing the connected schema you wish to operate on and set the +C attribute. =cut @@ -803,7 +815,8 @@ sub populate { } my $ddl_file; - my $dbh; + my $dbh; + my $schema; if ($params->{ddl} && $params->{connection_details}) { $ddl_file = file(delete $params->{ddl}); unless (-e $ddl_file) { @@ -812,13 +825,13 @@ sub populate { unless (ref $params->{connection_details} eq 'ARRAY') { return DBIx::Class::Exception->throw('connection details must be an arrayref'); } - } elsif ($params->{schema}) { - return DBIx::Class::Exception->throw('passing a schema is not supported at the moment'); + $schema = $self->_generate_schema({ ddl => $ddl_file, connection_details => delete $params->{connection_details}, %{$params} }); + } elsif ($params->{schema} && $params->{no_deploy}) { + $schema = $params->{schema}; } else { return DBIx::Class::Exception->throw('you must set the ddl and connection_details params'); } - my $schema = $self->_generate_schema({ ddl => $ddl_file, connection_details => delete $params->{connection_details}, %{$params} }); return 1 if $params->{no_populate}; @@ -835,7 +848,14 @@ sub populate { $tmp_fixture_dir->rmtree; } $self->msg("- creating temp dir"); - dircopy(dir($fixture_dir, $schema->source($_)->from), dir($tmp_fixture_dir, $schema->source($_)->from)) for grep { -e dir($fixture_dir, $schema->source($_)->from) } $schema->sources; + dircopy( + dir($fixture_dir, $schema->source($_)->from), + dir($tmp_fixture_dir, $schema->source($_)->from) + ) for grep { -e dir($fixture_dir, $schema->source($_)->from) } $schema->sources; + + unless (-d $tmp_fixture_dir) { + return DBIx::Class::Exception->throw("Unable to create temporary fixtures dir: $tmp_fixture_dir: $!"); + } my $fixup_visitor; my $formatter= $schema->storage->datetime_parser;