netbrothers-gmbh / version-bundle
Trigger based version tables with MariaDB/MySQL and Doctrine
Package info
github.com/netbrothers-gmbh/version-bundle
Type:symfony-bundle
pkg:composer/netbrothers-gmbh/version-bundle
Requires
- php: >=8.4
- doctrine/dbal: ^4.5
- doctrine/orm: ^3.6
- symfony/console: ^7.4 || ^8.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpunit/phpunit: ^12.0
- symfony/cache: ^7.4 || ^8.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This hybrid package works as a Symfony bundle or as a standalone PHP CLI tool for trigger-based row versioning in MariaDB and MySQL databases using Doctrine.
It automatically creates _version tables, synchronizes their schemas when your origin tables evolve through Doctrine migrations, and maintains INSERT / UPDATE triggers that record every revision.
Note: This package is designed specifically for MariaDB and MySQL. It is not compatible with PostgreSQL or SQLite.
Features
- Automatic
_versionschema synchronization via Doctrine DBAL — detects and appliesADD,MODIFY, andDROPcolumn changes without requiring manualALTER TABLE *_versionstatements in Doctrine migrations. - Historical-safe nullable columns — keeps all non-primary-key columns nullable in
_versiontables so addingNOT NULLcolumns without defaults (DATETIME,JSON,TEXT) or tighteningNULL → NOT NULLnever breaks on existing version history. - Robust DDL & triggers — DBAL-generated
CREATE TABLEDDL with safeNULL-version backfill,COALESCE(OLD.version, 0) + 1increments, reserved SQL keyword quoting, and deterministic 64-character MySQL/MariaDB identifier shortening. - Transparent CLI UX — structured per-table report, data-loss warnings for dropped columns,
--summarydry-run, clean pipeable--sqloutput (withDELIMITER $$blocks), single-table execution, and multi-EntityManager--emsupport. - Dual mode — works as a native Symfony bundle and as a standalone binary (
vendor/bin/netbrothers-version) with any PSR-11 container.
Requirements
- PHP
>= 8.4 - Symfony Console
^7.4 || ^8.0 - Doctrine DBAL
^4.5 - Doctrine ORM
^3.6 - MariaDB or MySQL
Installation
composer require netbrothers-gmbh/version-bundle
Standard Migration Workflow
Doctrine migrations only need to modify your origin tables (exclude *_version tables via doctrine.dbal.schema_filter: '~(?<!_version)$~'):
# 1. Apply Doctrine migrations (origin tables only) php bin/console doctrine:migrations:migrate # 2. Synchronize `_version` tables and recreate triggers php bin/console netbrothers:version
Preview planned changes or export an executable SQL script without modifying the database:
php bin/console netbrothers:version --summary php bin/console netbrothers:version --sql > version_sync.sql
Standalone Mode
vendor/bin/netbrothers-version --container-file=config/container.php
Documentation
- Full Documentation — installation, configuration, automatic schema sync details, CLI reference, data-migration edge case, and standalone setup.
- Upgrading from v4 to v5 — complete guide to all breaking changes and migration steps.
- Changelog — release history.
License
This bundle is released under the MIT license. See the bundled LICENSE file for details.