habbim/id-to-uuid

轻松从自增id迁移到uuid

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

This package is auto-updated.

Last update: 2024-09-15 01:50:53 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');
    }
}