has 'type' => (
is => 'rw',
isa => Str,
+ predicate => 'has_type',
);
has 'deferrable' => (
default => ''
);
- around add_column(Column $column) { $self->$orig($column->name, $column) }
+ around add_column(Column $column) {
+ if ($self->has_type && $self->type eq 'PRIMARY KEY') {
+ $column->is_primary_key(1);
+ }
+ $self->$orig($column->name, $column)
+ }
+
+ method is_valid { return $self->has_type && scalar $self->column_ids ? 1 : undef }
}
$name = 'ANON' . $idx;
}
$constraint->table($self);
+ if ($constraint->has_type && $constraint->type eq 'PRIMARY KEY') {
+ $self->get_column($_)->is_primary_key(1) for $constraint->column_ids;
+ }
$self->$orig($name, $constraint)
}