From 4f725387447eb2fadcbacd7b11449a1d330d84da Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 17 Dec 2024 14:49:00 +0100 Subject: [PATCH] db: Update models to reflect latest schema updates --- .../Model/Behavior/HasProblematicParent.php | 2 +- library/Icingadb/Model/Dependency.php | 95 ------------------- library/Icingadb/Model/DependencyEdge.php | 15 +-- .../Icingadb/Model/DependencyEdgeState.php | 47 +++++++++ library/Icingadb/Model/DependencyState.php | 58 ----------- library/Icingadb/Model/RedundancyGroup.php | 4 - library/Icingadb/Model/Timeperiod.php | 1 - library/Icingadb/Model/UnreachableParent.php | 13 +-- .../Icingadb/Widget/Detail/ObjectDetail.php | 2 +- 9 files changed, 60 insertions(+), 177 deletions(-) delete mode 100644 library/Icingadb/Model/Dependency.php create mode 100644 library/Icingadb/Model/DependencyEdgeState.php delete mode 100644 library/Icingadb/Model/DependencyState.php diff --git a/library/Icingadb/Model/Behavior/HasProblematicParent.php b/library/Icingadb/Model/Behavior/HasProblematicParent.php index 840479e19..6ec6a4b2f 100644 --- a/library/Icingadb/Model/Behavior/HasProblematicParent.php +++ b/library/Icingadb/Model/Behavior/HasProblematicParent.php @@ -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(); diff --git a/library/Icingadb/Model/Dependency.php b/library/Icingadb/Model/Dependency.php deleted file mode 100644 index 0a32a8096..000000000 --- a/library/Icingadb/Model/Dependency.php +++ /dev/null @@ -1,95 +0,0 @@ -add(new Binary([ - 'id', - 'redundancy_group_id', - 'timeperiod_id' - ])); - $behaviors->add(new BoolCast([ - 'disable_checks', - 'disable_notifications', - 'ignore_soft_states' - ])); - $behaviors->add(new Bitmask([ - 'states' => [ - 'ok' => 1, - 'warning' => 2, - 'critical' => 4, - 'unknown' => 8, - 'up' => 16, - 'down' => 32 - ], - ])); - } - - public function createRelations(Relations $relations): void - { - $relations->belongsTo('timeperiod', Timeperiod::class) - ->setJoinType('LEFT'); - $relations->belongsTo('redundancy_group', RedundancyGroup::class) - ->setJoinType('LEFT'); - - $relations->hasOne('state', DependencyState::class) - ->setJoinType('LEFT'); - - $relations->hasOne('edge', DependencyEdge::class); - } -} diff --git a/library/Icingadb/Model/DependencyEdge.php b/library/Icingadb/Model/DependencyEdge.php index 7674ce3ed..9e67c7e05 100644 --- a/library/Icingadb/Model/DependencyEdge.php +++ b/library/Icingadb/Model/DependencyEdge.php @@ -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 { @@ -38,7 +39,8 @@ public function getColumns(): array return [ 'to_node_id', 'from_node_id', - 'dependency_id' + 'display_name', + 'dependency_edge_state_id' ]; } @@ -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' ])); } @@ -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) diff --git a/library/Icingadb/Model/DependencyEdgeState.php b/library/Icingadb/Model/DependencyEdgeState.php new file mode 100644 index 000000000..e0f001c93 --- /dev/null +++ b/library/Icingadb/Model/DependencyEdgeState.php @@ -0,0 +1,47 @@ + t('Dependency Edge State Failed') + ]; + } + + public function createBehaviors(Behaviors $behaviors): void + { + $behaviors->add(new BoolCast([ + 'failed' + ])); + } +} diff --git a/library/Icingadb/Model/DependencyState.php b/library/Icingadb/Model/DependencyState.php deleted file mode 100644 index cf1eb5de0..000000000 --- a/library/Icingadb/Model/DependencyState.php +++ /dev/null @@ -1,58 +0,0 @@ -add(new Binary([ - 'id', - 'dependency_id' - ])); - $behaviors->add(new BoolCast([ - 'failed' - ])); - } - - public function createRelations(Relations $relations): void - { - $relations->belongsTo('dependency', Dependency::class); - } -} diff --git a/library/Icingadb/Model/RedundancyGroup.php b/library/Icingadb/Model/RedundancyGroup.php index efe44d9b2..ad3b89f04 100644 --- a/library/Icingadb/Model/RedundancyGroup.php +++ b/library/Icingadb/Model/RedundancyGroup.php @@ -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 */ @@ -39,7 +37,6 @@ public function getKeyName(): string public function getColumns(): array { return [ - 'name', 'display_name' ]; } @@ -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) diff --git a/library/Icingadb/Model/Timeperiod.php b/library/Icingadb/Model/Timeperiod.php index 34ff55096..e1664103b 100644 --- a/library/Icingadb/Model/Timeperiod.php +++ b/library/Icingadb/Model/Timeperiod.php @@ -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); } } diff --git a/library/Icingadb/Model/UnreachableParent.php b/library/Icingadb/Model/UnreachableParent.php index 6ba633aac..b4661ffbe 100644 --- a/library/Icingadb/Model/UnreachableParent.php +++ b/library/Icingadb/Model/UnreachableParent.php @@ -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 { @@ -52,7 +50,6 @@ public function getColumns(): array 'host_id', 'service_id', 'redundancy_group_id', - 'dependency_id', 'is_group_member' ]; } @@ -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 @@ -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([ @@ -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) { @@ -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') )); @@ -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() diff --git a/library/Icingadb/Widget/Detail/ObjectDetail.php b/library/Icingadb/Widget/Detail/ObjectDetail.php index 064fb1f02..f0f6a0125 100644 --- a/library/Icingadb/Widget/Detail/ObjectDetail.php +++ b/library/Icingadb/Widget/Detail/ObjectDetail.php @@ -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