use strict;
use warnings;
-our $VERSION = '0.02';
+our $VERSION = '0.02_01';
## On create/insert, add new entry to AuditLog
{
my $s_name = $self->result_source->source_name();
my $al = $self->result_source->schema->_journal_schema->resultset("${s_name}AuditLog");
- my ($pri, $too_many) = map { $self->get_column($_)} $self->primary_columns;
- if(defined $pri && defined $too_many)
- {
- $self->throw_exception( "More than one possible key found for auto-inc on ".ref $self );
- }
- $pri ||= \'NULL'; #'
- $al->create({
- ID => $pri,
-# created => {
-# changeset => $self->result_source->schema->_journal_schema->current_changeset(),
-# },
+ $al->update_or_create({
+ ( map { $_ => $self->get_column($_)} $self->primary_columns ),
+ created => { changeset_id => $al->result_source->schema->current_changeset },
});
}
{
my $s_name = $self->result_source->source_name();
my $al = $self->result_source->schema->_journal_schema->resultset("${s_name}AuditLog");
- my ($pri, $too_many) = map { $self->get_column($_)} $self->primary_columns;
- if(defined $pri && defined $too_many)
- {
- $self->throw_exception( "More than one possible key found for auto-inc on ".ref $self );
- }
-
- if($pri)
- {
- my $alentry = $al->find({ID => $pri});
- $self->throw_exception( "No audit_log entry found for ".ref($self) . " item $pri" ) if(!$alentry);
-
- ## bulk_update doesnt do "create new item on update of rel-accessor with hashref, yet
- my $change = $self->result_source->schema->_journal_schema->resultset('ChangeLog')->create({ changeset_id => $self->result_source->schema->_journal_schema->current_changeset });
- $alentry->delete_id($change->id);
- $alentry->update();
- }
+ my $alentry = $al->find_or_create({ map { $_ => $self->get_column($_)} $self->primary_columns });
+
+ ## bulk_update doesnt do "create new item on update of rel-accessor with hashref, yet
+ my $change = $self->result_source->schema->_journal_schema->resultset('ChangeLog')->create({ changeset_id => $self->result_source->schema->_journal_schema->current_changeset });
+ $alentry->delete_id($change->id);
+ $alentry->update();
}
}
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.
=item Arguments: \@connect_info
-=back
-
Set the connection information for the database to save your audit
information to. Leaving this blank assumes you want to store the audit
data into your current database.
-=over
-
=item journal_sources
=item Arguments: \@source_names
-=back
-
Set a list of source names you would like to audit, if unset, all
sources are used.
NOTE: Currently only sources with a single-column PK are supported, so
use this method if you have sources with multi-column PKs.
-=over
-
=item journal_storage_type
=item Arguments: $storage_type
-=back
-
Enter the special storage type of your journal schema if needed. See
L<DBIx::Class::Storage::DBI> for more information on storage types.
-=over
-
=item journal_user
=item Arguments: \@relation_args
-=back
-
The user_id column in the L</ChangeSet> will be linked to your user id
with a belongs_to relation, if this is set with the appropriate
arguments.
-=over
-
=item changeset_user
=item Arguments: $user_id
-=back
-
Set the user_id for the following changeset(s). This must be an integer.
-=over
-
=item changeset_session
=item Arguments: $user_id
-=back
-
Set the session_id for the following changeset(s). This must be an integer.
-=over
-
=item txn_do
-=iitem Arguments: $code_ref
+=item Arguments: $code_ref
=back
an audited table will use the changeset_id created in the most recent
txn_do call.
+=back
+
=head1 SEE ALSO
L<DBIx::Class> - You'll need it to use this.