From: Amiri Barksdale Date: Fri, 28 May 2010 15:06:57 +0000 (+0000) Subject: New parser sort functions fulfills its purpose but appears to make deploy_depends_on... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9efcc79f18629f5960fb0fce8092e6abd4c00d04;p=dbsrgits%2FDBIx-Class-Historic.git New parser sort functions fulfills its purpose but appears to make deploy_depends_on superfluous. I will merge the depeendencies and deploy_depends_on hashes to make sure any uncaught are folded in. --AKB --- diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index 20a2d64..5801edf 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -299,19 +299,6 @@ EOW #(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 { @@ -322,8 +309,10 @@ EOW $a cmp $b } map { $dbicschema->source($_) } (sort keys %view_monikers); - - print STDERR Dumper @view_sources; + + + print STDERR "View monikers: ", Dumper %view_monikers; + print STDERR "Source name of view source: ", $_->source_name, "\n" for @view_sources; print STDERR Dumper "Dependencies: ", $dependencies; foreach my $source (@view_sources) diff --git a/t/105view_deps.t b/t/105view_deps.t index d3aaf58..a9e63e6 100644 --- a/t/105view_deps.t +++ b/t/105view_deps.t @@ -17,8 +17,8 @@ BEGIN { 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'); +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/; @@ -27,16 +27,19 @@ can_ok( $view, $_ ) for qw/new from deploy_depends_on/; my $schema = ViewDeps->connect; ok( $schema, 'Connected to ViewDeps schema OK' ); my $bar_rs = $schema->resultset('Bar'); + #diag(DwarnS $bar_rs->result_source); -my @bar_deps = keys %{ $schema->resultset('Bar')->result_source->deploy_depends_on }; +my @bar_deps + = keys %{ $schema->resultset('Bar')->result_source->deploy_depends_on }; -my @foo_deps = keys %{ $schema->resultset('Foo')->result_source->deploy_depends_on }; +my @foo_deps + = keys %{ $schema->resultset('Foo')->result_source->deploy_depends_on }; isa_ok( $schema->resultset('Bar')->result_source, 'DBIx::Class::ResultSource::View', 'Bar' ); -is( $bar_deps[0], 'baz', 'which is reported to depend on baz...' ); +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...' ); @@ -51,15 +54,19 @@ isa_ok( "Baz on the other hand" ); dies_ok { - ViewDeps::Result::Baz->result_source_instance->deploy_depends_on( - { ViewDeps::Result::Mixin->result_source_instance->name => 1 } ); + ViewDeps::Result::Baz->result_source_instance + ->deploy_depends_on("ViewDeps::Result::Mixin"); } "...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); +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); +my $dir = "t/sql"; # tempdir(CLEANUP => 0); +$schema->create_ddl_dir( ['PostgreSQL','SQLite'], 0.1, $dir ); done_testing; diff --git a/t/sql/ViewDeps-0.1-PostgreSQL.sql b/t/sql/ViewDeps-0.1-PostgreSQL.sql new file mode 100644 index 0000000..7661937 --- /dev/null +++ b/t/sql/ViewDeps-0.1-PostgreSQL.sql @@ -0,0 +1,56 @@ +-- +-- Created by SQL::Translator::Producer::PostgreSQL +-- Created on Fri May 28 08:01:56 2010 +-- +-- +-- Table: just_a_table +-- +DROP TABLE "just_a_table" CASCADE; +CREATE TABLE "just_a_table" ( + "id" serial NOT NULL, + "name" character varying(255) NOT NULL, + PRIMARY KEY ("id") +); + +-- +-- Table: mixin +-- +DROP TABLE "mixin" CASCADE; +CREATE TABLE "mixin" ( + "id" serial NOT NULL, + "words" text NOT NULL, + PRIMARY KEY ("id") +); + +-- +-- Table: baz +-- +DROP TABLE "baz" CASCADE; +CREATE TABLE "baz" ( + "id" integer NOT NULL +); +CREATE INDEX "baz_idx_b" on "baz" ("b"); + +-- +-- View: "bar" +-- +DROP VIEW "bar"; +CREATE VIEW "bar" ( "id", "a", "b" ) AS + select * from just_a_table +; + +-- +-- View: "foo" +-- +DROP VIEW "foo"; +CREATE VIEW "foo" ( "id", "a" ) AS + select * from just_a_table +; + +-- +-- Foreign Key Definitions +-- + +ALTER TABLE "baz" ADD FOREIGN KEY ("b") + REFERENCES "just_a_table" ("id") DEFERRABLE; +