SymfonyBundle for handling versions based on triggers in mysql with doctrine

dev-main 2022-02-18 14:46 UTC

This package is auto-updated.

Last update: 2022-05-18 15:21:27 UTC


This is a symfony bundle for managing versions in version tables.

The bundle offers a command, which will create version tables based on the columns in your origin tables: All tables with a column named version (type INT/BIGINT) will have a corresponding version table called [originTableName]_version with same columns of the originTable.

Every originTable gets trigger, which will increase the version column on insert/updates and saves a copy in the version table.

NOTE: This works only for MySQL-Databases.


Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

composer require netbrothers-gmbh/version-bundle

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

composer require netbrothers-gmbh/version-bundle

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    NetBrothers\VersionBundle\NetBrothersVersionBundle::class => ['all' => true],


You have to set up the bundle:

  1. Copy vendor/netbrothers-gmbh/install/config/packages/netbrothers_version.yaml to symfony's config path.

  2. If you use Doctrine's migration:

    • Find out the config file doctrine.yaml and insert schema_filter: ~(?<!_version)$~ (find an example under vendor/netbrothers-gmbh/install/config/packages/doctrine_example.yaml). This tells Doctrine migrations to ignore the version tables. If you do not do this, doctrine migrations will drop the version tables on next migration!
    • Open netbrothers_version.yaml and set Doctrine's migration table as ignored. If you do not do this, this table will also have a version table!
  3. In netbrothers_version.yaml you can define columns, which are always ignored by the compare algorithm (The command always compares existing version tables with their origin tables).

  4. Clear symfony's cache.


  1. Prepare your origin tables: Add a column named version (type INT/BIGINT) to every table, you wish to have a version table. Best practice is to use the trait src/Traits/VersionColumn.php in your entities.

  2. Make a migration.

  3. Open a command console, enter your project directory and execute the following command:

php bin/console netbrothers:version 

The command will now recognize all tables with a version-column:

  • Create a version table, if none exists.
  • If a version table exists, compare the columns in both tables.
  • Drop existing triggers.
  • Create triggers.

You can specify a single table as argument. The command will just check this table:

php bin/console netbrothers:version blog

You can specify some options:

option meaning
create-trigger (default) Drop triggers, create not existing version tables, create triggers
drop-trigger Drop triggers
drop-version Drop triggers, drop version table
summary print todos to stdout - do not execute
sql print prepared SQL-Statements to stdout - do not execute


Stefan Wessel, NetBrothers GmbH