Basically, yes, you store it in both formats, as an option and as a constant for comparative purposes. It provides a layer of checks and balances that is no more difficult to implement than not doing it in the first place. Truth...
Refer to the following Q&A thread for some nice examples how:
Note: none of the code shown here is mine so full credit where credit is due!
m0r7if3r provides the following http://wordpress.stackexchange.com/a/49736/13418
if( $db_version < {your desired version} ) {
// previous updates and such
$db_version = $new_version; //put that in the database
}
if( $db_version < $current_version ) {
create $options array
foreach( $option as $o ) {
if( get_option( $o['old_name'] ) ) {
update_option( $o['new_name'], get_option( $o['old_name'] ) );
delete_option( $o['old_name'] ); //clean up behind yourself
}
}
and then update your database version again
}
which is the accepted answer to that question.
However,
One Trick Pony goes on to elaborate on that example with a nice bit of code in response...
class MyPlugin{
const
OPTION_NAME = 'my_plugin_options',
VERSION = '1.0';
protected
$options = null,
// default options and values go here
$defaults = array(
'version' => self::VERSION, // this one should not change
'test_option' => 'abc',
'another_one' => 420,
);
public function getOptions(){
// already did the checks
if(isset($this->options))
return $this->options;
// first call, get the options
$options = get_option(self::OPTION_NAME);
// options exist
if($options !== false){
$new_version = version_compare($options['version'], self::VERSION, '!=');
$desync = array_diff_key($this->defaults, $options) !== array_diff_key($options, $this->defaults);
// update options if version changed, or we have missing/extra (out of sync) option entries
if($new_version || $desync){
$new_options = array();
// check for new options and set defaults if necessary
foreach($this->defaults as $option => $value)
$new_options[$option] = isset($options[$option]) ? $options[$option] : $value;
// update version info
$new_options['version'] = self::VERSION;
update_option(self::OPTION_NAME, $new_options);
$this->options = $new_options;
// no update was required
}else{
$this->options = $options;
}
// new install (plugin was just activated)
}else{
update_option(self::OPTION_NAME, $this->defaults);
$this->options = $this->defaults;
}
return $this->options;
}
}
Please don't accept this answer as the correct answer, I'm just providing additional, supporting material that I have as a reference and which I think supports this topic well.
Do however show your support and up-vote their answers if you use them with any success.