1 package DBIx::Class::Schema::Journal;
3 use base qw/DBIx::Class/;
5 __PACKAGE__->mk_classdata('journal_dsn');
6 __PACKAGE__->mk_classdata('journal_sources'); ## [ source names ]
7 __PACKAGE__->mk_classdata('journal_user'); ## [ class, field for user id ]
8 __PACKAGE__->mk_classdata('_journal_schema');
13 $self->next::method(@_);
15 $self->_journal_schema((__PACKAGE__ . '::DB')->connect($self->journal_dsn || $self->storage->connect_info));
17 my %j_sources = @{$self->journal_sources} ? map { $_ => 1 } @{$self->journal_sources} : map { $_ => 1 } $self->sources;
18 foreach my $s_name ($self->sources)
20 next unless($j_sources{$s_name});
21 $self->create_journal_for($s_name);
24 ## Set up relationship between changeset->user_id and this schema's user
25 if(!@{$self->journal_user})
27 warn "No Journal User set!";
31 DBIx::Class::Schema::Journal::DB::ChangeSet->belongs_to('user', @{$self->journal_user});
34 sub get_audit_log_class_name
36 my ($self, $sourcename) = @_;
38 return __PACKAGE__ . "::DB::${sourcename}AuditLog";
41 sub get_audit_history_class_name
43 my ($self, $sourcename) = @_;
45 return __PACKAGE__ . "::DB::${sourcename}AuditHistory";
48 sub create_journal_for
50 my ($self, $s_name) = @_;
52 my $source = $self->source($s_name);
53 my $newclass = $self->get_audit_log_class_name($s_name);
54 DBIx::Class::Componentised->inject_base($newclass, 'DBIx::Class');
55 $newclass->load_components('Core');
56 $newclass->table(lc($s_name) . "_audit_log");
57 $newclass->add_columns(
59 data_type => 'integer',
63 data_type => 'integer',
67 data_type => 'integer',
70 $newclass->belongs_to('created', 'DBIx::Class::Schema::Journal::DB::Change', 'create_id');
71 $newclass->belongs_to('deleted', 'DBIx::Class::Schema::Journal::DB::Change', 'delete_id');
74 my $histclass = $self->get_audit_hisory_class_name($s_name);
75 DBIx::Class::Componentised->inject_base($histclass, 'DBIx::Class');
76 $histclass->load_components('Core');
77 $histclass->table(lc($s_name) . "_audit_hisory");
78 $histclass->add_columns(
80 data_type => 'integer',
83 map { $_ => $source->column_info($_) } $source->columns
85 $histclass->belongs_to('change', 'DBIx::Class::Schema::Journal::DB::Change', 'change_id');