alexandrump/id-to-uuid-doctrine3

轻松将自增ID迁移到UUID

1.0.0 2022-09-15 11:56 UTC

This package is auto-updated.

Last update: 2024-09-15 16:53:53 UTC


README

此库是将包移植到Doctrine 3的版本。

轻松将项目中的自增整数ID迁移到UUID,使用DoctrineMigrationsBundle。自动检测外键并更新它们。 仅适用于MySQL

安装

composer require alexandrump/id-to-uuid-doctrine3

使用

  1. id列从integer更新为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. 配置symfony

点击这里

  1. 添加新迁移
// 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');
    }
}