Merge 'trunk' into 'view-deps'
Peter Rabbitson [Wed, 2 Jun 2010 13:34:40 +0000 (13:34 +0000)]
r9483@Thesaurus (orig r9469):  rabbit | 2010-05-31 13:21:04 +0200
Skip tests segfaulting with ancient DBD::Sybase versions
r9488@Thesaurus (orig r9474):  frew | 2010-05-31 17:11:51 +0200
use namespace::clean w/ Try::Tiny
r9489@Thesaurus (orig r9475):  rabbit | 2010-05-31 17:13:29 +0200
Fix Top-limit problem of missed bindvars
r9490@Thesaurus (orig r9476):  rabbit | 2010-05-31 17:21:20 +0200
Skip failing tests on old DBD
r9491@Thesaurus (orig r9477):  frew | 2010-05-31 17:23:49 +0200
add namespace::clean as regular dep
r9501@Thesaurus (orig r9487):  rabbit | 2010-05-31 19:45:27 +0200
Fix RT57467, simplify test
r9503@Thesaurus (orig r9489):  rabbit | 2010-05-31 23:52:17 +0200
Fix Schema::Versioned borkage
r9506@Thesaurus (orig r9492):  rabbit | 2010-06-01 00:08:45 +0200
 r9306@Thesaurus (orig r9293):  edenc | 2010-05-03 21:20:21 +0200
 braching for bug fixes (rt 54939)
 r9339@Thesaurus (orig r9326):  edenc | 2010-05-07 18:15:47 +0200
 added failing test case for non-versioned schema deploy attempt
 r9340@Thesaurus (orig r9327):  edenc | 2010-05-07 18:16:03 +0200
 dbicadmin can now install non-versioned schemas
 r9342@Thesaurus (orig r9329):  rabbit | 2010-05-07 18:28:27 +0200
 Trap erroneous warnings
 r9345@Thesaurus (orig r9332):  edenc | 2010-05-08 00:02:00 +0200
 test for the dbicadmin -I option
 r9346@Thesaurus (orig r9333):  edenc | 2010-05-08 00:02:25 +0200
 fixes to dbicadmin -I test
 r9347@Thesaurus (orig r9334):  edenc | 2010-05-08 00:02:41 +0200
 -I option functional and passing tests
 r9348@Thesaurus (orig r9335):  edenc | 2010-05-08 01:39:52 +0200
 moved mock schema out of t/var
 r9375@Thesaurus (orig r9361):  edenc | 2010-05-14 04:02:41 +0200
 added debug option
 r9376@Thesaurus (orig r9362):  edenc | 2010-05-14 04:03:00 +0200
 debug and include_dirs integration between dbicadmin and DBIx::Class::Admin
 r9377@Thesaurus (orig r9363):  edenc | 2010-05-14 04:03:21 +0200
 testing dbicadmin/DBIx::Class::Admin integration
 r9494@Thesaurus (orig r9480):  rabbit | 2010-05-31 18:03:08 +0200
 Simplify includedir testing
 r9496@Thesaurus (orig r9482):  rabbit | 2010-05-31 18:47:35 +0200
 Some comments
 r9497@Thesaurus (orig r9483):  rabbit | 2010-05-31 18:50:50 +0200
 Properly ignore contents of var
 r9498@Thesaurus (orig r9484):  rabbit | 2010-05-31 18:59:49 +0200
 Remove leftovers
 r9499@Thesaurus (orig r9485):  rabbit | 2010-05-31 19:24:55 +0200
 Cleanup debug output
 r9500@Thesaurus (orig r9486):  rabbit | 2010-05-31 19:35:31 +0200
 Fix RT#57732
 r9502@Thesaurus (orig r9488):  rabbit | 2010-05-31 19:48:41 +0200
 typos
 r9505@Thesaurus (orig r9491):  rabbit | 2010-06-01 00:08:29 +0200
 Changes

r9514@Thesaurus (orig r9500):  rabbit | 2010-06-01 00:25:35 +0200
 r9365@Thesaurus (orig r9351):  ribasushi | 2010-05-12 10:09:54 +0200
 New branch to cleanup resultset-wide update/delete
 r9419@Thesaurus (orig r9405):  wreis | 2010-05-19 02:49:47 +0200
 failing tests for RS->update
 r9511@Thesaurus (orig r9497):  rabbit | 2010-06-01 00:20:39 +0200
 Fix update/delete on prefetching resultsets
 r9512@Thesaurus (orig r9498):  rabbit | 2010-06-01 00:24:54 +0200
 Test cleanup
 r9513@Thesaurus (orig r9499):  rabbit | 2010-06-01 00:25:14 +0200
 test replication test fail

r9520@Thesaurus (orig r9506):  frew | 2010-06-01 03:35:36 +0200
do not lazily set up include dirs and do not localize
r9523@Thesaurus (orig r9509):  rabbit | 2010-06-01 13:36:42 +0200
Versioned compat code connects too early
r9524@Thesaurus (orig r9510):  rabbit | 2010-06-01 15:04:49 +0200
Move order outside of the GenSubQ subquery, to appease retarded Sybase
r9525@Thesaurus (orig r9511):  caelum | 2010-06-01 15:08:08 +0200
fix uninitialized warning
r9527@Thesaurus (orig r9513):  rabbit | 2010-06-01 15:46:41 +0200
Try::Tiny is a part of the clan
r9529@Thesaurus (orig r9515):  rabbit | 2010-06-01 16:02:42 +0200
 r7935@Thesaurus (orig r7923):  ribasushi | 2009-11-19 11:05:04 +0100
 Branches for RTs
 r7936@Thesaurus (orig r7924):  ribasushi | 2009-11-19 11:10:18 +0100
 Patch by kalex
 r8152@Thesaurus (orig r8140):  rbo | 2009-12-18 12:51:16 +0100
 Add PRIOR as special and unary op to SQLAHacks::Oracle and use _recurse_where to create the connect_by sql statment

 r8968@Thesaurus (orig r8955):  rabbit | 2010-03-10 10:24:50 +0100
 Merge fallout
 r9004@Thesaurus (orig r8991):  rbo | 2010-03-12 09:00:54 +0100
 Use SQL::Abstract 1.61_01, add some tests.

 r9016@Thesaurus (orig r9003):  rbo | 2010-03-15 12:48:03 +0100
 Fixed 73oracle.t because of new implementation of connect_by

 r9019@Thesaurus (orig r9006):  rbo | 2010-03-15 15:06:10 +0100
 fixed requirements

 r9020@Thesaurus (orig r9007):  ribasushi | 2010-03-15 15:49:26 +0100
 Rewrite hierarchical query tests
 r9021@Thesaurus (orig r9008):  ribasushi | 2010-03-15 16:02:54 +0100
 Whoops
 r9022@Thesaurus (orig r9009):  ribasushi | 2010-03-15 16:03:50 +0100
 Now really fixed
 r9023@Thesaurus (orig r9010):  rbo | 2010-03-15 16:52:24 +0100
 fixed sql mistakes from hierarchical query tests

 r9024@Thesaurus (orig r9011):  rbo | 2010-03-15 18:24:47 +0100
 Update _order_siblings_by, use _order_by_chunks instead of own stuff

 r9025@Thesaurus (orig r9012):  rbo | 2010-03-15 18:25:56 +0100
 fixed hierarchical query tests, not all pass yet

 r9078@Thesaurus (orig r9065):  rbo | 2010-03-27 10:50:33 +0100
 Fixed typo

 r9079@Thesaurus (orig r9066):  rbo | 2010-03-27 11:50:38 +0100
 Update POD, because of new connect_by implemenation

 r9080@Thesaurus (orig r9067):  rbo | 2010-03-27 12:03:23 +0100
 Support NOCYCLE parameter.

 r9082@Thesaurus (orig r9069):  rbo | 2010-03-27 19:10:26 +0100
 Test with the correct arrangement of the tree.
 (oracle hierarchical queries)

 r9094@Thesaurus (orig r9081):  rbo | 2010-04-04 12:56:37 +0200
 Add missing nocycle test for hierarchical queries with oracle

 r9095@Thesaurus (orig r9082):  rbo | 2010-04-04 12:57:45 +0200
 Remove todo: 'Check the parameter syntax of connect_by' fixed with new SQLA release

 r9129@Thesaurus (orig r9116):  ribasushi | 2010-04-11 12:53:20 +0200
 Fix rogue tabs
 r9130@Thesaurus (orig r9117):  ribasushi | 2010-04-11 14:52:07 +0200
 Fix top-level PRIOR with missing '='
 Fix weird AND hardcoded in tests
 Test quotes as well
 r9131@Thesaurus (orig r9118):  ribasushi | 2010-04-11 14:54:59 +0200
 Move oracle offline test where it belongs
 r9144@Thesaurus (orig r9131):  rabbit | 2010-04-12 09:06:28 +0200
 Botched merge
 r9145@Thesaurus (orig r9132):  rabbit | 2010-04-12 09:10:39 +0200
 Pesky tabs
 r9162@Thesaurus (orig r9149):  rbo | 2010-04-14 20:19:20 +0200
 Fixed t/73oracle.t remove braces

 r9312@Thesaurus (orig r9299):  rabbit | 2010-05-04 10:13:47 +0200
 _select_args processing no longer necessary
 r9382@Thesaurus (orig r9368):  rbo | 2010-05-14 23:01:42 +0200
 Update TODO

 r9384@Thesaurus (orig r9370):  rbo | 2010-05-14 23:27:13 +0200
 Fixed broken count query, because of new count query implementation.

 r9385@Thesaurus (orig r9371):  rbo | 2010-05-14 23:35:33 +0200
 Rename option nocycle to connect_by_nocycle

 r9386@Thesaurus (orig r9372):  rbo | 2010-05-14 23:43:29 +0200
 Fixed count subquery from disabled test case

 r9387@Thesaurus (orig r9373):  rbo | 2010-05-14 23:55:28 +0200
 Enabled count sub query test, isn't broken anymore

 r9388@Thesaurus (orig r9374):  rbo | 2010-05-15 00:02:41 +0200
 Use connect_by OR connect_by_nocycle

 r9395@Thesaurus (orig r9381):  rabbit | 2010-05-15 17:01:10 +0200
 Use DDC instead of DD
 r9463@Thesaurus (orig r9449):  rbo | 2010-05-27 10:17:35 +0200
 Fixed group_by bind position problem, reported and patch by Alexande Keusch. Patch has been adjusted.

 r9517@Thesaurus (orig r9503):  rabbit | 2010-06-01 01:54:18 +0200
 Switch away from explicit count-attr lists - just delete what we do not need
 r9518@Thesaurus (orig r9504):  rabbit | 2010-06-01 02:26:49 +0200
 Do not pollute sqlmaker while scanning raw sql
 r9519@Thesaurus (orig r9505):  rabbit | 2010-06-01 02:28:06 +0200
 Minor touches/changes
 r9521@Thesaurus (orig r9507):  rbo | 2010-06-01 07:13:55 +0200
 Fixed typo in Changes file. Adding myself to the CONTRIBUTORS list

 r9528@Thesaurus (orig r9514):  rabbit | 2010-06-01 16:02:06 +0200
 Add A.Keusch to conrib list

r9532@Thesaurus (orig r9518):  caelum | 2010-06-01 16:56:48 +0200
pass postgres_version in producer_args when deploying to Pg
r9535@Thesaurus (orig r9521):  caelum | 2010-06-01 17:24:21 +0200
 r24518@hlagh (orig r9512):  rkitover | 2010-06-01 09:16:09 -0400
 branch to use namespace::clean
 r24523@hlagh (orig r9517):  rkitover | 2010-06-01 10:47:03 -0400
 use namespace::cleaned out imports for some common utilities
 r24526@hlagh (orig r9520):  rkitover | 2010-06-01 11:23:36 -0400
 remove useless use of n::c

r9537@Thesaurus (orig r9523):  rabbit | 2010-06-01 17:46:05 +0200
Rewrite test (no functional changes)
r9538@Thesaurus (orig r9524):  caelum | 2010-06-01 17:58:44 +0200
fix hang in SQLAHacks
r9539@Thesaurus (orig r9525):  caelum | 2010-06-01 19:48:24 +0200
pass sqlite and pg version properly on ->deploy for SQLT trunk
r9540@Thesaurus (orig r9526):  rabbit | 2010-06-01 21:57:46 +0200
Preserve @_ aliasing semantics on coderefs within try{} blocks
r9551@Thesaurus (orig r9537):  frew | 2010-06-02 07:05:39 +0200
perl modules shouldnt munge @INC; thats the job of the script
r9552@Thesaurus (orig r9538):  caelum | 2010-06-02 09:03:33 +0200
use SET ROWCOUNT for Sybase ASE limits without an offset
r9553@Thesaurus (orig r9539):  caelum | 2010-06-02 10:44:44 +0200
update Changes
r9554@Thesaurus (orig r9540):  rabbit | 2010-06-02 11:44:25 +0200
lib expects a list, not an arrayref
r9555@Thesaurus (orig r9541):  rabbit | 2010-06-02 11:53:13 +0200
Do not run test without sqlt
r9556@Thesaurus (orig r9542):  rabbit | 2010-06-02 11:55:48 +0200
Do not use 2**32 directly - causes %u differences between 32 and 64bit
r9557@Thesaurus (orig r9543):  rabbit | 2010-06-02 12:43:31 +0200
Really fix uninit warning
r9558@Thesaurus (orig r9544):  rabbit | 2010-06-02 12:44:59 +0200
Relax developer policy, allowing to skip optional dependencies when in a checkout
r9559@Thesaurus (orig r9545):  rabbit | 2010-06-02 12:55:54 +0200
Trash unnecessary attributes
r9560@Thesaurus (orig r9546):  rabbit | 2010-06-02 13:22:21 +0200
Make sure ddl_dir is created even if a dir-object is supplied
r9561@Thesaurus (orig r9547):  rabbit | 2010-06-02 13:41:40 +0200
More changelogging
r9562@Thesaurus (orig r9548):  rabbit | 2010-06-02 14:14:05 +0200
Auto-fill rdbms version for sqlt
r9563@Thesaurus (orig r9549):  rabbit | 2010-06-02 15:11:09 +0200
Codify result_class accessor/attribute behavior
r9564@Thesaurus (orig r9550):  rabbit | 2010-06-02 15:21:59 +0200
clarify choice of value

16 files changed:
lib/DBIx/Class.pm
lib/DBIx/Class/ResultSource/View.pm
lib/SQL/Translator/Parser/DBIx/Class.pm
t/105view_deps.t [new file with mode: 0644]
t/lib/ViewDeps.pm [new file with mode: 0644]
t/lib/ViewDeps/Result/ANameArtists.pm [new file with mode: 0644]
t/lib/ViewDeps/Result/AbNameArtists.pm [new file with mode: 0644]
t/lib/ViewDeps/Result/AbaNameArtists.pm [new file with mode: 0644]
t/lib/ViewDeps/Result/AbaNameArtistsAnd2010CDsWithManyTracks.pm [new file with mode: 0644]
t/lib/ViewDeps/Result/Artist.pm [new file with mode: 0644]
t/lib/ViewDeps/Result/Artwork.pm [new file with mode: 0644]
t/lib/ViewDeps/Result/CD.pm [new file with mode: 0644]
t/lib/ViewDeps/Result/Track.pm [new file with mode: 0644]
t/lib/ViewDeps/Result/TrackNumberFives.pm [new file with mode: 0644]
t/lib/ViewDeps/Result/Year2010CDs.pm [new file with mode: 0644]
t/lib/ViewDeps/Result/Year2010CDsWithManyTracks.pm [new file with mode: 0644]

index 464a43c..c3c364c 100644 (file)
@@ -227,6 +227,8 @@ aherzog: Adam Herzog <adam@herzogdesigns.com>
 
 Alexander Keusch <cpan@keusch.at>
 
+amiri: Amiri Barksdale <amiri@metalabel.com>
+
 amoore: Andrew Moore <amoore@cpan.org>
 
 andyg: Andy Grundman <andy@hybridized.org>
index 3dde9bd..09b9662 100644 (file)
@@ -8,8 +8,7 @@ use DBIx::Class::ResultSet;
 use base qw/DBIx::Class/;
 __PACKAGE__->load_components(qw/ResultSource/);
 __PACKAGE__->mk_group_accessors(
-  'simple' => qw(is_virtual view_definition)
-);
+    'simple' => qw(is_virtual view_definition deploy_depends_on) );
 
 =head1 NAME
 
@@ -130,6 +129,14 @@ database-based view.
 An SQL query for your view. Will not be translated across database
 syntaxes.
 
+=head2 deploy_depends_on 
+
+  __PACKAGE__->result_source_instance->deploy_depends_on(
+      "MyDB::Schema::Result::Year","MyDB::Schema::Result::CD"
+      );
+
+Specify the views (and only the views) that this view depends on.
+Pass this an array reference.
 
 =head1 OVERRIDDEN METHODS
 
@@ -141,9 +148,29 @@ or the SQL as a subselect if this is a virtual view.
 =cut
 
 sub from {
-  my $self = shift;
-  return \"(${\$self->view_definition})" if $self->is_virtual;
-  return $self->name;
+    my $self = shift;
+    return \"(${\$self->view_definition})" if $self->is_virtual;
+    return $self->name;
+}
+
+=head1 OTHER METHODS
+
+=head2 new
+
+The constructor.
+
+=cut
+
+sub new {
+    my ( $self, @args ) = @_;
+    my $new = $self->next::method(@args);
+    $new->{deploy_depends_on}
+        = {
+            map { $_->result_source_instance->name => 1 }
+            @{ $new->{deploy_depends_on}||[] }
+          }
+        unless ref $new->{deploy_depends_on} eq 'HASH';
+    return $new;
 }
 
 1;
@@ -160,6 +187,8 @@ Jess Robinson <castaway@desert-island.me.uk>
 
 Wallace Reis <wreis@cpan.org>
 
+Amiri Barksdale <amiri@metalabel.com>
+
 =head1 LICENSE
 
 You may distribute this code under the same terms as Perl itself.
index ad5998d..3a5d918 100644 (file)
@@ -270,6 +270,7 @@ sub parse {
     my $dependencies = {
       map { $_ => _resolve_deps ($_, \%tables) } (keys %tables)
     };
+
     for my $table (sort
       {
         keys %{$dependencies->{$a} || {} } <=> keys %{ $dependencies->{$b} || {} }
@@ -298,9 +299,20 @@ EOW
     }
 
     my %views;
-    foreach my $moniker (sort keys %view_monikers)
+
+    my @view_sources =
+    sort {
+        keys %{ $a->deploy_depends_on || {} }
+        <=>
+        keys %{ $b->deploy_depends_on || {} }
+        ||
+        $a->source_name cmp $b->source_name
+    }
+    map { $dbicschema->source($_) }
+    keys %view_monikers;
+
+    foreach my $source (@view_sources)
     {
-        my $source = $dbicschema->source($moniker);
         my $view_name = $source->name;
 
         # FIXME - this isn't the right way to do it, but sqlt does not
@@ -442,9 +454,15 @@ Limit the amount of parsed sources by supplying an explicit list of source names
 
 L<SQL::Translator>, L<DBIx::Class::Schema>
 
-=head1 AUTHORS
+=head1 AUTHOR
+
+Jess Robinson
+
+=head2 CONTRIBUTORS
 
-See L<DBIx::Class/CONTRIBUTORS>.
+Matt Trout
+Ash Berlin
+Amiri Barksdale
 
 =head1 LICENSE
 
diff --git a/t/105view_deps.t b/t/105view_deps.t
new file mode 100644 (file)
index 0000000..7905bd5
--- /dev/null
@@ -0,0 +1,98 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use ViewDeps;
+
+BEGIN {
+    use_ok('DBIx::Class::ResultSource::View');
+}
+
+#################### SANITY
+
+my $view = DBIx::Class::ResultSource::View->new( { name => 'Quux' } );
+
+isa_ok( $view, 'DBIx::Class::ResultSource', 'A new view' );
+isa_ok( $view, 'DBIx::Class', 'A new view also' );
+
+can_ok( $view, $_ ) for qw/new from deploy_depends_on/;
+
+#################### DEPS
+
+my @sql_files = glob("t/sql/ViewDeps*.sql");
+for (@sql_files) {
+    ok( unlink($_), "Deleted old SQL $_ OK" );
+}
+
+my $schema = ViewDeps->connect( 'dbi:SQLite::memory:',
+    { quote_char => '"', } );
+ok( $schema, 'Connected to ViewDeps schema OK' );
+
+my $deps_ref = {
+    map {
+        $schema->resultset($_)->result_source->name =>
+            $schema->resultset($_)->result_source->deploy_depends_on
+        }
+        grep {
+        $schema->resultset($_)
+            ->result_source->isa('DBIx::Class::ResultSource::View')
+        } @{ [ $schema->sources ] }
+};
+
+my @sorted_sources =
+    sort {
+        keys %{ $deps_ref->{$a} || {} }
+        <=>
+        keys %{ $deps_ref->{$b} || {} }
+        || $a cmp $b
+    }
+    keys %$deps_ref;
+
+#################### DEPLOY
+
+my $ddl_dir = "t/sql";
+$schema->create_ddl_dir( [ 'PostgreSQL', 'MySQL', 'SQLite' ], 0.1, $ddl_dir );
+
+ok( -e $_, "$_ was created successfully" ) for @sql_files;
+
+$schema->deploy( { add_drop_table => 1 } );
+
+#################### DOES ORDERING WORK?
+
+my $tr = $schema->{sqlt};
+
+my @keys = keys %{$tr->{views}};
+
+my @sqlt_sources = 
+    sort {
+        $tr->{views}->{$a}->{order}
+        cmp
+        $tr->{views}->{$b}->{order}
+    }
+    @keys;
+
+is_deeply(\@sorted_sources,\@sqlt_sources,"SQLT view order triumphantly matches our order.");
+
+#################### AND WHAT ABOUT USING THE SCHEMA?
+
+my $a_name_rs = $schema->resultset('ANameArtists');
+my $ab_name_rs = $schema->resultset('AbNameArtists');
+my $aba_name_rs = $schema->resultset('AbaNameArtists');
+my $aba_name_cds_rs = $schema->resultset('AbaNameArtistsAnd2010CDsWithManyTracks');
+my $track_five_rs = $schema->resultset('TrackNumberFives');
+my $year_2010_rs = $schema->resultset('Year2010CDs');
+my $year_2010_cds_rs = $schema->resultset('Year2010CDsWithManyTracks');
+
+ok($a_name_rs, "ANameArtists resultset is OK");
+ok($ab_name_rs, "AbNameArtists resultset is OK");
+ok($aba_name_rs, "AbaNameArtists resultset is OK");
+ok($aba_name_cds_rs, "AbaNameArtistsAnd2010CDsWithManyTracks resultset is OK");
+ok($track_five_rs, "TrackNumberFives resultset is OK");
+ok($year_2010_rs, "Year2010CDs resultset is OK");
+ok($year_2010_cds_rs, "Year2010CDsWithManyTracks resultset is OK");
+
+done_testing;
diff --git a/t/lib/ViewDeps.pm b/t/lib/ViewDeps.pm
new file mode 100644 (file)
index 0000000..6c3a311
--- /dev/null
@@ -0,0 +1,16 @@
+package    # hide from PAUSE
+    ViewDeps;
+## Used in 105view_deps.t
+
+use strict;
+use warnings;
+use base 'DBIx::Class::Schema';
+
+__PACKAGE__->load_namespaces;
+
+sub sqlt_deploy_hook {
+    my $self = shift;
+    $self->{sqlt} = shift;
+}
+
+1;
diff --git a/t/lib/ViewDeps/Result/ANameArtists.pm b/t/lib/ViewDeps/Result/ANameArtists.pm
new file mode 100644 (file)
index 0000000..e6fbb0f
--- /dev/null
@@ -0,0 +1,25 @@
+package    # hide from PAUSE
+    ViewDeps::Result::ANameArtists;
+
+use strict;
+use warnings;
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
+__PACKAGE__->table('a_name_artists');
+__PACKAGE__->result_source_instance->view_definition(
+    "SELECT id,name FROM artist WHERE name like 'a%'"
+);
+
+__PACKAGE__->add_columns(
+    id   => { data_type => 'integer', is_auto_increment => 1 },
+    name => { data_type => 'text' },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+__PACKAGE__->has_many( 'cds', 'ViewDeps::Result::CD',
+    { "foreign.artist" => "self.id" },
+);
+
+1;
diff --git a/t/lib/ViewDeps/Result/AbNameArtists.pm b/t/lib/ViewDeps/Result/AbNameArtists.pm
new file mode 100644 (file)
index 0000000..3651a5b
--- /dev/null
@@ -0,0 +1,28 @@
+package    # hide from PAUSE
+    ViewDeps::Result::AbNameArtists;
+
+use strict;
+use warnings;
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
+__PACKAGE__->table('ab_name_artists');
+__PACKAGE__->result_source_instance->view_definition(
+    "SELECT id,name FROM a_name_artists WHERE name like 'ab%'"
+);
+__PACKAGE__->result_source_instance->deploy_depends_on(
+    ["ViewDeps::Result::ANameArtists"]
+);
+
+__PACKAGE__->add_columns(
+    id   => { data_type => 'integer', is_auto_increment => 1 },
+    name => { data_type => 'text' },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+__PACKAGE__->has_many( 'cds', 'ViewDeps::Result::CD',
+    { "foreign.artist" => "self.id" },
+);
+
+1;
diff --git a/t/lib/ViewDeps/Result/AbaNameArtists.pm b/t/lib/ViewDeps/Result/AbaNameArtists.pm
new file mode 100644 (file)
index 0000000..fc989f6
--- /dev/null
@@ -0,0 +1,26 @@
+package    # hide from PAUSE
+    ViewDeps::Result::AbaNameArtists;
+
+use strict;
+use warnings;
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
+__PACKAGE__->table('aba_name_artists');
+__PACKAGE__->result_source_instance->view_definition(
+    "SELECT id,name FROM ab_name_artists WHERE name like 'aba%'" );
+__PACKAGE__->result_source_instance->deploy_depends_on(
+    ["ViewDeps::Result::AbNameArtists"] );
+
+__PACKAGE__->add_columns(
+    id   => { data_type => 'integer', is_auto_increment => 1 },
+    name => { data_type => 'text' },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+__PACKAGE__->has_many( 'cds', 'ViewDeps::Result::CD',
+    { "foreign.artist" => "self.id" },
+);
+
+1;
diff --git a/t/lib/ViewDeps/Result/AbaNameArtistsAnd2010CDsWithManyTracks.pm b/t/lib/ViewDeps/Result/AbaNameArtistsAnd2010CDsWithManyTracks.pm
new file mode 100644 (file)
index 0000000..83c651b
--- /dev/null
@@ -0,0 +1,26 @@
+package    # hide from PAUSE
+    ViewDeps::Result::AbaNameArtistsAnd2010CDsWithManyTracks;
+
+use strict;
+use warnings;
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
+__PACKAGE__->table('aba_name_artists_and_2010_cds_with_many_tracks');
+__PACKAGE__->result_source_instance->view_definition(
+    "SELECT aba.id,aba.name,cd.title,cd.year,cd.number_tracks FROM aba_name_artists aba JOIN year_2010_cds_with_many_tracks cd on (aba.id = cd.artist)"
+);
+__PACKAGE__->result_source_instance->deploy_depends_on(
+    ["ViewDeps::Result::AbNameArtists","ViewDeps::Result::Year2010CDsWithManyTracks"] );
+
+__PACKAGE__->add_columns(
+    id            => { data_type => 'integer', is_auto_increment => 1 },
+    name          => { data_type => 'text' },
+    title         => { data_type => 'text' },
+    year          => { data_type => 'integer' },
+    number_tracks => { data_type => 'integer' },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+1;
diff --git a/t/lib/ViewDeps/Result/Artist.pm b/t/lib/ViewDeps/Result/Artist.pm
new file mode 100644 (file)
index 0000000..276288d
--- /dev/null
@@ -0,0 +1,21 @@
+package    # hide from PAUSE
+    ViewDeps::Result::Artist;
+
+use strict;
+use warnings;
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->table('artist');
+
+__PACKAGE__->add_columns(
+    id   => { data_type => 'integer', is_auto_increment => 1 },
+    name => { data_type => 'text' },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+__PACKAGE__->has_many( 'cds', 'ViewDeps::Result::CD',
+    { "foreign.artist" => "self.id" },
+);
+
+1;
diff --git a/t/lib/ViewDeps/Result/Artwork.pm b/t/lib/ViewDeps/Result/Artwork.pm
new file mode 100644 (file)
index 0000000..056bdb8
--- /dev/null
@@ -0,0 +1,22 @@
+package    # hide from PAUSE
+    ViewDeps::Result::Artwork;
+
+use strict;
+use warnings;
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->table('artwork');
+
+__PACKAGE__->add_columns(
+    id            => { data_type => 'integer', is_auto_increment => 1 },
+    cd         => { data_type => 'integer' },
+    file          => { data_type => 'text' },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+__PACKAGE__->belongs_to( 'cd', 'ViewDeps::Result::CD',
+    { "foreign.id" => "self.cd" },
+);
+
+1;
diff --git a/t/lib/ViewDeps/Result/CD.pm b/t/lib/ViewDeps/Result/CD.pm
new file mode 100644 (file)
index 0000000..c69f4b3
--- /dev/null
@@ -0,0 +1,28 @@
+package    # hide from PAUSE
+    ViewDeps::Result::CD;
+
+use strict;
+use warnings;
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->table('cd');
+
+__PACKAGE__->add_columns(
+    id            => { data_type => 'integer', is_auto_increment => 1 },
+    title         => { data_type => 'text' },
+    artist        => { data_type => 'integer', is_nullable       => 0 },
+    year          => { data_type => 'integer' },
+    number_tracks => { data_type => 'integer' },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+__PACKAGE__->belongs_to( 'artist', 'ViewDeps::Result::Artist',
+    { "foreign.id" => "self.artist" },
+);
+
+__PACKAGE__->has_many( 'tracks', 'ViewDeps::Result::Track',
+    { "foreign.cd" => "self.id" },
+);
+
+1;
diff --git a/t/lib/ViewDeps/Result/Track.pm b/t/lib/ViewDeps/Result/Track.pm
new file mode 100644 (file)
index 0000000..62b1b99
--- /dev/null
@@ -0,0 +1,23 @@
+package    # hide from PAUSE
+    ViewDeps::Result::Track;
+
+use strict;
+use warnings;
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->table('track');
+
+__PACKAGE__->add_columns(
+    id           => { data_type => 'integer', is_auto_increment => 1 },
+    title        => { data_type => 'text' },
+    cd           => { data_type => 'integer' },
+    track_number => { data_type => 'integer' },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+__PACKAGE__->belongs_to( 'cd', 'ViewDeps::Result::CD',
+    { "foreign.id" => "self.cd" },
+);
+
+1;
diff --git a/t/lib/ViewDeps/Result/TrackNumberFives.pm b/t/lib/ViewDeps/Result/TrackNumberFives.pm
new file mode 100644 (file)
index 0000000..fc4a47b
--- /dev/null
@@ -0,0 +1,26 @@
+package    # hide from PAUSE
+    ViewDeps::Result::TrackNumberFives;
+
+use strict;
+use warnings;
+use base 'ViewDeps::Result::Track';
+
+__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
+__PACKAGE__->table('track_number_fives');
+__PACKAGE__->result_source_instance->view_definition(
+    "SELECT id,title,cd,track_number FROM track WHERE track_number = '5'");
+
+__PACKAGE__->add_columns(
+    id           => { data_type => 'integer', is_auto_increment => 1 },
+    title        => { data_type => 'text' },
+    cd           => { data_type => 'integer' },
+    track_number => { data_type => 'integer' },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+__PACKAGE__->belongs_to( 'cd', 'ViewDeps::Result::CD',
+    { "foreign.id" => "self.cd" },
+);
+
+1;
diff --git a/t/lib/ViewDeps/Result/Year2010CDs.pm b/t/lib/ViewDeps/Result/Year2010CDs.pm
new file mode 100644 (file)
index 0000000..2706fae
--- /dev/null
@@ -0,0 +1,31 @@
+package    # hide from PAUSE
+    ViewDeps::Result::Year2010CDs;
+
+use strict;
+use warnings;
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
+__PACKAGE__->table('year_2010_cds');
+__PACKAGE__->result_source_instance->view_definition(
+    "SELECT id,title,artist,year,number_tracks FROM cd WHERE year = '2010'");
+
+__PACKAGE__->add_columns(
+    id            => { data_type => 'integer', is_auto_increment => 1 },
+    title         => { data_type => 'text' },
+    artist        => { data_type => 'integer', is_nullable       => 0 },
+    year          => { data_type => 'integer' },
+    number_tracks => { data_type => 'integer' },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+__PACKAGE__->belongs_to( 'artist', 'ViewDeps::Result::Artist',
+    { "foreign.id" => "self.artist" },
+);
+
+__PACKAGE__->has_many( 'tracks', 'ViewDeps::Result::Track',
+    { "foreign.cd" => "self.id" },
+);
+
+1;
diff --git a/t/lib/ViewDeps/Result/Year2010CDsWithManyTracks.pm b/t/lib/ViewDeps/Result/Year2010CDsWithManyTracks.pm
new file mode 100644 (file)
index 0000000..c6e4144
--- /dev/null
@@ -0,0 +1,36 @@
+package    # hide from PAUSE
+    ViewDeps::Result::Year2010CDsWithManyTracks;
+
+use strict;
+use warnings;
+use base 'ViewDeps::Result::Year2010CDs';
+
+__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
+__PACKAGE__->table('year_2010_cds_with_many_tracks');
+__PACKAGE__->result_source_instance->view_definition(
+    "SELECT cd.id,cd.title,cd.artist,cd.year,cd.number_tracks,art.file FROM year_2010_cds cd JOIN artwork art on art.cd = cd.id WHERE cd.number_tracks > 10"
+);
+
+__PACKAGE__->result_source_instance->deploy_depends_on(
+    ["ViewDeps::Result::Year2010CDs"] );
+
+__PACKAGE__->add_columns(
+    id            => { data_type => 'integer', is_auto_increment => 1 },
+    title         => { data_type => 'text' },
+    artist        => { data_type => 'integer', is_nullable       => 0 },
+    year          => { data_type => 'integer' },
+    number_tracks => { data_type => 'integer' },
+    file       => { data_type => 'integer' },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+__PACKAGE__->belongs_to( 'artist', 'ViewDeps::Result::Artist',
+    { "foreign.id" => "self.artist" },
+);
+
+__PACKAGE__->has_many( 'tracks', 'ViewDeps::Result::Track',
+    { "foreign.cd" => "self.id" },
+);
+
+1;