Skip to content

Commit

Permalink
db: Update models to reflect latest schema updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Dec 17, 2024
1 parent 9c86ab9 commit 48d822f
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 177 deletions.
2 changes: 1 addition & 1 deletion library/Icingadb/Model/Behavior/HasProblematicParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function rewriteColumn($column, ?string $relation = null): ?AliasedExpres
->columns([new Expression('1')])
->utilize('from')
->limit(1)
->filter(Filter::equal('dependency.state.failed', 'y'));
->filter(Filter::equal('state.failed', 'y'));

$subQueryResolver = $subQuery->getResolver()->setAliasPrefix('hpp_');
$subQueryTarget = $subQueryResolver->resolveRelation($subQueryModel->getTableName() . '.from')->getTarget();
Expand Down
95 changes: 0 additions & 95 deletions library/Icingadb/Model/Dependency.php

This file was deleted.

15 changes: 9 additions & 6 deletions library/Icingadb/Model/DependencyEdge.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*
* @property string $to_node_id
* @property string $from_node_id
* @property ?string $dependency_id
* @property string $display_name
* @property string $dependency_edge_state_id
*
* @property DependencyNode|Query $child
* @property DependencyNode|Query $parent
* @property (?Dependency)|Query $dependency
* @property DependencyEdgeState|Query $state
*/
class DependencyEdge extends Model
{
Expand All @@ -38,7 +39,8 @@ public function getColumns(): array
return [
'to_node_id',
'from_node_id',
'dependency_id'
'display_name',
'dependency_edge_state_id'
];
}

Expand All @@ -47,7 +49,7 @@ public function createBehaviors(Behaviors $behaviors): void
$behaviors->add(new Binary([
'to_node_id',
'from_node_id',
'dependency_id'
'dependency_edge_state_id'
]));
}

Expand All @@ -57,8 +59,9 @@ public function createRelations(Relations $relations): void
->setCandidateKey('from_node_id');
$relations->belongsTo('parent', DependencyNode::class)
->setCandidateKey('to_node_id');
$relations->belongsTo('dependency', Dependency::class)
->setJoinType('LEFT');
$relations->hasOne('state', DependencyEdgeState::class)
->setCandidateKey('dependency_edge_state_id')
->setForeignKey('id');

// "from" and "to" are only necessary for sub-query filters.
$relations->belongsTo('from', DependencyNode::class)
Expand Down
47 changes: 47 additions & 0 deletions library/Icingadb/Model/DependencyEdgeState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Icinga\Module\Icingadb\Model;

use ipl\Orm\Behavior\BoolCast;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;

/**
* Dependency edge state model.
*
* @property string $id
* @property bool $failed
*/
class DependencyEdgeState extends Model
{
public function getTableName()
{
return 'dependency_edge_state';
}

public function getKeyName()
{
return 'id';
}

public function getColumns()
{
return [
'failed'
];
}

public function getColumnDefinitions()
{
return [
'failed' => t('Dependency Edge State Failed')
];
}

public function createBehaviors(Behaviors $behaviors): void
{
$behaviors->add(new BoolCast([
'failed'
]));
}
}
58 changes: 0 additions & 58 deletions library/Icingadb/Model/DependencyState.php

This file was deleted.

4 changes: 0 additions & 4 deletions library/Icingadb/Model/RedundancyGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
* Redundancy group model.
*
* @property string $id
* @property string $name
* @property string $display_name
*
* @property (?RedundancyGroupState)|Query $state
* @property Dependency|Query $dependency
* @property DependencyEdge|Query $from
* @property DependencyEdge|Query $to
*/
Expand All @@ -39,7 +37,6 @@ public function getKeyName(): string
public function getColumns(): array
{
return [
'name',
'display_name'
];
}
Expand Down Expand Up @@ -67,7 +64,6 @@ public function createRelations(Relations $relations): void
$relations->hasOne('state', RedundancyGroupState::class)
->setJoinType('LEFT');

$relations->hasMany('dependency', Dependency::class);
$relations->hasOne('dependency_node', DependencyNode::class)->setJoinType('LEFT');

$relations->belongsToMany('from', DependencyEdge::class)
Expand Down
1 change: 0 additions & 1 deletion library/Icingadb/Model/Timeperiod.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,5 @@ public function createRelations(Relations $relations)
$relations->hasMany('service', Service::class)
->setForeignKey('check_timeperiod_id');
$relations->hasMany('user', User::class);
$relations->hasMany('dependency', Dependency::class);
}
}
13 changes: 2 additions & 11 deletions library/Icingadb/Model/UnreachableParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
* @property ?string $host_id
* @property ?string $service_id
* @property ?string $redundancy_group_id
* @property ?string $dependency_id
* @property int $is_group_member
*
* @property (?Host)|Query $host
* @property (?Service)|Query $service
* @property (?RedundancyGroup)|Query $redundancy_group
* @property (?Dependency)|Query $dependency
*/
class UnreachableParent extends DependencyNode
{
Expand All @@ -52,7 +50,6 @@ public function getColumns(): array
'host_id',
'service_id',
'redundancy_group_id',
'dependency_id',
'is_group_member'
];
}
Expand All @@ -65,8 +62,6 @@ public function createRelations(Relations $relations): void
->setJoinType('LEFT');
$relations->belongsTo('redundancy_group', RedundancyGroup::class)
->setJoinType('LEFT');
$relations->belongsTo('dependency', Dependency::class)
->setJoinType('LEFT');
}

public function createBehaviors(Behaviors $behaviors): void
Expand All @@ -75,8 +70,7 @@ public function createBehaviors(Behaviors $behaviors): void
'id',
'host_id',
'service_id',
'redundancy_group_id',
'dependency_id'
'redundancy_group_id'
]));

$behaviors->add(new ReRoute([
Expand Down Expand Up @@ -113,7 +107,6 @@ private static function selectNodes(Connection $db, Model $root): Select
'host_id' => 'host_id',
'service_id' => new Expression("COALESCE(%s, CAST('' as binary(20)))", ['service_id']),
'redundancy_group_id' => new Expression("CAST('' as binary(20))"),
'dependency_id' => new Expression("CAST('' as binary(20))"),
'is_group_member' => new Expression('0')
]);
if ($root instanceof Host) {
Expand All @@ -139,11 +132,10 @@ private static function selectNodes(Connection $db, Model $root): Select
'host_id' => 'to.host_id',
'service_id' => 'to.service_id',
'redundancy_group_id' => 'to.redundancy_group_id',
'dependency_id' => 'dependency_id',
'is_group_member' => new Expression('urn.redundancy_group_id IS NOT NULL AND urn.level > 0')
]);
$nodeQuery->filter(Filter::any(
Filter::equal('dependency.state.failed', 'y'),
Filter::equal('state.failed', 'y'),
Filter::equal('to.redundancy_group.state.failed', 'y')
));

Expand All @@ -159,7 +151,6 @@ private static function selectNodes(Connection $db, Model $root): Select
'host_id' => null,
'service_id' => null,
'redundancy_group_id' => null,
'dependency_id' => null,
'is_group_member' => null
],
$nodeSelect->getColumns()
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/Detail/ObjectDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ protected function createAffectedObjects(): ?array
$failedEdges = DependencyEdge::on($this->getDb())
->utilize('child')
->columns([new Expression('1')])
->filter(Filter::equal('dependency.state.failed', 'y'));
->filter(Filter::equal('state.failed', 'y'));

if ($this->object instanceof Host) {
$failedEdges
Expand Down

0 comments on commit 48d822f

Please sign in to comment.