remove Base
[dbsrgits/DBIx-Class-Journal.git] / lib / DBIx / Class / Schema / Journal / DB / AuditHistory.pm
index bfa8fba..706addd 100644 (file)
@@ -1,14 +1,41 @@
 package DBIx::Class::Schema::Journal::DB::AuditHistory;
 
-use base 'DBIx::Class::Schema::Journal::DB::Base';
-__PACKAGE__->table(__PACKAGE__->table);
-
-__PACKAGE__->add_columns(
-                           audit_change_id => {
-                               data_type => 'integer',
-                               is_nullable => 0,
-                           });
-__PACKAGE__->belongs_to('change', 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'audit_change_id');
+use base 'DBIx::Class';
+
+sub journal_define_table {
+    my ( $class, $source ) = @_;
+
+    $class->load_components(qw(Core));
+
+    $class->table($source->name . "_audit_log");
+    
+    $class->add_column( audit_change_id => {
+        data_type => 'integer',
+        is_nullable => 0,
+        is_primary_key => 1,
+    });
+
+    $class->set_primary_key("audit_change_id");
+
+    foreach my $column ( $source->columns ) {
+        my $info = $source->column_info($column);
+
+        my %hist_info = %$info;
+
+        delete $hist_info{$_} for qw(
+            is_foreign_key
+            is_primary_key
+            is_auto_increment
+            default_value
+        );
+        
+        $hist_info{is_nullable} = 1;
+
+        $class->add_column($column => \%hist_info);
+    }
+                           
+    $class->belongs_to('change', 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'audit_change_id');
+}
 
 sub new
 {