__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:
=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
}
}
-sub prepopulate_journal {
+# XXX FIXME deploy is not idempotenta :-(
+sub bootstrap_journal {
my $self = shift;
+ $self->journal_schema_deploy;
+ $self->prepopulate_journal;
+}
- my %j_sources = map { $_ => 1 } $self->journal_sources
- ? @{$self->journal_sources}
- : $self->sources;
-
+# 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_schema = $self->_journal_schema;
- my $changelog_rs = $j_schema->resultset('ChangeLog');
+
+ # woah, looks like prepopulate has already run?
+ return if $schema->_journal_schema->resultset('ChangeSet')->count != 0;
# 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) {