carva/id-to-uuid

轻松从自增ID迁移到UUID

dev-master 2023-03-10 20:19 UTC

This package is not auto-updated.

Last update: 2024-09-21 22:46:56 UTC


README

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

安装

composer require habbim/id-to-uuid

使用方法

  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');
    }
}