habbim/id-to-uuid

Easily migrate from auto incremented id to uuid

dev-master 2023-04-14 22:28 UTC

This package is auto-updated.

Last update: 2024-04-15 00:31:16 UTC


README

Easily migrate from an auto incremented integer id to a uuid in a project using DoctrineMigrationsBundle. Autodetect your foreign keys and update them. Works only on MySQL.

Installation

composer require habbim/id-to-uuid

Usage

  1. Update your id column from integer to guid:
# User.orm.xml
<entity name="AppBundle\Entity\User" table="user">
---    <id name="id" column="id" type="integer">
---        <generator strategy="AUTO" />
+++    <id name="id" column="id" type="uuid_binary_ordered_time">
+++        <generator strategy="CUSTOM"/>
+++        <custom-id-generator class="Ramsey\Uuid\Doctrine\UuidGenerator"/>           
    </id>
 #...
</entity>
  1. Config your symfony:

Click here

  1. Add a new migration:
// app/DoctrineMigrations/VersionXYZ.php
<?php

namespace Application\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Habbim\IdToUuid\IdToUuidMigration;

class VersionXYZ extends IdToUuidMigration
{
    public function postUp(Schema $schema)
    {
        $this->migrate('user');
    }
}