#!/usr/bin/perl package # hide from pause Foo::DB::Workflow::Instance; use Moose; =pod =head1 DESCRIPTION This table will store workflow instances, retaining full history using this mechanism: $parent_instance = $instance->prev; It's structure is effectively close to an audit log. If this is a problem then you need to use a different abstraction, look at L and write a mutating storage solution instead, where there is only one workflow instance per item instead of a full history. It might be useful to add a cross reference from the workflow instance to the item it is keeping state for, so that when you delete the item instead of having a huge chain of cascaded deletes trigger through the C field, a single, aggregate cascading delete (C) could be used instead. =head1 COLUMNS =over 4 =item state The state the workflow instance is in. A rel to L. =item transition The transition that created this workflow instance. Could be C if this is an initial state. A rel to L. =item prev The instance this instance was derived from. Could be C if this is an initial state. A rel to this table. =back =head1 METHODS =over 4 =item _clone This overrides L to use L instead of L. =back =cut extends qw(DBIx::Class Moose::Object); with qw( Class::Workflow::Instance ); __PACKAGE__->load_components(qw(PK::Auto Core)); __PACKAGE__->table("instance"); __PACKAGE__->add_columns( id => { data_type => "integer", is_auto_increment => 1, is_nullable => 0, }, state => { data_type => "integer", is_nullable => 0, }, transition => { data_type => "integer", is_nullable => 1, }, prev => { data_type => "integer", is_nullable => 1, }, # ... more custom fields here... maybe extends Instance::Simple also has 'error', # logging data could go here, and any stateful fields ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->belongs_to( state => "Foo::DB::Workflow::State" ); __PACKAGE__->belongs_to( transition => "Foo::DB::Workflow::Transition" ); __PACKAGE__->belongs_to( prev => __PACKAGE__ ); # history sub _clone { my ( $self, @fields ) = @_; $self->copy({@fields}); } __PACKAGE__ __END__