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/;
}
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)
{
use Test::Exception;
use lib qw(t/lib);
use ViewDeps;
-use Devel::Dwarn;
BEGIN {
use_ok('DBIx::Class::ResultSource::View');
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 };
}
"...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;
-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;
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 },
__PACKAGE__->belongs_to( 'bar', 'ViewDeps::Result::Bar',
{ 'foreign.id' => 'self.a' } );
-
-
1;
--- /dev/null
+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;
+++ /dev/null
---
--- 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;
-