Jifty::Manual::Upgrading
Jifty provides a way for you to upgrade the database schema and data of your application between versions. If all you are doing is adding new models or columns to existing models Jifty will do the upgrade almost automatically. If more extensive changes are required you need to write some code to tell Jifty what to do.
When adding a new model to your application you need to tell Jifty at which version of your application the model was created. To do this add a since sub to your new model class.
sub since { 0.0.5 }
When you have an existing model and decide that you need to add another column to it you also need to tell Jifty about this. This is done by using since as well. However, the since goes into the column definition itself.
since
column created_by => refers_to Wifty::Model::User, since '0.0.20';
If a file called Upgrade.pm exists in your application it will be run by jifty schema --setup.
jifty schema --setup
Upgrade.pm can be used to make any schema changes or to manipulate your applications data.
At the very least your Upgrade.pm should contain the following:
package MyApp::Upgrade; use base qw(Jifty::Upgrade); use Jifty::Upgrade qw( since rename ); since '0.6.1' => sub { .... };
The since function is where you do all the work. Each since will be run in version order until the application is up to date.
To rename a column, simply call rename inside your since code block:
rename
use MyApp::Model::User; since '0.6.1' => sub { rename( table => 'MyApp::Model::User', column => 'zip', to => 'postcode' ); };
To install Jifty, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Jifty
CPAN shell
perl -MCPAN -e shell install Jifty
For more information on module installation, please visit the detailed CPAN module installation guide.