habbim / id-to-uuid
轻松从自增id迁移到uuid
dev-master
2023-04-14 22:28 UTC
Requires
- php: ^7.1 || ^8.0
- doctrine/dbal: ^2.9
- doctrine/doctrine-migrations-bundle: ^2.0
- doctrine/orm: ^2.6
- ramsey/uuid-doctrine: ^1.5
Requires (Dev)
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
使用方法
- 将
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'); } }