backup the schema for tables we don't need the data from. RT#85959
[freeside.git] / FS / FS / queue_depend.pm
1 package FS::queue_depend;
2 use base qw( FS::Record );
3
4 use strict;
5 use FS::Record qw( dbh );
6
7 =head1 NAME
8
9 FS::queue_depend - Object methods for queue_depend records
10
11 =head1 SYNOPSIS
12
13   use FS::queue_depend;
14
15   $record = new FS::queue_depend \%hash;
16   $record = new FS::queue_depend { 'column' => 'value' };
17
18   $error = $record->insert;
19
20   $error = $new_record->replace($old_record);
21
22   $error = $record->delete;
23
24   $error = $record->check;
25
26 =head1 DESCRIPTION
27
28 An FS::queue_depend object represents an job dependancy.  FS::queue_depend
29 inherits from FS::Record.  The following fields are currently supported:
30
31 =over 4
32
33 =item dependnum - primary key
34
35 =item jobnum - source jobnum (see L<FS::queue>).
36
37 =item depend_jobnum - dependancy jobnum (see L<FS::queue>)
38
39 =back
40
41 The job specified by B<jobnum> depends on the job specified B<depend_jobnum> -
42 the B<jobnum> job will not be run until the B<depend_jobnum> job has completed
43 successfully (or manually removed).
44
45 =head1 METHODS
46
47 =over 4
48
49 =item new HASHREF
50
51 Creates a new dependancy.  To add the dependancy to the database, see
52 L<"insert">.
53
54 Note that this stores the hash reference, not a distinct copy of the hash it
55 points to.  You can ask the object for a copy with the I<hash> method.
56
57 =cut
58
59 # the new method can be inherited from FS::Record, if a table method is defined
60
61 sub table { 'queue_depend'; }
62
63 =item insert
64
65 Adds this record to the database.  If there is an error, returns the error,
66 otherwise returns false.
67
68 =cut
69
70 # the insert method can be inherited from FS::Record
71
72 =item delete
73
74 Delete this record from the database.
75
76 =cut
77
78 # the delete method can be inherited from FS::Record
79
80 =item replace OLD_RECORD
81
82 Replaces the OLD_RECORD with this one in the database.  If there is an error,
83 returns the error, otherwise returns false.
84
85 =cut
86
87 # the replace method can be inherited from FS::Record
88
89 =item check
90
91 Checks all fields to make sure this is a valid dependancy.  If there is
92 an error, returns the error, otherwise returns false.  Called by the insert
93 and replace methods.
94
95 =cut
96
97 sub check {
98   my $self = shift;
99
100   $self->ut_numbern('dependnum')
101     || $self->ut_foreign_key('jobnum',        'queue', 'jobnum')
102     || $self->ut_foreign_key('depend_jobnum', 'queue', 'jobnum')
103     || $self->SUPER::check
104   ;
105 }
106
107 =back
108
109 =cut
110
111 sub _upgrade_schema {
112   my ($class, %opts) = @_;
113
114   my $sql = '
115     DELETE FROM queue_depend WHERE NOT EXISTS
116       ( SELECT 1 FROM queue WHERE queue.jobnum = queue_depend.jobnum )
117   ';
118
119   my $sth = dbh->prepare($sql) or die dbh->errstr;
120   $sth->execute or die $sth->errstr;
121   '';
122 }
123
124 =head1 BUGS
125
126 =head1 SEE ALSO
127
128 L<FS::queue>, L<FS::Record>, schema.html from the base documentation.
129
130 =cut
131
132 1;
133