more cleanup
[dbsrgits/DBIx-Class-Journal.git] / lib / DBIx / Class / Schema / Journal / DB / AuditHistory.pm
1 package DBIx::Class::Schema::Journal::DB::AuditHistory;
2
3 use base 'DBIx::Class';
4
5 sub journal_define_table {
6     my ( $class, $source ) = @_;
7
8     $class->load_components(qw(Core));
9
10     $class->table($source->name . "_audit_history");
11     
12     $class->add_columns(
13         audit_history_id => {
14             data_type => 'integer',
15             is_nullable => 0,
16             is_primary_key => 1,
17             is_auto_increment => 1,
18         },
19         audit_change_id => {
20             data_type => 'integer',
21             is_nullable => 0,
22             is_foreign_key => 1,
23         },
24     );
25
26     $class->set_primary_key("audit_history_id");
27
28     foreach my $column ( $source->columns ) {
29         my $info = $source->column_info($column);
30
31         my %hist_info = %$info;
32
33         delete $hist_info{$_} for qw(
34             is_foreign_key
35             is_primary_key
36             is_auto_increment
37             default_value
38         );
39         
40         $hist_info{is_nullable} = 1;
41
42         $class->add_column($column => \%hist_info);
43     }
44                            
45     $class->belongs_to('change', 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'audit_change_id');
46 }
47
48 1;