is => 'rw',
isa => Str,
required => 1,
- trigger => sub { my ($self, $new, $old) = @_; if (defined $old) { $self->table->drop_column($old); $self->table->add_column($self) } }
+ trigger => sub { my ($self, $new, $old) = @_; if (defined $old) { $self->table->remove_column($old); $self->table->add_column($self) } }
);
has 'data_type' => (
use MooseX::Declare;
role SQL::Translator::Object::Compat {
+ use MooseX::Types qw(Any ArrayRef Int Str);
+ use SQL::Translator::Types qw(Column Constraint Index Table);
+
use MooseX::MultiMethods;
multi method fields(Str $columns) {
multi method fields(Any $) { $self->column_ids }
+ method add_field(Column $column does coerce) { $self->add_column($column) }
+
+ method drop_table(Table|Str $table, Int :$cascade = 0) { $self->remove_table($table, cascade => $cascade) }
+ method drop_column(Column|Str $column, Int :$cascade = 0) { $self->remove_column($column, cascade => $cascade) }
+ method drop_index(Index|Str $index) { $self->remove_index($index) }
+ method drop_constraint(Constraint|Str $constraint) { $self->remove_constraint($constraint) }
+
method get_fields { $self->get_columns }
method get_field { $self->get_column }
method field_names { $self->column_ids }
default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
);
- around add_table(Table $table) {
+ around add_table(Table $table does coerce) {
die "Can't use table name " . $table->name if $self->exists_table($table->name) || $table->name eq '';
$table->schema($self);
$self->$orig($table->name, $table);
}
- around add_view(View $view) { $self->$orig($view->name, $view) }
- around add_procedure(Procedure $procedure) { $self->$orig($procedure->name, $procedure) }
- around add_trigger(Trigger $trigger) { $self->$orig($trigger->name, $trigger) }
+ around add_view(View $view does coerce) { $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) }
method is_valid { return $self->get_tables ? 1 : undef }
- multi method drop_table(Table $table, Int :$cascade = 0) {
- die "Can't drop non-existant table " . $table->name unless $self->exists_table($table->name);
- $self->remove_table($table->name);
-
- }
-
- multi method drop_table(Str $table, Int :$cascade = 0) {
- die "Can't drop non-existant table " . $table unless $self->exists_table($table);
- $self->remove_table($table);
+ around remove_table(Table|Str $table, Int :$cascade = 0) {
+ my $name = is_Table($table) ? $table->name : $table;
+ die "Can't drop non-existant table " . $name unless $self->exists_table($name);
+ $self->$orig($name);
}
method order { }
get_constraints => 'values',
get_constraint => 'get',
add_constraint => 'set',
+ remove_constraint => 'delete',
},
default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
);
default => 0
);
- method add_field(Column $column does coerce) { $self->add_column($column) }
-
around add_column(Column $column does coerce) {
die "Can't use column name " . $column->name if $self->exists_column($column->name) || $column->name eq '';
$column->table($self);
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 column " . $column->name unless $self->exists_column($column->name);
- $self->remove_column($column->name);
-
+ around remove_column(Column|Str $column, Int :$cascade = 0) {
+ my $name = is_Column($column) ? $column->name : $column;
+ die "Can't drop non-existant column " . $name unless $self->exists_column($name);
+ $self->$orig($name);
}
- multi method drop_column(Str $column, Int :$cascade = 0) {
- die "Can't drop non-existant column " . $column unless $self->exists_column($column);
- $self->remove_column($column);
- }
-
- multi method drop_index(Index $index) {
- die "Can't drop non-existant index " . $index->name unless $self->exists_index($index->name);
- $self->remove_index($index->name);
-
+ around remove_index(Index|Str $index) {
+ my $name = is_Index($index) ? $index->name : $index;
+ die "Can't drop non-existant index " . $name unless $self->exists_index($name);
+ $self->$orig($name);
}
- multi method drop_index(Str $index) {
- die "Can't drop non-existant index " . $index unless $self->exists_index($index);
- $self->remove_index($index);
+ around remove_constraint(Constraint|Str $constraint) {
+ my $name = is_Constraint($constraint) ? $constraint->name : $constraint;
+ die "Can't drop non-existant constraint " . $name unless $self->exists_constraint($name);
+ $self->$orig($name);
}
}