1use utf8; 2package App::Netdisco::DB::Result::Admin; 3 4 5use strict; 6use warnings; 7 8use base 'App::Netdisco::DB::Result'; 9__PACKAGE__->table("admin"); 10__PACKAGE__->add_columns( 11 "job", 12 { 13 data_type => "integer", 14 is_auto_increment => 1, 15 is_nullable => 0, 16 sequence => "admin_job_seq", 17 }, 18 "entered", 19 { 20 data_type => "timestamp", 21 default_value => \"current_timestamp", 22 is_nullable => 1, 23 original => { default_value => \"now()" }, 24 }, 25 "started", 26 { data_type => "timestamp", is_nullable => 1 }, 27 "finished", 28 { data_type => "timestamp", is_nullable => 1 }, 29 "device", 30 { data_type => "inet", is_nullable => 1 }, 31 "port", 32 { data_type => "text", is_nullable => 1 }, 33 "action", 34 { data_type => "text", is_nullable => 1 }, 35 "subaction", 36 { data_type => "text", is_nullable => 1 }, 37 "status", 38 { data_type => "text", is_nullable => 1 }, 39 "username", 40 { data_type => "text", is_nullable => 1 }, 41 "userip", 42 { data_type => "inet", is_nullable => 1 }, 43 "log", 44 { data_type => "text", is_nullable => 1 }, 45 "debug", 46 { data_type => "boolean", is_nullable => 1 }, 47 "device_key", 48 { data_type => "text", is_nullable => 1 }, 49); 50 51 52 53__PACKAGE__->set_primary_key("job"); 54 55=head1 RELATIONSHIPS 56 57=head2 device_skips( $backend?, $max_deferrals?, $retry_after? ) 58 59Returns the set of C<device_skip> entries which apply to this job. They match 60the device IP, current backend, and job action. 61 62You probably want to use the ResultSet method C<skipped> which completes this 63query with a C<backend> host, C<max_deferrals>, and C<retry_after> parameters 64(or sensible defaults). 65 66=cut 67 68__PACKAGE__->might_have( device_skips => 'App::Netdisco::DB::Result::DeviceSkip', 69 sub { 70 my $args = shift; 71 return { 72 "$args->{foreign_alias}.backend" => { '=' => \'?' }, 73 "$args->{foreign_alias}.device" 74 => { -ident => "$args->{self_alias}.device" }, 75 -or => [ 76 "$args->{foreign_alias}.actionset" 77 => { '@>' => \"string_to_array($args->{self_alias}.action,'')" }, 78 -and => [ 79 "$args->{foreign_alias}.deferrals" => { '>=' => \'?' }, 80 "$args->{foreign_alias}.last_defer" => 81 { '>', \'(LOCALTIMESTAMP - ?::interval)' }, 82 ], 83 ], 84 }; 85 }, 86 { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 } 87); 88 89=head2 target 90 91Returns the single C<device> to which this Job entry was associated. 92 93The JOIN is of type LEFT, in case the C<device> is not in the database. 94 95=cut 96 97__PACKAGE__->belongs_to( target => 'App::Netdisco::DB::Result::Device', 98 { 'foreign.ip' => 'self.device' }, { join_type => 'LEFT' } ); 99 100=head1 METHODS 101 102=head2 display_name 103 104An attempt to make a meaningful statement about the job. 105 106=cut 107 108sub display_name { 109 my $job = shift; 110 return join ' ', 111 $job->action, 112 ($job->device || ''), 113 ($job->port || ''); 114# ($job->subaction ? (q{'}. $job->subaction .q{'}) : ''); 115} 116 117=head1 ADDITIONAL COLUMNS 118 119=head2 entered_stamp 120 121Formatted version of the C<entered> field, accurate to the minute. 122 123The format is somewhat like ISO 8601 or RFC3339 but without the middle C<T> 124between the date stamp and time stamp. That is: 125 126 2012-02-06 12:49 127 128=cut 129 130sub entered_stamp { return (shift)->get_column('entered_stamp') } 131 132=head2 started_stamp 133 134Formatted version of the C<started> field, accurate to the minute. 135 136The format is somewhat like ISO 8601 or RFC3339 but without the middle C<T> 137between the date stamp and time stamp. That is: 138 139 2012-02-06 12:49 140 141=cut 142 143sub started_stamp { return (shift)->get_column('started_stamp') } 144 145=head2 finished_stamp 146 147Formatted version of the C<finished> field, accurate to the minute. 148 149The format is somewhat like ISO 8601 or RFC3339 but without the middle C<T> 150between the date stamp and time stamp. That is: 151 152 2012-02-06 12:49 153 154=cut 155 156sub finished_stamp { return (shift)->get_column('finished_stamp') } 157 1581; 159