[Bast-commits] r9253 - in
DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class: . Schema
oliver at dev.catalyst.perl.org
oliver at dev.catalyst.perl.org
Wed Apr 28 00:20:38 GMT 2010
Author: oliver
Date: 2010-04-28 01:20:38 +0100 (Wed, 28 Apr 2010)
New Revision: 9253
Modified:
DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Journal.pm
DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Schema/Journal.pm
Log:
add bootstrap_journal to make things simpler, and also make prepopulate_journal to be idempotent
Modified: DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Journal.pm
===================================================================
--- DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Journal.pm 2010-04-27 23:40:32 UTC (rev 9252)
+++ DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Journal.pm 2010-04-28 00:20:38 UTC (rev 9253)
@@ -84,7 +84,7 @@
__PACKAGE__->load_components(qw/Schema::Journal/);
-And then call C<< $schema->journal_schema_deploy >> to create all the tables
+And then call C<< $schema->bootstrap_journal >> to create all the tables
necessary for the journal, in your database.
Optionally set where the journal is stored:
@@ -240,6 +240,12 @@
=over 4
+=item bootstrap_journal
+
+This calls C<journal_schema_deploy> followed by C<prepopulate_journal> to
+create your journal tables and if necessary populate them with a snapshot of
+your current original schema data.
+
=item journal_schema_deploy
Will use L<DBIx::Class::Schema/deploy> to set up the tables for journalling in
Modified: DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Schema/Journal.pm
===================================================================
--- DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Schema/Journal.pm 2010-04-27 23:40:32 UTC (rev 9252)
+++ DBIx-Class-Journal/1.000/trunk/lib/DBIx/Class/Schema/Journal.pm 2010-04-28 00:20:38 UTC (rev 9253)
@@ -138,19 +138,30 @@
}
}
+# XXX FIXME deploy is not idempotenta :-(
+sub bootstrap_journal {
+ my $self = shift;
+ $self->journal_schema_deploy;
+ $self->prepopulate_journal;
+}
+
+# copy data from original schema sources into the journal as inserts in one
+# changeset, so that later deletes will not fail to be journalled.
sub prepopulate_journal {
my $self = shift;
+ my $schema = $self;
- my %j_sources = map { $_ => 1 } $self->journal_sources
- ? @{$self->journal_sources}
- : $self->sources;
+ # woah, looks like prepopulate has already run?
+ return if $schema->_journal_schema->resultset('ChangeSet')->count != 0;
- my $schema = $self;
- my $j_schema = $self->_journal_schema;
- my $changelog_rs = $j_schema->resultset('ChangeLog');
-
# using our own overridden txn_do (see below) will create a changeset
$schema->txn_do( sub {
+ my %j_sources = map { $_ => 1 } $self->journal_sources
+ ? @{$self->journal_sources}
+ : $self->sources;
+
+ my $j_schema = $self->_journal_schema;
+ my $changelog_rs = $j_schema->resultset('ChangeLog');
my $chs_id = $j_schema->current_changeset;
foreach my $s_name ($self->sources) {
More information about the Bast-commits
mailing list