[Bast-commits] r4680 - in trunk/DBIx-Class-Journal: lib/DBIx/Class
lib/DBIx/Class/Schema lib/DBIx/Class/Schema/Journal
lib/DBIx/Class/Schema/Journal/DB t
nothingmuch at dev.catalyst.perl.org
nothingmuch at dev.catalyst.perl.org
Wed Jul 30 05:53:28 BST 2008
Author: nothingmuch
Date: 2008-07-30 05:53:27 +0100 (Wed, 30 Jul 2008)
New Revision: 4680
Modified:
trunk/DBIx-Class-Journal/lib/DBIx/Class/Journal.pm
trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal.pm
trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB.pm
trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm
trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm
trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/ChangeLog.pm
trunk/DBIx-Class-Journal/t/01test.t
Log:
multi column PK support
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Journal.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Journal.pm 2008-07-30 03:56:05 UTC (rev 4679)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Journal.pm 2008-07-30 04:53:27 UTC (rev 4680)
@@ -29,17 +29,9 @@
{
my $s_name = $self->result_source->source_name();
my $al = $self->result_source->schema->_journal_schema->resultset("${s_name}AuditLog");
- my ($pri, $too_many) = map { $self->get_column($_)} $self->primary_columns;
- if(defined $pri && defined $too_many)
- {
- $self->throw_exception( "More than one possible key found for auto-inc on ".ref $self );
- }
- $pri ||= \'NULL'; #'
- $al->create({
- ID => $pri,
-# created => {
-# changeset => $self->result_source->schema->_journal_schema->current_changeset(),
-# },
+ $al->update_or_create({
+ ( map { $_ => $self->get_column($_)} $self->primary_columns ),
+ created => { changeset_id => $al->result_source->schema->current_changeset },
});
}
@@ -57,22 +49,12 @@
{
my $s_name = $self->result_source->source_name();
my $al = $self->result_source->schema->_journal_schema->resultset("${s_name}AuditLog");
- my ($pri, $too_many) = map { $self->get_column($_)} $self->primary_columns;
- if(defined $pri && defined $too_many)
- {
- $self->throw_exception( "More than one possible key found for auto-inc on ".ref $self );
- }
-
- if($pri)
- {
- my $alentry = $al->find({ID => $pri});
- $self->throw_exception( "No audit_log entry found for ".ref($self) . " item $pri" ) if(!$alentry);
-
- ## bulk_update doesnt do "create new item on update of rel-accessor with hashref, yet
- my $change = $self->result_source->schema->_journal_schema->resultset('ChangeLog')->create({ changeset_id => $self->result_source->schema->_journal_schema->current_changeset });
- $alentry->delete_id($change->id);
- $alentry->update();
- }
+ my $alentry = $al->find_or_create({ map { $_ => $self->get_column($_)} $self->primary_columns });
+
+ ## bulk_update doesnt do "create new item on update of rel-accessor with hashref, yet
+ my $change = $self->result_source->schema->_journal_schema->resultset('ChangeLog')->create({ changeset_id => $self->result_source->schema->_journal_schema->current_changeset });
+ $alentry->delete_id($change->id);
+ $alentry->update();
}
}
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm 2008-07-30 03:56:05 UTC (rev 4679)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm 2008-07-30 04:53:27 UTC (rev 4680)
@@ -4,11 +4,11 @@
__PACKAGE__->table(__PACKAGE__->table);
__PACKAGE__->add_columns(
- change_id => {
+ audit_change_id => {
data_type => 'integer',
is_nullable => 0,
});
-__PACKAGE__->belongs_to('change', 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'change_id');
+__PACKAGE__->belongs_to('change', 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'audit_change_id');
sub new
{
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm 2008-07-30 03:56:05 UTC (rev 4679)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm 2008-07-30 04:53:27 UTC (rev 4680)
@@ -1,42 +1,35 @@
package DBIx::Class::Schema::Journal::DB::AuditLog;
-use base 'DBIx::Class::Schema::Journal::DB::Base';
-__PACKAGE__->table(__PACKAGE__->table);
+use base 'DBIx::Class';
-__PACKAGE__->add_columns(
- ID => {
- data_type => 'integer',
-# is_auto_increment => 1,
- 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__->set_primary_key('ID');
+sub journal_define_table {
+ my ( $class, $source ) = @_;
- __PACKAGE__->belongs_to('created', 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'create_id');
- __PACKAGE__->belongs_to('deleted', 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'delete_id');
+ $class->load_components(qw(Core));
-sub new
-{
- my ($self, $data, @rest) = @_;
- my $source = $data->{-result_source};
+ $class->table($source->name . "_audit_log");
- $data->{created} = {
-# ID => \'DEFAULT',
-# ID => 1,
- changeset_id => $source->schema->current_changeset,
- %{$data->{created}||{}},
- };
+ $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,
+ }
+ );
- $self->next::method($data, @rest);
-}
+ 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;
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/ChangeLog.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/ChangeLog.pm 2008-07-30 03:56:05 UTC (rev 4679)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/ChangeLog.pm 2008-07-30 04:53:27 UTC (rev 4680)
@@ -4,7 +4,7 @@
# __PACKAGE__->load_components(qw/Core/);
__PACKAGE__->load_components(qw/Ordered Core/);
-__PACKAGE__->table('change_log');
+__PACKAGE__->table('changelog');
__PACKAGE__->add_columns(
ID => {
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB.pm 2008-07-30 03:56:05 UTC (rev 4679)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB.pm 2008-07-30 04:53:27 UTC (rev 4680)
@@ -10,10 +10,10 @@
DBIx::Class::Schema::Journal::DB->load_classes(qw/
ChangeSet
ChangeLog
- AuditLog
AuditHistory
/);
+require DBIx::Class::Schema::Journal::DB::AuditLog;
sub _current_changeset {
my $self = shift;
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal.pm 2008-07-30 03:56:05 UTC (rev 4679)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal.pm 2008-07-30 04:53:27 UTC (rev 4680)
@@ -131,11 +131,13 @@
my ($self, $s_name) = @_;
my $source = $self->source($s_name);
- my $newclass = $self->get_audit_log_class_name($s_name);
- DBIx::Class::Componentised->inject_base($newclass, 'DBIx::Class::Schema::Journal::DB::AuditLog');
- $newclass->table(lc($s_name) . "_audit_log");
+ 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, $newclass);
+ $self->_journal_schema->register_class($log_source, $logclass);
my $histclass = $self->get_audit_history_class_name($s_name);
Modified: trunk/DBIx-Class-Journal/t/01test.t
===================================================================
--- trunk/DBIx-Class-Journal/t/01test.t 2008-07-30 03:56:05 UTC (rev 4679)
+++ trunk/DBIx-Class-Journal/t/01test.t 2008-07-30 04:53:27 UTC (rev 4680)
@@ -68,7 +68,7 @@
$new_cd->delete;
} );
-my $alentry = $search->find({ ID => $new_cd->get_column($new_cd->primary_columns) });
+my $alentry = $search->find({ map { $_ => $new_cd->get_column($_) } $new_cd->primary_columns });
ok(defined($alentry->deleted), 'Deleted set in audit_log');
$schema->changeset_user(1);
More information about the Bast-commits
mailing list