How-to create migration

Migrations apply during upgrade installation. They change the structure of tables of the store’s database or modify data in those tables.

To write a migration, use Phinx. Please note that CS-Cart uses an old version of Phinx (0.4.3), so not all instructions from the latest Phinx documentation may apply. Here are the old Phinx 0.4.3 docs about:

The migration class must contain the up method that will be executed during the upgrade process.

For example:

use Phinx\Migration\AbstractMigration;

class AddonsSampleAddonUpdateVersion extends AbstractMigration
    public function up()
        $options = $this->adapter->getOptions();
        $pr = $options['prefix'];

        $this->execute("UPDATE {$pr}addons SET version = '1.1' WHERE addon = 'sample_addon'");

Do and Don’t

  • Separate your changes between migrations: each migration should implement a single logically complete action.
  • Don’t use raw SQL in migrations to change table structure; use only Phinx methods.
  • Don’t use CS-Cart core functions in the migrations: there is no guarantee that they will be available when an add-on upgrade is being installed. This will lead to the crash of the upgrade process and may result in a broken store.



If you have a problem, need assistance with tweaks or a free consultation, if you just want to discuss your project with experts and estimate the outcome, if you're looking for a solution that reinforces your online business, we will help. Let us know through MyCloud or email.