my $obj = $self->result_source->resultset->find( $self->ident_condition );
$ah->create({
- $obj->get_columns
- });
+ $obj->get_columns,
+ change => { changeset_id => $ah->result_source->schema->current_changeset },
+ });
}
$self->next::method($upd, @rest);
A ChangeSet has_many Changes.
-=item Change
+=item ChangeLog
Each change/operation done in the transaction is recorded as a row in
-the Change table. It contains an auto-incrementing ID, the
+the ChangeLog table. It contains an auto-incrementing ID, the
changeset_id and an order column for the ordering of each change in
the changeset.
For every table in the original database to be audited, an
AuditHistory table is created. Each row has a change_id field
-containing the ID of the Change row. The other fields correspond to
+containing the ID of the ChangeLog row. The other fields correspond to
all the fields from the original table. Each time a column value in
the original table is changed, the entire row contents before the
change are added as a new row in this table.
$class->load_components(qw(Core));
- $class->table($source->name . "_audit_log");
+ $class->table($source->name . "_audit_history");
- $class->add_column( audit_change_id => {
- data_type => 'integer',
- is_nullable => 0,
- is_primary_key => 1,
- });
-
- $class->set_primary_key("audit_change_id");
+ $class->add_columns(
+ audit_history_id => {
+ data_type => 'integer',
+ is_nullable => 0,
+ is_primary_key => 1,
+ is_auto_increment => 1,
+ },
+ audit_change_id => {
+ data_type => 'integer',
+ is_nullable => 0,
+ is_foreign_key => 1,
+ },
+ );
+
+ $class->set_primary_key("audit_history_id");
foreach my $column ( $source->columns ) {
my $info = $source->column_info($column);
$class->belongs_to('change', 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'audit_change_id');
}
-sub new
-{
- my ($self, $data, @rest) = @_;
- my $source = $data->{-result_source};
-
- $data->{change} = {
-# ID => \'DEFAULT',
- changeset_id => $source->schema->current_changeset,
- %{$data->{change}||{}},
- };
-
- $self->next::method($data, @rest);
-}
-
1;