carva / id-to-uuid
轻松从自增ID迁移到UUID
dev-master
2023-03-10 20:19 UTC
Requires
- php: ^8.0
- doctrine/dbal: ^2.9
- doctrine/doctrine-migrations-bundle: ^3.2
- doctrine/orm: ^2.13
- ramsey/uuid-doctrine: 1.6.*
Requires (Dev)
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
使用方法
- 将
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>
- 配置 symfony
- 添加新的迁移
// 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'); } }