X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FJournal%2FDB%2FAuditLog.pm;h=5498d0f44a8eec6ef75687ca579cd4d3d35c6f30;hb=34b144a0d087a0e609852ab05c59be751db0d530;hp=0d410a7e0fae9fe3cf9b2428e5cb7a8b0f8067dd;hpb=f3602465158d8b081b05f992d2871beaa5fc9f9c;p=dbsrgits%2FDBIx-Class-Journal.git diff --git a/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm b/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm index 0d410a7..5498d0f 100644 --- a/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm +++ b/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm @@ -1,37 +1,33 @@ package DBIx::Class::Schema::Journal::DB::AuditLog; -use base 'DBIx::Class::Schema::Journal::DB::Base'; -__PACKAGE__->table(__PACKAGE__->table); - -__PACKAGE__->add_columns( - ID => { - data_type => 'integer', - is_nullable => 0, - }, - create_id => { - data_type => 'integer', - is_nullable => 0, - is_foreign_key => 1, - }, - delete_id => { - data_type => 'integer', - is_nullable => 1, - is_foreign_key => 1, - }); - __PACKAGE__->belongs_to('created', 'DBIx::Class::Schema::Journal::DB::Change', 'create_id'); - __PACKAGE__->belongs_to('deleted', 'DBIx::Class::Schema::Journal::DB::Change', 'delete_id'); - -sub new -{ - my ($self, $data, $source, @rest) = @_; - - $data->{created} = { -# ID => \'DEFAULT', - changeset_id => $source->schema->current_changeset, - %{$data->{created}}, - }; - - $self->next::method($data, $source, @rest); -} +use base 'DBIx::Class::Core'; + +sub journal_define_table { + my ( $class, $source ) = @_; + + $class->table($source->name . '_audit_log'); + + $class->add_columns( + create_id => { + data_type => 'integer', + is_nullable => 0, + is_foreign_key => 1, + }, + delete_id => { + data_type => 'integer', + is_nullable => 1, + is_foreign_key => 1, + } + ); + + foreach my $column ( $source->primary_columns ) { + $class->add_column( $column => { %{ $source->column_info($column) } } ); + } + + $class->set_primary_key( $source->primary_columns ); + + $class->belongs_to(created => 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'create_id'); + $class->belongs_to(deleted => 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'delete_id'); +} 1;