actions in device_skip table are now an array/set
This commit is contained in:
		| @@ -56,6 +56,28 @@ __PACKAGE__->set_primary_key("job"); | ||||
|  | ||||
| # You can replace this text with custom code or comments, and it will be preserved on regeneration | ||||
|  | ||||
| =head1 RELATIONSHIPS | ||||
|  | ||||
| =head2 skipped | ||||
|  | ||||
| Retuns the set of C<device_skip> entries which may apply to this job. They | ||||
| match the device IP and job action, and may refer to one or more backends. | ||||
|  | ||||
| =cut | ||||
|  | ||||
| __PACKAGE__->has_many( skipped => 'App::Netdisco::DB::Result::DeviceSkip', | ||||
|   sub { | ||||
|     my $args = shift; | ||||
|     return { | ||||
|       "$args->{foreign_alias}.device" | ||||
|         => { -ident => "$args->{self_alias}.device" }, | ||||
|       "$args->{foreign_alias}.actionset" | ||||
|         => { '@>' => \"string_to_array($args->{self_alias}.action,'')" }, | ||||
|     }; | ||||
|   }, | ||||
|   { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 } | ||||
| ); | ||||
|  | ||||
| =head1 METHODS | ||||
|  | ||||
| =head2 summary | ||||
| @@ -114,17 +136,4 @@ between the date stamp and time stamp. That is: | ||||
|  | ||||
| sub finished_stamp  { return (shift)->get_column('finished_stamp')  } | ||||
|  | ||||
| =head1 RELATIONSHIPS | ||||
|  | ||||
| =head2 skipped | ||||
|  | ||||
| Retuns the set of C<device_skip> entries which may apply to this job. They | ||||
| match the device IP and job action, and may refer to one or more backends. | ||||
|  | ||||
| =cut | ||||
|  | ||||
| __PACKAGE__->has_many( skipped => 'App::Netdisco::DB::Result::DeviceSkip', | ||||
|    { 'foreign.device' => 'self.device', 'foreign.action' => 'self.action' }, | ||||
| ); | ||||
|  | ||||
| 1; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user