Skip to content

Commit 02ff5d8

Browse files
authored
Dependency postgres support (#1127)
2 parents 1eb1e72 + c42d469 commit 02ff5d8

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

library/Icingadb/Model/DependencyNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public function getColumns(): array
5656
['service.display_name', 'host.display_name', 'redundancy_group.display_name']
5757
),
5858
'severity' => new Expression(
59-
'COALESCE(%s, %s, %s)',
59+
"COALESCE(%s, %s, CASE WHEN %s = 'y' THEN 1 ELSE 0 END)",
6060
['service.state.severity', 'host.state.severity', 'redundancy_group.state.failed']
6161
),
6262
'state' => new Expression(
63-
'COALESCE(%s, %s, %s)',
63+
"COALESCE(%s, %s, CASE WHEN %s = 'y' THEN 1 ELSE 0 END)",
6464
['service.state.soft_state', 'host.state.soft_state', 'redundancy_group.state.failed']
6565
),
6666
'last_state_change' => new Expression(

library/Icingadb/Model/UnreachableParent.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use ipl\Orm\Model;
1212
use ipl\Orm\Query;
1313
use ipl\Orm\Relations;
14+
use ipl\Sql\Adapter\Pgsql;
1415
use ipl\Sql\Connection;
1516
use ipl\Sql\Expression;
1617
use ipl\Sql\Select;
@@ -70,6 +71,7 @@ public function createBehaviors(Behaviors $behaviors): void
7071
{
7172
$behaviors->add(new Binary([
7273
'id',
74+
'child_id',
7375
'host_id',
7476
'service_id',
7577
'redundancy_group_id'
@@ -115,15 +117,23 @@ public static function on(Connection $db, Model $root = null): Query
115117

116118
private static function selectNodes(Connection $db, Model $root): Select
117119
{
120+
if ($db->getAdapter() instanceof Pgsql) {
121+
$binaryCast = "CAST('00000000000000000000' AS bytea20)";
122+
$booleanCast = "CAST('0' AS boolean)";
123+
} else {
124+
$binaryCast = "CAST('' AS binary(20))";
125+
$booleanCast = '0';
126+
}
127+
118128
$rootQuery = DependencyNode::on($db)
119129
->columns([
120130
'id' => 'id',
121131
'child_id' => 'id',
122132
'level' => new Expression('0'),
123133
'host_id' => 'host_id',
124-
'service_id' => new Expression("COALESCE(%s, CAST('' as binary(20)))", ['service_id']),
125-
'redundancy_group_id' => new Expression("CAST('' as binary(20))"),
126-
'is_group_member' => new Expression('0')
134+
'service_id' => new Expression("COALESCE(%s, $binaryCast)", ['service_id']),
135+
'redundancy_group_id' => new Expression($binaryCast),
136+
'is_group_member' => new Expression($booleanCast)
127137
]);
128138
if ($root instanceof Host) {
129139
$rootQuery->filter(Filter::all(

0 commit comments

Comments
 (0)