Commit | Line | Data |
d27ed438 |
1 | package DBIx::Class::Schema::Journal::DB::AuditLog; |
2 | |
34b144a0 |
3 | use base 'DBIx::Class::Core'; |
30a4f241 |
4 | |
5 | sub journal_define_table { |
5b64dcdc |
6 | my ( $class, $source, $schema_class ) = @_; |
30a4f241 |
7 | |
34b144a0 |
8 | $class->table($source->name . '_audit_log'); |
30a4f241 |
9 | |
1befad28 |
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 | |
30a4f241 |
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 ) { |
f90c0e33 |
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 ); |
30a4f241 |
37 | } |
38 | |
39 | $class->set_primary_key( $source->primary_columns ); |
40 | |
5b64dcdc |
41 | $class->belongs_to(created => "${schema_class}::ChangeLog", 'create_id'); |
42 | $class->belongs_to(deleted => "${schema_class}::ChangeLog", 'delete_id'); |
30a4f241 |
43 | } |
d27ed438 |
44 | |
45 | 1; |