Pluf : PHP 5 Framework Download | Bug Tracking | Documentation | Forum | Latest Changes | Home

Migration system

(Un)Installation of an application

Let say you want to install the application MyApp. In your application configuration file, you will have the following:

$cfg['installed_apps'] = array('Pluf', 'MyApp');

Note, that Pluf must be first. So to install the application, you just need to run the following command:

$ php migrate.php -a -d -i --conf=./MyApp/conf/conf.php 

What does it means:

  • -a: All the applications (here Pluf and MyApp).
  • -d: Display some debug info.
  • -i: Do the installation.
  • --conf: Path to your configuration file.

The will install the two applications and ensure that the database schema is matching the one needed by the current code.

To uninstall the applications:

$ php migrate.php -a -d -x --conf=./MyApp/conf/conf.php 
  • -x: Do the uninstallation.

Upgrade/Downgrade your database schema

You use the migration script but this time with some other parameters.

$ php migrate.php -a -d --conf=./MyApp/conf/conf.php 

By default it will perform an upgrade to the latest version. But you can also downgrade to a given version:

$ php migrate.php -a -d -v4 --conf=./MyApp/conf/conf.php --app=MyApp

Note that you cannot migrate all the applications to a given version, you need to do that application by application.

  • --app: The application to act upon.
  • -v: The target version, here version 4.

Create migration scripts

Migrations scripts are located in the folder MyApp/Migrations/.

Installation

You need at least one script to install the application MyApp/Migrations/Install.php and this script provides to functions:

  • MyApp_Migrations_Install_setup: To install the application.
  • MyApp_Migrations_Install_teardown: To uninstall the application.

Usually you will create/drop the database tables of your models. Take a look at the Install.php file of Pluf to see what is done.

Upgrade/Downgrade

Upgrade downgrade scripts are in the form MyApp/Migrations/(\d+)Description.php, par exemple:

  • MyApp/Migrations/1AddDescriptionField.php
  • MyApp/Migrations/2CleanOldModel.php

The number at the start is used to order the migration scripts and to find the latest to be run.

Each script provides 2 functions, one to upgrade to the given version and one to downgrade to the previous version. For example:

function MyApp_Migrations_2CleanOldModel_up($params=null)
function MyApp_Migrations_2CleanOldModel_down($params=null)

Report issues in the documentation

If you find errors or issues in the documentation, report a bug with the label Component-Docs. We will update the documentation accordingly.

Pluf © 2005-2008 Loïc d'Anterroches, supported by Céondo Ltd.