From: Peter Rabbitson Date: Mon, 4 May 2009 07:17:36 +0000 (+0000) Subject: table/field counts are held per-object, not globally X-Git-Tag: v0.11008~163^2~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d37416fd148d986a4c228899e74b80404806bb23;p=dbsrgits%2FSQL-Translator.git table/field counts are held per-object, not globally Tests adjusted (no idea why they were initially written this way...) --- diff --git a/lib/SQL/Translator/Schema.pm b/lib/SQL/Translator/Schema.pm index 926cf7c..eebb185 100644 --- a/lib/SQL/Translator/Schema.pm +++ b/lib/SQL/Translator/Schema.pm @@ -54,12 +54,27 @@ use SQL::Translator::Schema::View; use SQL::Translator::Utils 'parse_list_arg'; use base 'SQL::Translator::Schema::Object'; -use vars qw[ $VERSION $TABLE_ORDER $VIEW_ORDER $TRIGGER_ORDER $PROC_ORDER ]; +use vars qw[ $VERSION ]; $VERSION = '1.59'; __PACKAGE__->_attributes(qw/name database translator/); +sub new { + my $class = shift; + my $self = $class->SUPER::new (@_) + or return; + + $self->{_order} = { map { $_ => 0 } qw/ + table + view + trigger + proc + /}; + + return $self; +} + # ---------------------------------------------------------------------- sub as_graph { @@ -143,7 +158,7 @@ not be created. or return $self->error( $table_class->error ); } - $table->order( ++$TABLE_ORDER ); + $table->order( ++$self->{_order}{table} ); # We know we have a name as the Table->new above errors if none given. my $table_name = $table->name; @@ -237,7 +252,7 @@ procedure will not be created. or return $self->error( $procedure_class->error ); } - $procedure->order( ++$PROC_ORDER ); + $procedure->order( ++$self->{_order}{proc} ); my $procedure_name = $procedure->name or return $self->error('No procedure name'); @@ -323,7 +338,7 @@ not be created. or return $self->error( $trigger_class->error ); } - $trigger->order( ++$TRIGGER_ORDER ); + $trigger->order( ++$self->{_order}{trigger} ); my $trigger_name = $trigger->name or return $self->error('No trigger name'); if ( defined $self->{'triggers'}{$trigger_name} ) { @@ -405,7 +420,7 @@ not be created. $view = $view_class->new( \%args ) or return $view_class->error; } - $view->order( ++$VIEW_ORDER ); + $view->order( ++$self->{_order}{view} ); my $view_name = $view->name or return $self->error('No view name'); if ( defined $self->{'views'}{$view_name} ) { diff --git a/lib/SQL/Translator/Schema/Table.pm b/lib/SQL/Translator/Schema/Table.pm index fff4799..01fb965 100644 --- a/lib/SQL/Translator/Schema/Table.pm +++ b/lib/SQL/Translator/Schema/Table.pm @@ -47,7 +47,7 @@ use Data::Dumper; use base 'SQL::Translator::Schema::Object'; -use vars qw( $VERSION $FIELD_ORDER ); +use vars qw( $VERSION ); $VERSION = '1.59'; @@ -77,6 +77,20 @@ Object constructor. =cut +sub new { + my $class = shift; + my $self = $class->SUPER::new (@_) + or return; + + $self->{_order} = { map { $_ => 0 } qw/ + field + /}; + + return $self; +} + + + # ---------------------------------------------------------------------- sub add_constraint { @@ -320,7 +334,7 @@ existing field, you will get an error and the field will not be created. $self->error( $field_class->error ); } - $field->order( ++$FIELD_ORDER ); + $field->order( ++$self->{_order}{field} ); # We know we have a name as the Field->new above errors if none given. my $field_name = $field->name; diff --git a/t/17sqlfxml-producer.t b/t/17sqlfxml-producer.t index e909673..050bc42 100644 --- a/t/17sqlfxml-producer.t +++ b/t/17sqlfxml-producer.t @@ -172,7 +172,7 @@ $ans = < - +
@@ -290,10 +290,10 @@ $ans = < -
+
- + diff --git a/t/18ttschema-producer.t b/t/18ttschema-producer.t index 7b5d5b9..2df7891 100644 --- a/t/18ttschema-producer.t +++ b/t/18ttschema-producer.t @@ -293,7 +293,7 @@ Fields is_foreign_key: 0 foreign_key_reference: is_valid: 1 - order: 10 + order: 1 table: Another diff --git a/t/24yaml.t b/t/24yaml.t index 8955bce..9f9f2c7 100644 --- a/t/24yaml.t +++ b/t/24yaml.t @@ -153,7 +153,7 @@ schema: is_primary_key: 0 is_unique: 0 name: age - order: 10 + order: 4 size: - 0 name: @@ -164,7 +164,7 @@ schema: is_primary_key: 0 is_unique: 0 name: name - order: 9 + order: 3 size: - 30 person_id: @@ -175,7 +175,7 @@ schema: is_primary_key: 1 is_unique: 0 name: person_id - order: 8 + order: 2 size: - 0 pet_id: @@ -186,7 +186,7 @@ schema: is_primary_key: 1 is_unique: 0 name: pet_id - order: 7 + order: 1 size: - 0 indices: [] diff --git a/t/39-filter-globals.t b/t/39-filter-globals.t index 68fd98d..2a7636d 100644 --- a/t/39-filter-globals.t +++ b/t/39-filter-globals.t @@ -74,7 +74,7 @@ schema: is_primary_key: 0 is_unique: 0 name: created - order: 3 + order: 2 size: - 0 first_name: @@ -85,7 +85,7 @@ schema: is_primary_key: 0 is_unique: 0 name: first_name - order: 2 + order: 1 size: - 0 modified: @@ -96,7 +96,7 @@ schema: is_primary_key: 0 is_unique: 1 name: modified - order: 4 + order: 3 size: - 0 indices: