From: Justin Hunter Date: Tue, 8 Sep 2009 16:02:44 +0000 (-0700) Subject: allow adding of indexes where name is "" X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c27fec89400be747e44711d5be24dc7ffeb38dbc;p=dbsrgits%2FSQL-Translator-2.0-ish.git allow adding of indexes where name is "" --- diff --git a/lib/SQL/Translator/Object/Table.pm b/lib/SQL/Translator/Object/Table.pm index bb7aa13..785963c 100644 --- a/lib/SQL/Translator/Object/Table.pm +++ b/lib/SQL/Translator/Object/Table.pm @@ -84,17 +84,25 @@ class SQL::Translator::Object::Table extends SQL::Translator::Object { ); around add_column(Column $column) { $self->$orig($column->name, $column) } - around add_index(Index $index) { $self->$orig($index->name, $index) } - around add_sequence(Sequence $sequence) { $self->$orig($sequence->name, $sequence) } around add_constraint(Constraint $constraint) { my $name = $constraint->name; if ($name eq '') { - my $index = 0; - while ($self->exists_constraint('ANON' . $index)) { $index++ } - $name = 'ANON' . $index; + my $idx = 0; + while ($self->exists_constraint('ANON' . $idx)) { $idx++ } + $name = 'ANON' . $idx; } $self->$orig($name, $constraint) } + around add_index(Index $index) { + my $name = $index->name; + if ($name eq '') { + my $idx = 0; + while ($self->exists_index('ANON' . $idx)) { $idx++ } + $name = 'ANON' . $idx; + } + $self->$orig($name, $index) + } + around add_sequence(Sequence $sequence) { $self->$orig($sequence->name, $sequence) } multi method primary_key(Any $) { grep /^PRIMARY KEY$/, $_->type for $self->get_constraints } multi method primary_key(Str $column) { $self->get_column($column)->is_primary_key(1) }