is => 'rw',
isa => Bit,
required => 1,
- default => 1
+ default => 1,
);
has 'is_unique' => (
my $order = $self->_order;
unless (defined $order && $order) {
my $columns = Tie::IxHash->new( map { $_->name => $_ } $self->table->get_columns );
- $order = ($columns->Indices($self->name) + 1) || 0;
+ $order = $columns->Indices($self->name) || 0; $order++;
$self->_order($order);
}
return $order;
use MooseX::Declare;
class SQL::Translator::Object::Constraint extends SQL::Translator::Object {
- use MooseX::Types::Moose qw(ArrayRef Bool HashRef Maybe Str Undef);
+ use MooseX::Types::Moose qw(ArrayRef Bool HashRef Int Maybe Str Undef);
use MooseX::MultiMethods;
use SQL::Translator::Types qw(Column MatchType Table);
default => ''
);
+ has '_order' => (
+ isa => Int,
+ is => 'rw',
+ );
+
has 'on_delete' => ( is => 'rw', required => 0);
has 'on_update' => ( is => 'rw', required => 0);
$self->$orig($column->name, $column)
}
+ multi method order(Int $order) { $self->_order($order); }
+ multi method order {
+ my $order = $self->_order;
+ unless (defined $order && $order) {
+ my $tables = Tie::IxHash->new( map { $_->name => $_ } $self->schema->get_tables );
+ $order = $tables->Indices($self->name) || 0; $order++;
+ $self->_order($order);
+ }
+ return $order;
+ }
+
method is_valid { return $self->has_type && scalar $self->column_ids ? 1 : undef }
}
use MooseX::Declare;
class SQL::Translator::Object::Table extends SQL::Translator::Object is dirty {
- use MooseX::Types::Moose qw(Any Bool HashRef Str);
+ use MooseX::Types::Moose qw(Any Bool HashRef Int Str);
use MooseX::MultiMethods;
use SQL::Translator::Types qw(Column Constraint Index Schema Sequence);
use SQL::Translator::Object::Column;
default => 0
);
+ has '_order' => (
+ is => 'rw',
+ isa => Int,
+ );
+
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);
return $primary_key;
}
+ multi method order(Int $order) { $self->_order($order); }
+ multi method order {
+ my $order = $self->_order;
+ unless (defined $order && $order) {
+ my $tables = Tie::IxHash->new( map { $_->name => $_ } $self->schema->get_tables );
+ $order = $tables->Indices($self->name) || 0; $order++;
+ $self->_order($order);
+ }
+ return $order;
+ }
+
method is_valid { return $self->get_columns ? 1 : undef }
- method order { }
before name($name?) { die "Can't use table name $name, table already exists" if $name && $self->schema->exists_table($name) && $name ne $self->name }
use MooseX::Declare;
class SQL::Translator::Object::Trigger extends SQL::Translator::Object {
- use MooseX::Types::Moose qw(Any ArrayRef HashRef Str);
+ use MooseX::Types::Moose qw(Any ArrayRef HashRef Int Str);
use MooseX::MultiMethods;
use SQL::Translator::Types qw(Column Schema Table);
required => 1,
);
+ has '_order' => (
+ isa => Int,
+ is => 'rw',
+ );
+
around add_column(Column $column) { $self->$orig($column->name, $column) }
multi method database_events(Str $database_event) { $self->add_database_event($database_event); $self->database_events }
multi method database_events(ArrayRef $database_events) { $self->add_database_event($_) for @$database_events; $self->database_events }
multi method database_events { $self->_database_events }
+ multi method order(Int $order) { $self->_order($order); }
+ multi method order {
+ my $order = $self->_order;
+ unless (defined $order && $order) {
+ my $triggers = Tie::IxHash->new( map { $_->name => $_ } $self->schema->get_triggers );
+ $order = $triggers->Indices($self->name) || 0; $order++;
+ $self->_order($order);
+ }
+ return $order;
+ }
+
method is_valid { 1 }
}