A model can have a installer class to execute query. installer contain a batch of query that execute on each version update of a mode. All installers we create in "installer" directory inside the folder of model.
Installer is a class that extends model class and name of the class follow the folder path of it. See below example
Model Class:
First create the model class with a latest version
class blogCommentModel extends appRain_Base_Model
{
public $version = "0.1.0";
public $name = "BlogComment";
public $db_table = "blogcomments";
public $relation = array();
protected $model_validation = Array();
}
Installer Class:
Create installer class that extends model. The installer class has a method installerResource() that return query. System always execute query for present version of model. To create a SQL batch we update model version then create new SQL batch in return array.
Version number in model must sequentially incremental. For example: 0.1.0, 0.1.2 ....0.1.9,2.0.1,2.0.2 etc.
class Development_Models_Installer_blogComment extends blogCommentModel
{
public function installerResource()
{
$prefix = App::get("db_prefix");
return array(
"0.1.0"=>"CREATE TABLE IF NOT EXISTS `{$prefix['primary']}blogcomments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`postid` int(11) NOT NULL,
`userid` int(11) NOT NULL,
`name` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`website` varchar(100) NOT NULL,
`comment` text NOT NULL,
`dated` datetime NOT NULL,
`status` enum('Active','Inactive') NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"
);
}
}
1.Check Model Version and Installer index. You can also check model version form below location:
a.Login Admin Panel and Click Preferences.
b.On left Side click on System > MVC Manager and check version of model.
2.Set Model Version Control=Yes in System Configuration from below location:
Admin Panel > Preferences > Configuration
3.Set Debug=2 from below location to see the system SQL list at below of the page:
Admin Panel > Preferences > Configuration
4.For further inspection you can see the updated version in database table coreresources