X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser%2FDBIx%2FClass.pm;h=835edbbdcb2f094b7694062515990a2f7d9f33f7;hb=084a2c0ae84b2ae56f05deeb67dd007246f7692e;hp=cc8d5b624999a7ffa5a335a6ed978a78a7142982;hpb=4a9f6cdc9c6700115a0469712de8915847d6864c;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index cc8d5b6..835edbb 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -66,7 +66,18 @@ sub parse { } - foreach my $moniker (sort @monikers) + my(@table_monikers, @view_monikers); + for my $moniker (@monikers){ + my $source = $dbicschema->source($moniker); + next if $source->is_virtual; + if ( $source->isa('DBIx::Class::ResultSource::Table') ) { + push(@table_monikers, $moniker); + } elsif( $source->isa('DBIx::Class::ResultSource::View') ){ + push(@view_monikers, $moniker); + } + } + + foreach my $moniker (sort @table_monikers) { my $source = $dbicschema->source($moniker); @@ -218,6 +229,25 @@ sub parse { $source->_invoke_sqlt_deploy_hook($table); } + foreach my $moniker (sort @view_monikers) + { + my $source = $dbicschema->source($moniker); + # Skip custom query sources + next if ref($source->name); + + # Its possible to have multiple DBIC source using same table + next if $seen_tables{$source->name}++; + + my $view = $schema->add_view( + name => $source->name, + fields => [ $source->columns ], + $source->view_definition ? ( 'sql' => $source->view_definition ) : () + ); + if ($source->result_class->can('sqlt_deploy_hook')) { + $source->result_class->sqlt_deploy_hook($view); + } + } + if ($dbicschema->can('sqlt_deploy_hook')) { $dbicschema->sqlt_deploy_hook($schema); } @@ -234,6 +264,14 @@ from a DBIx::Class::Schema instance =head1 SYNOPSIS + ## Via DBIx::Class + use MyApp::Schema; + my $schema = MyApp::Schema->connect("dbi:SQLite:something.db"); + $schema->create_ddl_dir(); + ## or + $schema->deploy(); + + ## Standalone use MyApp::Schema; use SQL::Translator; @@ -247,12 +285,24 @@ from a DBIx::Class::Schema instance =head1 DESCRIPTION +This class requires L installed to work. + C reads a DBIx::Class schema, interrogates the columns, and stuffs it all in an $sqlt_schema object. +It's primary use is in deploying database layouts described as a set +of L classes, to a database. To do this, see the +L method. + +This can also be achieved by having DBIx::Class export the schema as a +set of SQL files ready for import into your database, or passed to +other machines that need to have your application installed but don't +have SQL::Translator installed. To do this see the +L method. + =head1 SEE ALSO -SQL::Translator. +L, L =head1 AUTHORS