1 package FS::upgrade_journal;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
9 FS::upgrade_journal - Object methods for upgrade_journal records
13 use FS::upgrade_journal;
15 $record = new FS::upgrade_journal \%hash;
16 $record = new FS::upgrade_journal { 'column' => 'value' };
18 $error = $record->insert;
21 my $upgrade = 'rename_all_customers_to_Bob';
22 if ( ! FS::upgrade_journal->is_done($upgrade) ) {
23 ... # do the upgrade, then, if it succeeds
24 FS::upgrade_journal->set_done($upgrade);
29 An FS::upgrade_journal object records an upgrade procedure that was run
30 on the database. FS::upgrade_journal inherits from FS::Record. The
31 following fields are currently supported:
35 =item upgradenum - primary key
37 =item _date - unix timestamp when the upgrade was run
39 =item upgrade - string identifier for the upgrade procedure; must match /^\w+$/
41 =item status - either 'done' or 'failed'
43 =item statustext - any other message that needs to be recorded
53 Creates a new upgrade record. To add it to the database, see L<"insert">.
55 Note that this stores the hash reference, not a distinct copy of the hash it
56 points to. You can ask the object for a copy with the I<hash> method.
60 # the new method can be inherited from FS::Record, if a table method is defined
62 sub table { 'upgrade_journal'; }
66 Adds this record to the database. If there is an error, returns the error,
67 otherwise returns false.
71 # the insert method can be inherited from FS::Record
73 sub delete { die "upgrade_journal records can't be deleted" }
74 sub replace { die "upgrade_journal records can't be modified" }
78 Checks all fields to make sure this is a valid example. If there is
79 an error, returns the error, otherwise returns false. Called by the insert
84 # the check method should currently be supplied - FS::Record contains some
85 # data checking routines
90 if ( !$self->_date ) {
95 $self->ut_numbern('upgradenum')
96 || $self->ut_number('_date')
97 || $self->ut_alpha('upgrade')
98 || $self->ut_text('status')
99 || $self->ut_textn('statustext')
101 return $error if $error;
112 =item is_done UPGRADE
114 Returns the upgrade entry with identifier UPGRADE and status 'done', if
115 there is one. This is an easy way to check whether an upgrade has been done.
120 my ($class, $upgrade) = @_;
121 qsearch('upgrade_journal', { 'status' => 'done', 'upgrade' => $upgrade })
124 =item set_done UPGRADE
126 Creates and inserts an upgrade entry with the current time, status 'done',
127 and identifier UPGRADE. Dies on error.
132 my ($class, $upgrade) = @_;
133 my $new = $class->new({ 'status' => 'done', 'upgrade' => $upgrade });
134 my $error = $new->insert;
135 die $error if $error;
142 Despite how it looks, this is not currently suitable for use as a mutex.
146 L<FS::Record>, schema.html from the base documentation.