70fe8183fe52bf363c89e8de11350ce330080558
[dbsrgits/DBIx-Class-Journal.git] / lib / DBIx / Class / Schema / Journal / DB / AuditLog.pm
1 package DBIx::Class::Schema::Journal::DB::AuditLog;
2
3 use base 'DBIx::Class::Core';
4
5 sub journal_define_table {
6     my ( $class, $source, $schema_class ) = @_;
7
8     $class->table($source->name . '_audit_log');
9
10     # the create_id is the id of first insertion of the row
11     # so we always know where to roll back to
12     # and presumably should be supplied on every insert
13
14     $class->add_columns(
15         create_id => {
16             data_type => 'integer',
17             is_nullable => 0,
18             is_foreign_key => 1,
19         },
20         delete_id => {
21             data_type => 'integer',
22             is_nullable => 1,
23             is_foreign_key => 1,
24         }
25     );
26
27     foreach my $column ( $source->primary_columns ) {
28         $class->add_column( $column => { %{ $source->column_info($column) } } );
29     }
30
31     $class->set_primary_key( $source->primary_columns );
32
33     $class->belongs_to(created => "${schema_class}::ChangeLog", 'create_id');
34     $class->belongs_to(deleted => "${schema_class}::ChangeLog", 'delete_id');
35 }
36
37 1;