App-Sqitch
view release on metacpan or search on metacpan
lib/App/Sqitch/Engine/pg.pm view on Meta::CPAN
) i(tid, tg, proj, chid, n, name, email, at, pname, pemail)
LEFT JOIN tags ON i.tid = tags.tag_id
WHERE tags.tag_id IS NULL
},
undef,
map { (
$_->id,
$_->format_name,
$proj,
$id,
$_->note,
$user,
$email,
$_->timestamp->as_string(format => 'iso'),
$_->planner_name,
$_->planner_email,
) } @tags
);
return $self;
}
# Override to take advantage of the RETURNING expression, and to save tags as
# an array rather than a space-delimited string.
sub log_revert_change {
my ($self, $change) = @_;
my $dbh = $self->dbh;
# Delete tags.
my $del_tags = $dbh->selectcol_arrayref(
'DELETE FROM tags WHERE change_id = ? RETURNING tag',
undef, $change->id
) || [];
# Retrieve dependencies.
my ($req, $conf) = $dbh->selectrow_array(q{
SELECT ARRAY(
SELECT dependency
FROM dependencies
WHERE change_id = $1
AND type = 'require'
), ARRAY(
SELECT dependency
FROM dependencies
WHERE change_id = $1
AND type = 'conflict'
)
}, undef, $change->id);
# Delete the change record.
$dbh->do(
'DELETE FROM changes where change_id = ?',
undef, $change->id,
);
# Log it.
return $self->_log_event( revert => $change, $del_tags, $req, $conf );
}
sub _dt($) {
require App::Sqitch::DateTime;
return App::Sqitch::DateTime->new(split /:/ => shift);
}
sub _no_table_error {
return 0 unless $DBI::state && $DBI::state eq '42P01'; # undefined_table
my $dbh = shift->dbh;
return 1 unless $dbh->{pg_server_version} >= 90000;
# Try to avoid confusion for people monitoring the Postgres error log by
# sending a warning to the log immediately after the missing relation error
# to tell log watchers that Sqitch is aware of the issue and will next
# initialize the database. Hopefully this will reduce confusion and
# unnecessary time trouble shooting an error that Sqitch handles.
my @msg = map { $dbh->quote($_) } (
__ 'Sqitch registry not initialized',
__ 'Because the "changes" table does not exist, Sqitch will now initialize the database to create its registry tables.',
);
$dbh->do(sprintf q{DO $$
BEGIN
SET LOCAL client_min_messages = 'ERROR';
RAISE WARNING USING ERRCODE = 'undefined_table', MESSAGE = %s, DETAIL = %s;
END;
$$}, @msg);
return 1;
}
# https://www.postgresql.org/docs/current/errcodes-appendix.html
sub _no_column_error {
return $DBI::state && $DBI::state eq '42703'; # undefined_column
}
sub _unique_error {
return $DBI::state && $DBI::state eq '23505'; # unique_violation
}
sub _in_expr {
my ($self, $vals) = @_;
return '= ANY(?)', $vals;
}
sub _run {
my $self = shift;
my $sqitch = $self->sqitch;
my $pass = $self->password or return $sqitch->run( $self->psql, @_ );
local $ENV{PGPASSWORD} = $pass;
return $sqitch->run( $self->psql, @_ );
}
sub _capture {
my $self = shift;
my $sqitch = $self->sqitch;
my $pass = $self->password or return $sqitch->capture( $self->psql, @_ );
local $ENV{PGPASSWORD} = $pass;
return $sqitch->capture( $self->psql, @_ );
}
sub _probe {
my $self = shift;
my $sqitch = $self->sqitch;
my $pass = $self->password or return $sqitch->probe( $self->psql, @_ );
local $ENV{PGPASSWORD} = $pass;
( run in 0.963 second using v1.01-cache-2.11-cpan-99c4e6809bf )