actions in device_skip table are now an array/set

This commit is contained in:
Oliver Gorwits
2017-05-23 11:34:27 +01:00
parent 5e126eef07
commit b55854e91d
4 changed files with 112 additions and 66 deletions

View File

@@ -4,6 +4,8 @@ package App::Netdisco::DB::Result::DeviceSkip;
use strict;
use warnings;
use List::MoreUtils ();
use base 'DBIx::Class::Core';
__PACKAGE__->table("device_skip");
__PACKAGE__->add_columns(
@@ -11,18 +13,18 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 0 },
"device",
{ data_type => "inet", is_nullable => 0 },
"action",
{ data_type => "text", is_nullable => 0 },
"actionset",
{ data_type => "text[]", is_nullable => 0 },
"deferrals",
{ data_type => "integer", is_nullable => 1, default_value => '0' },
"skipover",
{ data_type => "boolean", is_nullable => 1, default_value => \'false' },
);
__PACKAGE__->set_primary_key("backend", "device", "action");
__PACKAGE__->set_primary_key("backend", "device");
__PACKAGE__->add_unique_constraint(
device_skip_pkey => [qw/backend device action/]);
device_skip_pkey => [qw/backend device/]);
=head1 METHODS
@@ -39,4 +41,17 @@ sub increment_deferrals {
return $row->update({ deferrals => ($row->deferrals + 1) });
}
=head2 add_to_actionset
=cut
sub add_to_actionset {
my ($row, @badactions) = @_;
return unless $row->in_storage;
return unless scalar @badactions;
return $row->update({ actionset =>
[ sort (List::MoreUtils::uniq( @{ $row->actionset }, @badactions )) ]
});
}
1;