From: Justin Hunter Date: Sun, 18 Oct 2009 06:09:32 +0000 (-0700) Subject: remove all columns before adding new ones via ->fields or ->columns X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=452c34e6a5872b69863896814459603b9fc95422;p=dbsrgits%2FSQL-Translator-2.0-ish.git remove all columns before adding new ones via ->fields or ->columns --- diff --git a/lib/SQL/Translator/Object/Compat.pm b/lib/SQL/Translator/Object/Compat.pm index e85b9b8..8f2389f 100644 --- a/lib/SQL/Translator/Object/Compat.pm +++ b/lib/SQL/Translator/Object/Compat.pm @@ -6,6 +6,7 @@ role SQL::Translator::Object::Compat { use MooseX::MultiMethods; multi method fields(Str $columns) { + $self->clear_columns; my @columns = split /\s*,\s*/, $columns; for my $column (@columns) { die "Column '$column' does not exist!" unless $self->table->exists_column($column); @@ -15,6 +16,7 @@ role SQL::Translator::Object::Compat { } multi method fields(ArrayRef $columns) { + $self->clear_columns; for my $column (@$columns) { die "Column '$column' does not exist!" unless $self->table->exists_column($column); $self->add_column($self->table->get_column($column)); diff --git a/lib/SQL/Translator/Object/Constraint.pm b/lib/SQL/Translator/Object/Constraint.pm index 2badd90..9a9b43c 100644 --- a/lib/SQL/Translator/Object/Constraint.pm +++ b/lib/SQL/Translator/Object/Constraint.pm @@ -27,6 +27,7 @@ class SQL::Translator::Object::Constraint extends SQL::Translator::Object { get_columns => 'values', get_column => 'get', add_column => 'set', + clear_columns => 'clear', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); diff --git a/lib/SQL/Translator/Object/Index.pm b/lib/SQL/Translator/Object/Index.pm index 828ee21..4fad2fe 100644 --- a/lib/SQL/Translator/Object/Index.pm +++ b/lib/SQL/Translator/Object/Index.pm @@ -26,6 +26,7 @@ class SQL::Translator::Object::Index extends SQL::Translator::Object { get_columns => 'values', get_column => 'get', add_column => 'set', + clear_columns => 'clear', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); diff --git a/lib/SQL/Translator/Object/Table.pm b/lib/SQL/Translator/Object/Table.pm index b6b78d6..5b572e7 100644 --- a/lib/SQL/Translator/Object/Table.pm +++ b/lib/SQL/Translator/Object/Table.pm @@ -28,6 +28,7 @@ class SQL::Translator::Object::Table extends SQL::Translator::Object is dirty { get_column => 'get', add_column => 'set', remove_column => 'delete', + clear_columns => 'clear', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); diff --git a/lib/SQL/Translator/Object/Trigger.pm b/lib/SQL/Translator/Object/Trigger.pm index cf85168..d820b12 100644 --- a/lib/SQL/Translator/Object/Trigger.pm +++ b/lib/SQL/Translator/Object/Trigger.pm @@ -19,6 +19,7 @@ class SQL::Translator::Object::Trigger extends SQL::Translator::Object { get_columns => 'values', get_column => 'get', add_column => 'set', + clear_columns => 'clear', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, );