From: Justin Hunter Date: Tue, 22 Sep 2009 00:33:55 +0000 (-0700) Subject: add ability to drop(remove) a column X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=40fb14a965cea852d27d2325b1b39cd1ef31f81a;p=dbsrgits%2FSQL-Translator-2.0-ish.git add ability to drop(remove) a column --- diff --git a/lib/SQL/Translator/Object/Table.pm b/lib/SQL/Translator/Object/Table.pm index bc5f9d0..41d54c7 100644 --- a/lib/SQL/Translator/Object/Table.pm +++ b/lib/SQL/Translator/Object/Table.pm @@ -27,6 +27,7 @@ class SQL::Translator::Object::Table extends SQL::Translator::Object is dirty { get_columns => 'values', get_column => 'get', add_column => 'set', + remove_column => 'delete', ## compat get_fields => 'values', @@ -117,6 +118,16 @@ class SQL::Translator::Object::Table extends SQL::Translator::Object is dirty { method is_valid { return $self->get_columns ? 1 : undef } method order { } - before name($name?) { die "Can't use table name $name" if $name && $self->schema->exists_table($name); } + before name($name?) { die "Can't use table name $name, table already exists" if $name && $self->schema->exists_table($name) && $name ne $self->name } + multi method drop_column(Column $column, Int :$cascade = 0) { + die "Can't drop non-existant table " . $column->name unless $self->exists_column($column->name); + $self->remove_column($column->name); + + } + + multi method drop_column(Str $column, Int :$cascade = 0) { + die "Can't drop non-existant table " . $column unless $self->exists_column($column); + $self->remove_column($column); + } }