6 eval "use DBD::SQLite; use SQL::Translator";
8 ? ( skip_all => 'needs DBD::SQLite and SQL::Translator for testing' )
15 # connect to db and deploy only the original db schema, not journal schema
16 my $schema = DBICTest->init_schema(no_populate => 1, no_deploy => 1);
18 ok($schema, 'Created a Schema');
21 # check we have no journal
23 $schema->_journal_schema->resultset('ChangeLog')->count;
27 is( $count, undef, 'no count' );
28 like( $e, qr/table.*changelog/, 'missing table error' );
30 # insert two rows -not- in txn
31 my ($artistA, $artistB);
32 #$schema->txn_do(sub {
33 $artistA = $schema->resultset('Artist')->create({
34 name => 'Fred Bloggs A',
37 $artistB = $schema->resultset('Artist')->create({
38 name => 'Fred Bloggs B',
43 $schema->journal_schema_deploy();
46 $count = eval { $schema->_journal_schema->resultset('ChangeLog')->count };
48 is( $@, '', "no error" );
49 is( $count, 0, "count is 0 (changelog)" );
52 $schema->prepopulate_journal();
54 # check there is only one changeset
55 $count = eval { $schema->_journal_schema->resultset('ChangeSet')->count };
57 is( $@, '', "no error" );
58 is( $count, 1, "count is 1 (changeset)" );
60 # check it contains two inserts
61 $count = eval { $schema->_journal_schema->resultset('ChangeLog')->count };
63 is( $@, '', "no error" );
64 is( $count, 2, "count is 2 (changelog)" );
66 # check audit log has two rows for two inserts
67 $count = eval { $schema->_journal_schema->resultset('ArtistAuditLog')->count };
69 is( $@, '', "no error" );
70 is( $count, 2, "count is 2 (auditlog)" );
74 my $deleted = $schema->txn_do(sub {
79 is( $@, '', "no error from deletion journal (create_id not null)" );
80 is( $artistA->in_storage, 0, "row was deleted" );
82 # check journal log still has two rows
83 $count = eval { $schema->_journal_schema->resultset('ArtistAuditLog')->count };
85 is( $@, '', "no error" );
86 is( $count, 2, "count is 2 (auditlog 2)" );
88 # and that one of them has a delete_id
90 $schema->_journal_schema->resultset('ArtistAuditLog')
92 artistid => $artistA->id,
93 delete_id => { '-not' => undef }
97 is( $@, '', "no error" );
98 is( $count, 1, "count is 1 (delete_id)" );