From: Yuval Kogman Date: Wed, 30 Jul 2008 06:09:01 +0000 (+0000) Subject: more cleanup X-Git-Tag: v0.900201~79 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=41daf59034b89e67e6071e0e6a30fb1bb4a2e2f7;p=dbsrgits%2FDBIx-Class-Journal.git more cleanup --- diff --git a/lib/DBIx/Class/Journal.pm b/lib/DBIx/Class/Journal.pm index 4130baa..d2fb599 100644 --- a/lib/DBIx/Class/Journal.pm +++ b/lib/DBIx/Class/Journal.pm @@ -72,8 +72,9 @@ sub 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); @@ -135,10 +136,10 @@ session_id, and a set_date which defaults to the current datetime. 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. @@ -155,7 +156,7 @@ created or deleted this row. 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. diff --git a/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm b/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm index 706addd..708ab40 100644 --- a/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm +++ b/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm @@ -7,15 +7,23 @@ sub journal_define_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); @@ -37,18 +45,4 @@ sub journal_define_table { $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; diff --git a/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm b/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm index ec9d2e0..83a1a90 100644 --- a/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm +++ b/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm @@ -7,7 +7,7 @@ sub journal_define_table { $class->load_components(qw(Core)); - $class->table($source->name . "_audit_history"); + $class->table($source->name . "_audit_log"); $class->add_columns( create_id => {