use DBIx::Class::ResultSet;
use SQL::Translator::Parser::DBIx::Class;
+use Data::Dumper::Concise;
+
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/ResultSource/);
__PACKAGE__->mk_group_accessors(
my ( $self, @args ) = @_;
my $new = $self->next::method(@args);
$new->{deploy_depends_on}
- = { map { $_ => 1 } @{ ($new->{deploy_depends_on} || []) } };
- use Data::Dumper;
- print STDERR Dumper $new;
+ = { map { $_->result_source_instance->name => 1 } @{ $new->{deploy_depends_on}||[] } }
+ unless ref $new->{deploy_depends_on} eq 'HASH';
return $new;
}
use vars qw($DEBUG $VERSION @EXPORT_OK);
$VERSION = '1.10';
$DEBUG = 0 unless defined $DEBUG;
-
+use Data::Dumper;
use Exporter;
use SQL::Translator::Utils qw(debug normalize_name);
use Carp::Clan qw/^SQL::Translator|^DBIx::Class/;
use Scalar::Util ();
-
use base qw(Exporter);
@EXPORT_OK = qw(parse);
my $dependencies = {
map { $_ => _resolve_deps ($_, \%tables) } (keys %tables)
};
+
for my $table (sort
{
keys %{$dependencies->{$a} || {} } <=> keys %{ $dependencies->{$b} || {} }
}
my %views;
+ #my @view_sources =
+ #sort {
+ #(exists $a->deploy_depends_on->{$b->source_name} ? 1 : 0)
+ #<=>
+ #(exists $b->deploy_depends_on->{$a->source_name} ? 1 : 0)
+ #}
+ #map { $dbicschema->source($_) } (sort keys %view_monikers);
+
+ #my @view_sources =
+ #grep { $_->can('view_definition') } # make sure it's a view
+ #map { $dbicschema->source($_) } # have to get a source
+ #map { $tables{$_}{source}{source_name} } # have to get a sourcename
+ #sort {
+ #keys %{ $dependencies->{$a} || {} }
+ #<=>
+ #keys %{ $dependencies->{$b} || {} }
+ #||
+ #$a cmp $b
+ #}
+ #keys %$dependencies;
+
my @view_sources =
- sort {
- (exists $a->depends_on->{$b->source_name} ? 1 : 0)
- <=>
- (exists $b->depends_on->{$a->source_name} ? 1 : 0)
- }
- map { $dbicschema->source($_) } (sort keys %view_monikers);
+ sort {
+ keys %{ $dependencies->{$a} || {} }
+ <=>
+ keys %{ $dependencies->{$b} || {} }
+ ||
+ $a cmp $b
+ }
+ map { $dbicschema->source($_) } (sort keys %view_monikers);
+
+ print STDERR Dumper @view_sources;
+ print STDERR Dumper "Dependencies: ", $dependencies;
foreach my $source (@view_sources)
{
isa_ok( $schema->resultset('Bar')->result_source,
'DBIx::Class::ResultSource::View', 'Bar' );
-is( $bar_deps[0], 'mixin', 'which is reported to depend on mixin.' );
+is( $bar_deps[0], 'baz', 'which is reported to depend on baz...' );
+is( $bar_deps[1], 'mixin', 'and on mixin.' );
is( $foo_deps[0], undef, 'Foo has no dependencies...' );
isa_ok(
}
"...and you cannot use deploy_depends_on with that";
+diag("ViewDeps::Foo view definition: ", ViewDeps->source('Foo')->view_definition);
+diag("schema->rs(Bar) view definition: ", $schema->resultset('Bar')->result_source->view_definition);
+
+my $dir = "t/sql"; # tempdir(CLEANUP => 0);
+$schema->create_ddl_dir([ 'PostgreSQL' ], 0.1, $dir);
+
done_testing;
__PACKAGE__->table('bar');
__PACKAGE__->result_source_instance->deploy_depends_on(
- "ViewDeps::Result::Baz", "ViewDeps::Result::Mixin"
+["ViewDeps::Result::Baz", "ViewDeps::Result::Mixin"]
);
__PACKAGE__->add_columns(
use warnings;
use base qw(DBIx::Class::Core);
-__PACKAGE__->table('bar');
+__PACKAGE__->table('baz');
__PACKAGE__->add_columns( id => { data_type => 'integer' } );
__PACKAGE__->table_class(View);
__PACKAGE__->table('foo');
+
+__PACKAGE__->result_source_instance->view_definition("select * from just_a_table");
+
__PACKAGE__->add_columns(
id => { data_type => 'integer', is_auto_increment => 1 },
a => { data_type => 'integer', is_nullable => 1 }
__PACKAGE__->belongs_to( 'bar', 'ViewDeps::Result::Bar',
{ 'foreign.id' => 'self.a' } );
+
+
1;