From: Jess Robinson Date: Wed, 9 May 2007 22:02:07 +0000 (+0000) Subject: Yay, test passes! X-Git-Tag: v0.900201~104 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8092c4ed6087b0f0beca5d3d7c7288db1604551d;p=dbsrgits%2FDBIx-Class-Journal.git Yay, test passes! --- diff --git a/lib/DBIx/Class/Journal.pm b/lib/DBIx/Class/Journal.pm index 231f8ba..623cfe0 100644 --- a/lib/DBIx/Class/Journal.pm +++ b/lib/DBIx/Class/Journal.pm @@ -22,9 +22,15 @@ sub insert if($self->in_storage) { my $s_name = $self->result_source->source_name(); - print STDERR "Schema: ", ref($self->result_source->schema), "\n"; 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(), # }, diff --git a/lib/DBIx/Class/Schema/Journal.pm b/lib/DBIx/Class/Schema/Journal.pm index ea342f2..634f96e 100644 --- a/lib/DBIx/Class/Schema/Journal.pm +++ b/lib/DBIx/Class/Schema/Journal.pm @@ -18,7 +18,7 @@ sub throw_exception sub exception_action { my $self = shift; - print STDERR Carp::longmess; +# print STDERR Carp::longmess; $self->next::method(@_); } @@ -28,7 +28,7 @@ sub connection my $self = shift; $self->next::method(@_); - print STDERR join(":", $self->sources), "\n"; +# print STDERR join(":", $self->sources), "\n"; my $journal_schema = DBIx::Class::Schema::Journal::DB->connect(@{ $self->journal_connection || $self->storage->connect_info }); # print STDERR "conn", $journal_schema->storage->connect_info; @@ -104,6 +104,8 @@ sub txn_do ## Create a new changeset, then run $code as a transaction my $cs = $self->_journal_schema->resultset('ChangeSet'); + + $self->txn_begin; my $changeset = $cs->create({ ( $self->_journal_schema->current_user() ? ( user_id => $self->_journal_schema->current_user()) : () ), # user_id => $self->_journal_schema->current_user(), session_id => $self->_journal_schema->current_session(), diff --git a/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm b/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm index 12898e1..f1d65c6 100644 --- a/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm +++ b/lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm @@ -13,6 +13,7 @@ __PACKAGE__->belongs_to('change', 'DBIx::Class::Schema::Journal::DB::Change', 'c sub new { my ($self, $data, @rest) = @_; + my $source = $data->{-result_source}; $data->{change} = { # ID => \'DEFAULT', diff --git a/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm b/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm index 0d410a7..879c47d 100644 --- a/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm +++ b/lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm @@ -6,6 +6,7 @@ __PACKAGE__->table(__PACKAGE__->table); __PACKAGE__->add_columns( ID => { data_type => 'integer', +# is_auto_increment => 1, is_nullable => 0, }, create_id => { @@ -23,15 +24,17 @@ __PACKAGE__->add_columns( sub new { - my ($self, $data, $source, @rest) = @_; + my ($self, $data, @rest) = @_; + my $source = $data->{-result_source}; $data->{created} = { # ID => \'DEFAULT', +# ID => 1, changeset_id => $source->schema->current_changeset, %{$data->{created}}, }; - $self->next::method($data, $source, @rest); + $self->next::method($data, @rest); } 1; diff --git a/lib/DBIx/Class/Schema/Journal/DB/Change.pm b/lib/DBIx/Class/Schema/Journal/DB/Change.pm index f5c5dc1..519973a 100644 --- a/lib/DBIx/Class/Schema/Journal/DB/Change.pm +++ b/lib/DBIx/Class/Schema/Journal/DB/Change.pm @@ -2,6 +2,7 @@ package DBIx::Class::Schema::Journal::DB::Change; use base 'DBIx::Class'; +# __PACKAGE__->load_components(qw/Core/); __PACKAGE__->load_components(qw/Ordered Core/); __PACKAGE__->table('change'); @@ -28,6 +29,6 @@ __PACKAGE__->set_primary_key('ID'); __PACKAGE__->add_unique_constraint('setorder', [ qw/changeset_id order_in/ ]); __PACKAGE__->belongs_to('changeset', 'DBIx::Class::Schema::Journal::DB::ChangeSet', 'changeset_id'); -__PACKAGE__->position_column('order_in'); -__PACKAGE__->grouping_column('changeset_id'); + __PACKAGE__->position_column('order_in'); + __PACKAGE__->grouping_column('changeset_id'); 1;