chameleon-system-private/id-rewrite-bundle

There is no license information available for the latest version (8.0.45) of this package.

8.0.45 2025-06-16 13:34 UTC

README

Adds the ability to do one-time rewriting of IDs in the database. This bundle is largely centered around the rewrite_ids console command, which executes the ID-rewriting.

Usage:
  rewrite_ids [options]

Options:
      --dry-run         Do not change anything, just show what would be changed
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Defining ID-Rewriting Rules

This bundle only provides the 'plumbing' for rewriting IDs. It assumes that a project using it provides one or multiple RewritableIdFinder: A service implementing RewritableIdFinderInterface tagged with the chameleon_system.id_rewrite.rewritable_id_finder tag.

<service class="My\Vendor\MyIdFinder" id="my_vendor.my_id_finder">
    <argument type="service" id="database_connection" />
    <tag name="chameleon_system.id_rewrite.rewritable_id_finder" priority="10" />
</service>
use ChameleonSystem\IdRewriteBundle\Finder\RewritableIdFinderInterface;
use ChameleonSystem\IdRewriteBundle\Finder\RewritableIdListDataModel;
use ChameleonSystem\IdRewriteBundle\Finder\RewritableIdDataModel;

class MyIdFinder implements RewritableIdFinderInterface {
    public function findRewritableIds(): RewritableIdListDataModel {
        return RewritableIdListDataModel::forTable('my_table', [
            new RewritableIdDataModel('old_id', 'new_id'),
        ]);
    }
}

Architecture

High-Level overview of how this bundle rewrites IDs:

  • RewritableIdFinder 's find IDs that can be rewritten. The result of these is a list of "The ID on this table can change from X -> Y"
  • IdMigrationService::getChangesForIdMigration takes such a change and uses ForeignKeyDetectors in order to find all columns that must be changed in order for the ID change to be sucessful. It then converts the ID change to a list of changeSets, where one changeset refers to a singular database query. Most times, a singular ID change will result in multiple changesets and thus multiple database queries.
  • IdMigrationService::applyChanges takes a singular changeset and applies it to the database.
  • RewriteIdsCommand wires these services up such that each ID change from a finder will be converted to a list of changesets and then applied to the database.