Tigra is a tool that simplifies your daily work with Magento as a developer. As you probably know, there's a Setup Resource thing in Magento, that has shortcut methods for operations like working with atributes and entity types. The problem with it is that it is connected to a particular module, which is mostly not useful when you need to make changes to different parts of application. Moreover, setup resources are hard to manage so you can't apply your database changes using Cron job or automate things with deployment tool like Phing. Tigra allows you to create database migrations and manage your database version via command line and/or Magento backend.
- Copy all repo files to Magento root directory
- Login to the backend
- Create a migrations directory somewhere in Magento directory
- Follow System->Configuration, Developer->Database migrations and fill in the "Migrations directory" with appropriate directory path.
- Save config.
Before you start, please make sure you are familiar with the following:
Also, make sure that your tables support transactions.
To create a migration, do the following:
- Run the following in your magento directory:
$ cd shell/
$ ./tigra --generate MIGRATION_NAME
This will create a skeleton migration for you in your migrations/ directory (e.g., 005_change_site_name.php). Edit it to reflect your needs.
- Migrate:
$ ./tigra up
For your convenience, Tigra is coming shipped with both CLI and WEB interfaces.
All commands below are executed in the shell/ directory.
To get help, run ./tigra
in your magento/shell directory.
To upgrade your database, run
$ ./tigra up
By default, it applies all migrations that it can found in migrations/ directory.
To downgrade, run
$ ./tigra down
It will downgrade the database to the previous version.
If you want to upgrade/downgrade to a particular version, you can pass the --to
parameter:
$ ./tigra up --to 003
The following command prints the current version of the database:
$ ./tigra version
Web interface is available at the Magento backend, System->Tools->DB Migrations.
To upgrade the database using Web interface, follow the "Update to" link near the migration you want to upgrade to.
To upgrade the database using Web interface, follow the "Rollback (including)" link near the migration you want to downgrade to.
In case if you want to create the migration manually, please follow the rules below when picking the migration name.
Each migration should be named as <migration_num>_<description>.php
and should not contain any spaces.
The code inside should follow the next rules:
- Class name should be descriptive enough as this text is being stored in the database changelog table as a migration description.
- Each migration should have both up() and down() methods to make migration mechanism working in two directions.
Here's the small example on how the migration file should look like:
<?php
class Alter_Position extends Tigra_Migration {
public function up() {
Mage::log('Upgrading the database...');
// any magento code you like
}
public function down() {
// the code to cancel changes in up() method
}
}
Inside migrations, you can execute any Magento code you like. For example, you can use features of Mage_Eav_Model_Setup model, that is available for you by calling
$setup = $this->_getSetup();
in your migration file.