{"id":23453667,"url":"https://github.com/netbrothers-gmbh/version-bundle","last_synced_at":"2025-04-13T22:50:55.128Z","repository":{"id":43790053,"uuid":"351025510","full_name":"netbrothers-gmbh/version-bundle","owner":"netbrothers-gmbh","description":"Trigger based version tables with MariaDB/MySQL and Doctrine","archived":false,"fork":false,"pushed_at":"2024-05-31T12:32:22.000Z","size":62,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-27T13:06:40.097Z","etag":null,"topics":["database","doctrine","mariadb","mysql","php","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/netbrothers-gmbh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-24T09:48:11.000Z","updated_at":"2024-07-01T14:00:08.000Z","dependencies_parsed_at":"2024-05-31T13:51:47.716Z","dependency_job_id":null,"html_url":"https://github.com/netbrothers-gmbh/version-bundle","commit_stats":{"total_commits":31,"total_committers":3,"mean_commits":"10.333333333333334","dds":0.3870967741935484,"last_synced_commit":"74df44fdd948d40279e26b31d54f733266d2f925"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netbrothers-gmbh%2Fversion-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netbrothers-gmbh%2Fversion-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netbrothers-gmbh%2Fversion-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netbrothers-gmbh%2Fversion-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/netbrothers-gmbh","download_url":"https://codeload.github.com/netbrothers-gmbh/version-bundle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501865,"owners_count":21114683,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","doctrine","mariadb","mysql","php","symfony"],"created_at":"2024-12-24T02:19:36.905Z","updated_at":"2025-04-13T22:50:55.108Z","avatar_url":"https://github.com/netbrothers-gmbh.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![build status](https://github.com/netbrothers-gmbh/version-bundle/actions/workflows/build.yml/badge.svg)\n\n# NetBrothers Version Bundle\n\nThis hybrid package works as a [Symfony bundle](https://symfony.com/doc/current/bundles.html)\nor as a standalone PHP package for managing versioned tables in [MariaDB](https://mariadb.com/)\nand [MySQL](https://www.mysql.com/) databases. It makes use of the\n[Doctrine ORM](https://www.doctrine-project.org/projects/orm.html) to interact\nwith your database.\n\n__NOTE__: This package is designed to work with MariaDB/MySQL. It is **not**\nconsidered to work with other RDBMS.\n\nIn essence, this package provides one command which does two things.\n\n1. Create Version Tables  \nFor tables (e.g. `orig_table`) with a column named `version` of type\n`INT`/`BIGINT` the script will create a corresponding version table (e.g.\n`orig_table_version`) so that origin and version tables are structurally identical.\n\n2. Create Version Triggers  \nFor every versioned origin table the script creates a trigger, which will on\n`INSERT`s and `UPDATE`s increase the version number in the version column and\nsave a copy of the row in the version table.\n\n## Installation\n\nOn the command prompt, change into your project's root directory and execute:\n\n```console\ncomposer require netbrothers-gmbh/version-bundle\n```\n\nThere are three installation variants:\n\n### Standalone Package\n\nNo further installation steps are necessary.\n### Symfony Bundle with Flex\n\nNo further installation steps are necessary. Symfony Flex will automatically\nregister the bundle in `config/bundles.php`.\n### Symfony Bundle without Flex\n\nYou have to enable the bundle by adding it to the list of registered bundles in\nthe file `config/bundles.php` in your project.\n\n```php\n// config/bundles.php\nreturn [\n    // ...\n    NetBrothers\\VersionBundle\\NetBrothersVersionBundle::class =\u003e ['all' =\u003e true],\n    // ...\n];\n```\n\n## Configuration\n\n### Symfony Bundle\n\nCopy the file [netbrothers_version.yaml](install/config/packages/netbrothers_version.yaml)\nfrom the `install` folder of this package to your Symfony project's config path.\n\n#### **Doctrine Migrations**\n\nIf you are using [Doctrine Migrations](https://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html)\ninstruct it to ignore your version tables, by using/customizing the\n[schema filter](https://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html#manual-tables) option.\nIf you don't have any other schema filter, you might use this:\n`schema_filter: ~(?\u003c!_version)$~`. See in the [example file](install/config/packages/doctrine_example.yaml)\nhow it's done.\n\n__NOTE__: If you don't filter your version tables, Doctrine may drop them on the\nnext occasion.\n\n#### **Bundle Configuration**\n\nYou can specify certain columns (by name) to always be ignored by the compare\nalgorithm when creating versions. See how it's done in the example file\n[`netbrothers_version.yaml`](install/config/packages/netbrothers_version.yaml).\n\n### Standalone\n\nIn most PHP frameworks you will have a [PSR-11 compatible container](https://php-di.org/)\nto manage your dependencies. You'll have to provide this container to the script\nvia a file argument.\n\n```console\nvendor/bin/netbrothers-version --container-file=config/container.php --summary\n```\n\nThe script will check if the provided container implements the\n[PSR-11 `ContainerInterface`](https://github.com/php-fig/container/blob/master/src/ContainerInterface.php).\nIf it does, it will assume an instance of the\n[Doctrine EntityManagerInterface](https://github.com/doctrine/orm/blob/2.8.x/lib/Doctrine/ORM/EntityManagerInterface.php)\nby the identifier `EntityManagerInterface::class`. Here's an example on how to check,\nif your container file works properly.\n\n```php\n\u003c?php\n\nrequire_once '/path/to/vendor/autoload.php';\n\nuse Psr\\Container\\ContainerInterface;\nuse Doctrine\\ORM\\EntityManagerInterface;\n\n$container = require '/path/to/your/container-file.php';\n\nif (\n    $container instanceof ContainerInterface\n    \u0026\u0026 $container-\u003eget(EntityManagerInterface::class) instanceof EntityManagerInterface\n) {\n    // everything is fine\n} else {\n    // you need to check your container file\n}\n```\n\nIn standalone mode, ignoring tables and columns is controlled by command\nline options.\n\n```console\nvendor/bin/netbrothers-version \\\n    --container-file=config/container.php \\\n    --ignore-table=unversioned_table_one \\\n    --ignore-table=unversioned_table_two \\\n    --exclude-column=unversioned_column_one \\\n    --exclude-column=unversioned_column_two \\\n    --create-trigger\n```\n\n## Usage\n\n### Prepare your Entities/Origin Tables\n\nAdd a column named `version` (type `INT`/`BIGINT`) to every table you want to\nbe versioned. This can be done by adding the Trait\n[VersionColumn](src/Traits/VersionColumn.php) to your entities and then creating\nand applying a migration.\n\n### Create Version Tables and Triggers\n\nIssue the following command.\n\n```console\n# Symfony\nbin/console netbrothers:version \n\n# Standalone\nvendor/bin/netbrothers-version --container-file=config/container.php\n```\n\nFor every table with a `version`-column the command will\n\n- create a corresponding version table (if it doesn't exist yet),\n- compare the columns in both tables and alter the version table to match\n  the origin table,\n- (if present) it will drop the old version triggers and\n- (in any case) it will create the version triggers.\n\n### Create Version Tables and Triggers for a Single Table\n\nIf needed, you can apply the versioning to a single table. This can be done by\nproviding the table name as an argument to the console command.\n\n```console\n\n# Symfony\nbin/console netbrothers:version [\u003ctableName\u003e]\n\n# Standalone\nvendor/bin/netbrothers-version --container-file=config/container.php [\u003ctableName\u003e]\n```\n\n### Command Line Options\n\nThe version command provides these options (sub commands).\n\n| Option             | Meaning                                                      |\n| -------------      | ------------------------------------------------------------ |\n| `--create-trigger` (default)  | drop triggers, create non-existent version tables, recreate triggers |\n| `--drop-trigger`   | drop triggers                                                |\n| `--drop-version`   | drop triggers, drop version tables                           |\n| `--sql`            | print the SQL statements without doing anything              |\n| `--summary`        | print a human readable summary of what the command would do  |\n\n## Licence\n\nMIT\n\n## Authors\n\n- [Stefan Wessel, NetBrothers GmbH](https://netbrothers.de)\n- [Thilo Ratnaweera, NetBrothers GmbH](https://netbrothers.de)\n\n[![nb.logo](https://netbrothers.de/wp-content/uploads/2020/12/netbrothers_logo.png)](https://netbrothers.de)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetbrothers-gmbh%2Fversion-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetbrothers-gmbh%2Fversion-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetbrothers-gmbh%2Fversion-bundle/lists"}