Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db: Update models to reflect latest schema updates #1113

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
raviks789 marked this conversation as resolved.
Show resolved Hide resolved
{
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 @@ -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
Loading