From: Justin Hunter Date: Fri, 9 Oct 2009 13:55:29 +0000 (-0700) Subject: add remove methods for the rest of the objects and add around methods for add_ ... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e09616eca0c8bb869d6b9e70d2288178b1d6d676;p=dbsrgits%2FSQL-Translator-2.0-ish.git add remove methods for the rest of the objects and add around methods for add_ & remove_ view (sanity checks) --- diff --git a/lib/SQL/Translator/Object/Schema.pm b/lib/SQL/Translator/Object/Schema.pm index 5017bcf..7b48900 100644 --- a/lib/SQL/Translator/Object/Schema.pm +++ b/lib/SQL/Translator/Object/Schema.pm @@ -41,6 +41,7 @@ class SQL::Translator::Object::Schema extends SQL::Translator::Object { get_views => 'values', get_view => 'get', add_view => 'set', + remove_view => 'delete', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); @@ -55,6 +56,7 @@ class SQL::Translator::Object::Schema extends SQL::Translator::Object { get_procedures => 'values', get_procedure => 'get', add_procedure => 'set', + remove_procedure => 'delete', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); @@ -69,6 +71,7 @@ class SQL::Translator::Object::Schema extends SQL::Translator::Object { get_triggers => 'values', get_trigger => 'get', add_trigger => 'set', + remove_trigger => 'delete', }, default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash }, ); @@ -79,7 +82,12 @@ class SQL::Translator::Object::Schema extends SQL::Translator::Object { $self->$orig($table->name, $table); } - around add_view(View $view does coerce) { $self->$orig($view->name, $view) } + around add_view(View $view does coerce) { + die "Can't use view name " . $view->name if $self->exists_view($view->name) || $view->name eq ''; + $view->schema($self); + $self->$orig($view->name, $view) + } + around add_procedure(Procedure $procedure does coerce) { $self->$orig($procedure->name, $procedure) } around add_trigger(Trigger $trigger does coerce) { $self->$orig($trigger->name, $trigger) } @@ -91,6 +99,12 @@ class SQL::Translator::Object::Schema extends SQL::Translator::Object { $self->$orig($name); } + around remove_view(View|Str $view) { + my $name = is_View($view) ? $view->name : $view; + die "Can't drop non-existant view " . $name unless $self->exists_view($name); + $self->$orig($name); + } + method order { } method perform_action_when { } method database_events { }