App-Sqitch
view release on metacpan or search on metacpan
lib/App/Sqitch/Engine/exasol.pm view on Meta::CPAN
sub _limit_default { '18446744073709551611' }
sub _simple_from { ' FROM dual' }
sub _multi_values {
my ($self, $count, $expr) = @_;
return join "\nUNION ALL ", ("SELECT $expr FROM dual") x $count;
}
sub _initialized {
my $self = shift;
return $self->dbh->selectcol_arrayref(q{
SELECT EXISTS(
SELECT TRUE FROM exa_all_tables
WHERE table_schema = ? AND table_name = ?
)
}, undef, uc $self->registry, 'CHANGES')->[0];
}
# LIMIT / OFFSET in Exasol doesn't seem to play nice in the original query with
# JOIN and GROUP BY; wrap it in a subquery instead..
sub change_offset_from_id {
my ( $self, $change_id, $offset ) = @_;
# Just return the object if there is no offset.
return $self->load_change($change_id) unless $offset;
# Are we offset forwards or backwards?
my ($dir, $op, $offset_expr) = $self->_offset_op($offset);
my $tscol = sprintf $self->_ts2char_format, 'c.planned_at';
my $tagcol = sprintf $self->_listagg_format, 't.tag';
my $change = $self->dbh->selectrow_hashref(qq{
SELECT id, name, project, note, "timestamp", planner_name, planner_email,
tags, script_hash
FROM (
SELECT c.change_id AS id, c.change AS name, c.project, c.note,
$tscol AS "timestamp", c.planner_name, c.planner_email,
$tagcol AS tags, c.committed_at, c.script_hash
FROM changes c
LEFT JOIN tags t ON c.change_id = t.change_id
WHERE c.project = ?
AND c.committed_at $op (
SELECT committed_at FROM changes WHERE change_id = ?
)
GROUP BY c.change_id, c.change, c.project, c.note, c.planned_at,
c.planner_name, c.planner_email, c.committed_at, c.script_hash
) changes
ORDER BY changes.committed_at $dir
LIMIT 1 $offset_expr
}, undef, $self->plan->project, $change_id) || return undef;
$change->{timestamp} = _dt $change->{timestamp};
unless (ref $change->{tags}) {
$change->{tags} = $change->{tags} ? [ split / / => $change->{tags} ] : [];
}
return $change;
}
sub changes_requiring_change {
my ( $self, $change ) = @_;
# Why CTE: https://forums.oracle.com/forums/thread.jspa?threadID=1005221
# NOTE: Query from DBIEngine doesn't work in Exasol:
# Error: [00444] more than one column in select list of correlated subselect
# The CTE-based query below seems to be fine, however.
return @{ $self->dbh->selectall_arrayref(q{
WITH tag AS (
SELECT tag, committed_at, project,
ROW_NUMBER() OVER (partition by project ORDER BY committed_at) AS rnk
FROM tags
)
SELECT c.change_id, c.project, c.change, t.tag AS asof_tag
FROM dependencies d
JOIN changes c ON c.change_id = d.change_id
LEFT JOIN tag t ON t.project = c.project AND t.committed_at >= c.committed_at
WHERE d.dependency_id = ?
AND (t.rnk IS NULL OR t.rnk = 1)
}, { Slice => {} }, $change->id) };
}
sub name_for_change_id {
my ( $self, $change_id ) = @_;
# Why CTE: https://forums.oracle.com/forums/thread.jspa?threadID=1005221
# NOTE: Query from DBIEngine doesn't work in Exasol:
# Error: [0A000] Feature not supported: non-equality correlations in correlated subselect
# The CTE-based query below seems to be fine, however.
return $self->dbh->selectcol_arrayref(q{
WITH tag AS (
SELECT tag, committed_at, project,
ROW_NUMBER() OVER (partition by project ORDER BY committed_at) AS rnk
FROM tags
)
SELECT change || COALESCE(t.tag, '@HEAD')
FROM changes c
LEFT JOIN tag t ON c.project = t.project AND t.committed_at >= c.committed_at
WHERE change_id = ?
AND (t.rnk IS NULL OR t.rnk = 1)
}, undef, $change_id)->[0];
}
sub _cid {
my ( $self, $ord, $offset, $project ) = @_;
my $offset_expr = $offset ? " OFFSET $offset" : '';
return try {
$self->dbh->selectcol_arrayref(qq{
SELECT change_id
FROM changes
WHERE project = ?
ORDER BY committed_at $ord
LIMIT 1$offset_expr
}, undef, $project || $self->plan->project)->[0];
} catch {
return if $self->_no_table_error && !$self->initialized;
die $_;
};
}
sub is_deployed_tag {
my ( $self, $tag ) = @_;
return $self->dbh->selectcol_arrayref(
'SELECT 1 FROM tags WHERE tag_id = ?',
undef, $tag->id
)->[0];
}
sub _registry_variable {
my $self = shift;
my $schema = $self->registry;
return "DEFINE registry=$schema;";
}
sub _initialize {
my $self = shift;
my $schema = $self->registry;
hurl engine => __ 'Sqitch already initialized' if $self->initialized;
# Load up our database.
(my $file = file(__FILE__)->dir->file('exasol.sql')) =~ s/"/""/g;
$self->_run_with_verbosity($file);
$self->dbh->do("OPEN SCHEMA $schema") if $schema;
$self->_register_release;
}
( run in 1.040 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )