From: Amiri Barksdale Date: Sun, 30 May 2010 22:36:33 +0000 (+0000) Subject: Change dependency parser in SQL::T::Parser::DBIC for @view_sources. --AKB X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ebed3aafa2b8501b96b7bb4dd6de5733a65ddb90;p=dbsrgits%2FDBIx-Class-Historic.git Change dependency parser in SQL::T::Parser::DBIC for @view_sources. --AKB --- diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index 5801edf..182206d 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -11,7 +11,7 @@ use warnings; 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/; @@ -292,28 +292,17 @@ EOW } 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 = - sort { - keys %{ $dependencies->{$a} || {} } - <=> - keys %{ $dependencies->{$b} || {} } - || - $a cmp $b - } - map { $dbicschema->source($_) } (sort keys %view_monikers); - - 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; + my @view_sources = + sort { + keys %{ $dependencies->{$a} || {} } + <=> + keys %{ $dependencies->{$b} || {} } + || + $a cmp $b + } + map { $dbicschema->source($_) } + keys %view_monikers; foreach my $source (@view_sources) { diff --git a/t/105view_deps.t b/t/105view_deps.t index a9e63e6..b584cbd 100644 --- a/t/105view_deps.t +++ b/t/105view_deps.t @@ -7,7 +7,6 @@ use Test::More; use Test::Exception; use lib qw(t/lib); use ViewDeps; -use Devel::Dwarn; BEGIN { use_ok('DBIx::Class::ResultSource::View'); @@ -26,9 +25,9 @@ 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_rs = $schema->resultset('Bar'); my @bar_deps = keys %{ $schema->resultset('Bar')->result_source->deploy_depends_on }; @@ -59,14 +58,9 @@ dies_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 ); +is(ViewDeps->source('Foo')->view_definition, $schema->resultset('Bar')->result_source->view_definition, "Package Foo's view definition is equivalent to resultset Bar's view definition"); -my $dir = "t/sql"; # tempdir(CLEANUP => 0); +my $dir = "t/sql"; $schema->create_ddl_dir( ['PostgreSQL','SQLite'], 0.1, $dir ); done_testing; diff --git a/t/lib/ViewDeps/Result/Bar.pm b/t/lib/ViewDeps/Result/Bar.pm index e0243df..b81d430 100644 --- a/t/lib/ViewDeps/Result/Bar.pm +++ b/t/lib/ViewDeps/Result/Bar.pm @@ -1,33 +1,26 @@ -package # hide from PAUSE +package # hide from PAUSE ViewDeps::Result::Bar; use strict; use warnings; -use base qw(ViewDeps::Result::Foo); +use base qw/ViewDeps::Result::Foo/; -use ViewDeps::Result::Mixin; -use ViewDeps::Result::Baz; +require ViewDeps::Result::Mixin; __PACKAGE__->table('bar'); __PACKAGE__->result_source_instance->deploy_depends_on( -["ViewDeps::Result::Baz", "ViewDeps::Result::Mixin"] -); + ["ViewDeps::Result::Mixin", "ViewDeps::Result::Baz"] ); -__PACKAGE__->add_columns( - b => { data_type => 'integer' } -); +__PACKAGE__->add_columns( b => { data_type => 'integer' } ); __PACKAGE__->belongs_to( - 'table', - 'ViewDeps::Result::JustATable', - { 'foreign.id' => 'self.b' }, + 'table', + 'ViewDeps::Result::JustATable', + { 'foreign.id' => 'self.b' }, ); -__PACKAGE__->has_many( - 'foos', - 'ViewDeps::Result::Foo', - { 'foreign.id' => 'self.id' } -); +__PACKAGE__->has_many( 'foos', 'ViewDeps::Result::Foo', + { 'foreign.id' => 'self.id' } ); 1; diff --git a/t/lib/ViewDeps/Result/Foo.pm b/t/lib/ViewDeps/Result/Foo.pm index 8950489..07f7c90 100644 --- a/t/lib/ViewDeps/Result/Foo.pm +++ b/t/lib/ViewDeps/Result/Foo.pm @@ -3,13 +3,13 @@ package # hide from PAUSE use strict; use warnings; -use base qw(DBIx::Class::Core); -use aliased 'DBIx::Class::ResultSource::View'; +use base qw(ViewDeps::Result::Quux); -__PACKAGE__->table_class(View); +__PACKAGE__->table_class('DBIx::Class::ResultSource::View'); __PACKAGE__->table('foo'); -__PACKAGE__->result_source_instance->view_definition("select * from just_a_table"); +__PACKAGE__->result_source_instance->view_definition( + "select * from just_a_table"); __PACKAGE__->add_columns( id => { data_type => 'integer', is_auto_increment => 1 }, @@ -21,6 +21,4 @@ __PACKAGE__->set_primary_key('id'); __PACKAGE__->belongs_to( 'bar', 'ViewDeps::Result::Bar', { 'foreign.id' => 'self.a' } ); - - 1; diff --git a/t/lib/ViewDeps/Result/Quux.pm b/t/lib/ViewDeps/Result/Quux.pm new file mode 100644 index 0000000..77862f6 --- /dev/null +++ b/t/lib/ViewDeps/Result/Quux.pm @@ -0,0 +1,24 @@ +package # hide from PAUSE + ViewDeps::Result::Quux; + +use strict; +use warnings; +use base qw(DBIx::Class::Core); + +__PACKAGE__->table_class('DBIx::Class::ResultSource::View'); +__PACKAGE__->table('quux'); + +__PACKAGE__->result_source_instance->view_definition( + "select * from quux"); + +__PACKAGE__->add_columns( + etc => { data_type => 'text' }, + c => { data_type => 'integer', is_nullable => 1 } +); + +__PACKAGE__->set_primary_key('c'); + +__PACKAGE__->belongs_to( 'foo', 'ViewDeps::Result::Foo', + { 'foreign.a' => 'self.c' } ); + +1; diff --git a/t/sql/ViewDeps-0.1-PostgreSQL.sql b/t/sql/ViewDeps-0.1-PostgreSQL.sql deleted file mode 100644 index 7661937..0000000 --- a/t/sql/ViewDeps-0.1-PostgreSQL.sql +++ /dev/null @@ -1,56 +0,0 @@ --- --- 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; -