RT60983: why is *_audit_log id col an auto-inc?
[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         my %column_info = %{$source->column_info($column)};
29         delete $column_info{$_} for qw(
30            is_autoincrement
31            is_foreign_key
32            default_value
33            sequence
34            auto_nextval
35         );
36         $class->add_column( $column => \%column_info );
37     }
38
39     $class->set_primary_key( $source->primary_columns );
40
41     $class->belongs_to(created => "${schema_class}::ChangeLog", 'create_id');
42     $class->belongs_to(deleted => "${schema_class}::ChangeLog", 'delete_id');
43 }
44
45 1;