Permalink
Browse files

Allow current_tag_name() to work if no sqitch schema.

  • Loading branch information...
1 parent 4ca27e1 commit aabdac6568154380dc5bf7472d009913d0f85e58 @theory committed May 17, 2012
Showing with 19 additions and 11 deletions.
  1. +17 −11 lib/App/Sqitch/Engine/pg.pm
  2. +2 −0 t/pg.t
@@ -6,6 +6,7 @@ use utf8;
use Path::Class;
use DBI;
use Carp;
+use Try::Tiny;
use App::Sqitch::Plan::Step;
use namespace::autoclean;
@@ -455,17 +456,22 @@ sub check_requires {
sub current_tag_name {
my $dbh = shift->_dbh;
- return $dbh->selectrow_array(q{
- SELECT tag_name
- FROM tag_names
- WHERE tag_id = (
- SELECT tag_id
- FROM tags
- ORDER BY applied_at DESC
- LIMIT 1
- )
- LIMIT 1;
- });
+ return try {
+ $dbh->selectrow_array(q{
+ SELECT tag_name
+ FROM tag_names
+ WHERE tag_id = (
+ SELECT tag_id
+ FROM tags
+ ORDER BY applied_at DESC
+ LIMIT 1
+ )
+ LIMIT 1;
+ });
+ } catch {
+ return if $DBI::state eq '42P01'; # undefined_table
+ die $_;
+ };
}
sub _run {
View
2 t/pg.t
@@ -237,6 +237,8 @@ subtest 'live database' => sub {
sqitch_schema => '__sqitchtest',
), 'Create a pg with postgres user and __sqitchtest schema';
+ is $pg->current_tag_name, undef, 'No init, no current tag';
+
ok !$pg->initialized, 'Database should no longer seem initialized';
push @cleanup, 'DROP SCHEMA __sqitchtest CASCADE';
ok $pg->initialize, 'Initialize the database again';

0 comments on commit aabdac6

Please sign in to comment.