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 299ca1f commit 945eb5f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 137 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
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
<?php

/* Icinga DB Web | (c) 2024 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Icingadb\Model;

use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behavior\BoolCast;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
use ipl\Orm\Query;
use ipl\Orm\Relations;

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

public function getKeyName(): string
Expand All @@ -35,24 +28,24 @@ public function getKeyName(): string
public function getColumns(): array
{
return [
'dependency_id',
'failed'
];
}

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

public function createBehaviors(Behaviors $behaviors): void
{
$behaviors->add(new Binary([
'id',
'dependency_id'
'id'
]));
$behaviors->add(new BoolCast([
'failed'
]));
}

public function createRelations(Relations $relations): void
{
$relations->belongsTo('dependency', Dependency::class);
}
}
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 @@ -25,13 +25,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 @@ -54,7 +52,6 @@ public function getColumns(): array
'host_id',
'service_id',
'redundancy_group_id',
'dependency_id',
'is_group_member'
];
}
Expand All @@ -67,8 +64,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 @@ -77,8 +72,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 @@ -116,7 +110,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 @@ -143,11 +136,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 @@ -164,7 +156,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 945eb5f

Please sign in to comment.