$self->_journal_schema->deploy( $sqlt_args, @args );
}
-sub get_audit_log_class_name
-{
- my ($self, $sourcename) = @_;
-
- return blessed($self->_journal_schema) . "::${sourcename}AuditLog";
-}
-
-sub get_audit_history_class_name
-{
- my ($self, $sourcename) = @_;
-
- return blessed($self->_journal_schema) . "::${sourcename}AuditHistory";
-}
-
sub create_journal_for
{
my ($self, $s_name) = @_;
my $source = $self->source($s_name);
- my $logclass = $self->get_audit_log_class_name($s_name);
-
- DBIx::Class::Componentised->inject_base($logclass, 'DBIx::Class::Schema::Journal::DB::AuditLog');
- $logclass->journal_define_table($source);
- my $log_source = "${s_name}AuditLog";
- $self->_journal_schema->register_class($log_source, $logclass);
-
+ foreach my $audit (qw(AuditLog AuditHistory)) {
+ my $audit_source = join("", $s_name, $audit);
+ my $class = blessed($self->_journal_schema) . "::$audit_source";
- my $histclass = $self->get_audit_history_class_name($s_name);
- DBIx::Class::Componentised->inject_base($histclass, 'DBIx::Class::Schema::Journal::DB::AuditHistory');
- $histclass->table(lc($s_name) . "_audit_history");
-# $histclass->result_source_instance->name(lc($s_name) . "_audit_hisory");
+ DBIx::Class::Componentised->inject_base($class, "DBIx::Class::Schema::Journal::DB::$audit");
- foreach my $column ( $source->columns ) {
- my $info = $source->column_info($column);
+ $class->journal_define_table($source);
- 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;
-
- $histclass->add_column($column => \%hist_info);
+ $self->_journal_schema->register_class($audit_source, $class);
}
-
- my $hist_source = "${s_name}AuditHistory";
- $self->_journal_schema->register_class($hist_source, $histclass);
-
- return ( $log_source, $hist_source );
}
sub txn_do
__PACKAGE__->mk_group_accessors( simple => 'current_session' );
__PACKAGE__->mk_group_accessors( simple => '_current_changeset_container' );
-DBIx::Class::Schema::Journal::DB->load_classes(qw/
- ChangeSet
- ChangeLog
- AuditHistory
- /);
+DBIx::Class::Schema::Journal::DB->load_classes(qw(ChangeSet ChangeLog));
require DBIx::Class::Schema::Journal::DB::AuditLog;
+require DBIx::Class::Schema::Journal::DB::AuditHistory;
sub _current_changeset {
my $self = shift;
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
{
$class->load_components(qw(Core));
- $class->table($source->name . "_audit_log");
+ $class->table($source->name . "_audit_history");
$class->add_columns(
create_id => {
+++ /dev/null
-package DBIx::Class::Schema::Journal::DB::Base;
-
-use base 'DBIx::Class';
-
-__PACKAGE__->load_components(qw/Core/);
-__PACKAGE__->table('dummy');
-
-
-1;
isa_ok($schema->_journal_schema->source('ArtistAuditLog'), 'DBIx::Class::ResultSource', 'ArtistAuditLog source exists');
my $count = eval {
- $schema->_journal_schema->resultset('ArtistAuditLog')->count;
+ $schema->_journal_schema->resultset('ArtistAuditHistory')->count;
};
my $e = $@;
$schema->journal_schema_deploy();
-$count = eval { $schema->_journal_schema->resultset('ArtistAuditLog')->count };
+$count = eval { $schema->_journal_schema->resultset('ArtistAuditHistory')->count };
is( $@, '', "no error" );
is( $count, 0, "count is 0" );