mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-30 06:33:31 +00:00
report old and new table
This commit is contained in:
parent
a618c07a50
commit
160c9a6413
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -14,4 +14,6 @@ phpstan-dependencies.json
|
||||||
phpstan-paths.txt
|
phpstan-paths.txt
|
||||||
|
|
||||||
# tests - travis
|
# tests - travis
|
||||||
/laravel-dir
|
/laravel-dir
|
||||||
|
|
||||||
|
uuid-migration.json
|
|
@ -1,18 +0,0 @@
|
||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Rector\App;
|
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\Entity
|
|
||||||
*/
|
|
||||||
class EntityWithRelation
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @ORM\ManyToOne(targetEntity="Rector\App\SomeEntityWithIntegerId", cascade={"persist", "merge"})
|
|
||||||
* @ORM\JoinColumn(nullable=false)
|
|
||||||
*/
|
|
||||||
private $amenity;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Rector\App;
|
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\Entity
|
|
||||||
*/
|
|
||||||
class SomeEntityWithIntegerId
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
* @ORM\Id
|
|
||||||
* @ORM\Column(type="integer")
|
|
||||||
* @ORM\GeneratedValue(strategy="AUTO")
|
|
||||||
*/
|
|
||||||
private $id;
|
|
||||||
}
|
|
|
@ -134,7 +134,6 @@
|
||||||
"Rector\\TypeDeclaration\\Tests\\": "packages/TypeDeclaration/tests"
|
"Rector\\TypeDeclaration\\Tests\\": "packages/TypeDeclaration/tests"
|
||||||
},
|
},
|
||||||
"classmap": [
|
"classmap": [
|
||||||
"app",
|
|
||||||
"packages/Symfony/tests/Rector/FrameworkBundle/AbstractToConstructorInjectionRectorSource",
|
"packages/Symfony/tests/Rector/FrameworkBundle/AbstractToConstructorInjectionRectorSource",
|
||||||
"packages/Symfony/tests/Rector/FrameworkBundle/ContainerGetToConstructorInjectionRector/Source",
|
"packages/Symfony/tests/Rector/FrameworkBundle/ContainerGetToConstructorInjectionRector/Source",
|
||||||
"packages/NodeTypeResolver/tests/PerNodeTypeResolver/ParamTypeResolver/Source",
|
"packages/NodeTypeResolver/tests/PerNodeTypeResolver/ParamTypeResolver/Source",
|
||||||
|
|
|
@ -14,11 +14,16 @@ final class UuidMigrationDataCollector
|
||||||
$this->propertiesByClass[$class]['properties'][] = $property;
|
$this->propertiesByClass[$class]['properties'][] = $property;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addClassToManyRelationProperty(string $class, string $property, string $tableName): void
|
public function addClassToManyRelationProperty(
|
||||||
{
|
string $class,
|
||||||
|
string $property,
|
||||||
|
string $currentTableName,
|
||||||
|
string $uuidTableName
|
||||||
|
): void {
|
||||||
$this->propertiesByClass[$class]['to_many_relations'][] = [
|
$this->propertiesByClass[$class]['to_many_relations'][] = [
|
||||||
'property' => $property,
|
'property' => $property,
|
||||||
'table_name' => $tableName,
|
'current_table_name' => $currentTableName,
|
||||||
|
'uuid_table_name' => $uuidTableName,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Rector\Doctrine\Extension;
|
namespace Rector\Doctrine\Extension;
|
||||||
|
|
||||||
|
use Nette\Utils\FileSystem;
|
||||||
use Nette\Utils\Json;
|
use Nette\Utils\Json;
|
||||||
use Rector\Contract\Extension\FinishingExtensionInterface;
|
use Rector\Contract\Extension\FinishingExtensionInterface;
|
||||||
use Rector\Doctrine\Collector\UuidMigrationDataCollector;
|
use Rector\Doctrine\Collector\UuidMigrationDataCollector;
|
||||||
|
@ -41,6 +42,11 @@ final class ReportEntitiesWithAddedPropertiesFinishExtension implements Finishin
|
||||||
|
|
||||||
$jsonContent = Json::encode($data, Json::PRETTY);
|
$jsonContent = Json::encode($data, Json::PRETTY);
|
||||||
|
|
||||||
$this->symfonyStyle->writeln($jsonContent);
|
$filePath = getcwd() . '/uuid-migration.json';
|
||||||
|
FileSystem::write($filePath, $jsonContent);
|
||||||
|
|
||||||
|
$this->symfonyStyle->warning(
|
||||||
|
'See freshly created "uuid-migration.json" file for changes on entities and further SQL migration steps'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||||
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
|
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
|
||||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||||
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\AttributeAwarePhpDocTagNode;
|
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\AttributeAwarePhpDocTagNode;
|
||||||
use Rector\Doctrine\Uuid\UuidTableNameResolver;
|
use Rector\Doctrine\Uuid\JoinTableNameResolver;
|
||||||
use Rector\Doctrine\ValueObject\DoctrineClass;
|
use Rector\Doctrine\ValueObject\DoctrineClass;
|
||||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\ColumnTagValueNode;
|
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\ColumnTagValueNode;
|
||||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\CustomIdGeneratorTagValueNode;
|
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\CustomIdGeneratorTagValueNode;
|
||||||
|
@ -24,14 +24,14 @@ final class PhpDocTagNodeFactory
|
||||||
private $doctrineUuidGeneratorClass;
|
private $doctrineUuidGeneratorClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var UuidTableNameResolver
|
* @var JoinTableNameResolver
|
||||||
*/
|
*/
|
||||||
private $uuidTableNameResolver;
|
private $joinTableNameResolver;
|
||||||
|
|
||||||
public function __construct(string $doctrineUuidGeneratorClass, UuidTableNameResolver $uuidTableNameResolver)
|
public function __construct(string $doctrineUuidGeneratorClass, JoinTableNameResolver $joinTableNameResolver)
|
||||||
{
|
{
|
||||||
$this->doctrineUuidGeneratorClass = $doctrineUuidGeneratorClass;
|
$this->doctrineUuidGeneratorClass = $doctrineUuidGeneratorClass;
|
||||||
$this->uuidTableNameResolver = $uuidTableNameResolver;
|
$this->joinTableNameResolver = $joinTableNameResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createVarTagUuidInterface(): PhpDocTagNode
|
public function createVarTagUuidInterface(): PhpDocTagNode
|
||||||
|
@ -78,9 +78,10 @@ final class PhpDocTagNodeFactory
|
||||||
|
|
||||||
public function createJoinTableTagNode(Property $property): PhpDocTagNode
|
public function createJoinTableTagNode(Property $property): PhpDocTagNode
|
||||||
{
|
{
|
||||||
$joinTableName = $this->uuidTableNameResolver->resolveManyToManyTableNameForProperty($property);
|
$joinTableName = $this->joinTableNameResolver->resolveManyToManyTableNameForProperty($property);
|
||||||
|
$uuidJoinTable = $joinTableName . '_uuid';
|
||||||
|
|
||||||
$joinTableTagValueNode = new JoinTableTagValueNode($joinTableName, null, [
|
$joinTableTagValueNode = new JoinTableTagValueNode($uuidJoinTable, null, [
|
||||||
new JoinColumnTagValueNode(null, 'uuid'),
|
new JoinColumnTagValueNode(null, 'uuid'),
|
||||||
], [new JoinColumnTagValueNode(null, 'uuid')]);
|
], [new JoinColumnTagValueNode(null, 'uuid')]);
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||||
use Rector\Doctrine\Collector\UuidMigrationDataCollector;
|
use Rector\Doctrine\Collector\UuidMigrationDataCollector;
|
||||||
use Rector\Doctrine\PhpDocParser\Ast\PhpDoc\PhpDocTagNodeFactory;
|
use Rector\Doctrine\PhpDocParser\Ast\PhpDoc\PhpDocTagNodeFactory;
|
||||||
use Rector\Doctrine\Provider\EntityWithMissingUuidProvider;
|
use Rector\Doctrine\Provider\EntityWithMissingUuidProvider;
|
||||||
use Rector\Doctrine\Uuid\UuidTableNameResolver;
|
use Rector\Doctrine\Uuid\JoinTableNameResolver;
|
||||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\DoctrineRelationTagValueNodeInterface;
|
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\DoctrineRelationTagValueNodeInterface;
|
||||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToManyTagNodeInterface;
|
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToManyTagNodeInterface;
|
||||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToOneTagNodeInterface;
|
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToOneTagNodeInterface;
|
||||||
|
@ -43,9 +43,9 @@ final class AddUuidMirrorForRelationPropertyRector extends AbstractRector
|
||||||
private $uuidMigrationDataCollector;
|
private $uuidMigrationDataCollector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var UuidTableNameResolver
|
* @var JoinTableNameResolver
|
||||||
*/
|
*/
|
||||||
private $uuidTableNameResolver;
|
private $joinTableNameResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var EntityWithMissingUuidProvider
|
* @var EntityWithMissingUuidProvider
|
||||||
|
@ -56,13 +56,13 @@ final class AddUuidMirrorForRelationPropertyRector extends AbstractRector
|
||||||
DocBlockManipulator $docBlockManipulator,
|
DocBlockManipulator $docBlockManipulator,
|
||||||
PhpDocTagNodeFactory $phpDocTagNodeFactory,
|
PhpDocTagNodeFactory $phpDocTagNodeFactory,
|
||||||
UuidMigrationDataCollector $uuidMigrationDataCollector,
|
UuidMigrationDataCollector $uuidMigrationDataCollector,
|
||||||
UuidTableNameResolver $uuidTableNameResolver,
|
JoinTableNameResolver $joinTableNameResolver,
|
||||||
EntityWithMissingUuidProvider $entityWithMissingUuidProvider
|
EntityWithMissingUuidProvider $entityWithMissingUuidProvider
|
||||||
) {
|
) {
|
||||||
$this->docBlockManipulator = $docBlockManipulator;
|
$this->docBlockManipulator = $docBlockManipulator;
|
||||||
$this->phpDocTagNodeFactory = $phpDocTagNodeFactory;
|
$this->phpDocTagNodeFactory = $phpDocTagNodeFactory;
|
||||||
$this->uuidMigrationDataCollector = $uuidMigrationDataCollector;
|
$this->uuidMigrationDataCollector = $uuidMigrationDataCollector;
|
||||||
$this->uuidTableNameResolver = $uuidTableNameResolver;
|
$this->joinTableNameResolver = $joinTableNameResolver;
|
||||||
$this->entityWithMissingUuidProvider = $entityWithMissingUuidProvider;
|
$this->entityWithMissingUuidProvider = $entityWithMissingUuidProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,13 +221,15 @@ final class AddUuidMirrorForRelationPropertyRector extends AbstractRector
|
||||||
/** @var DoctrineRelationTagValueNodeInterface $doctrineRelationTagValueNode */
|
/** @var DoctrineRelationTagValueNodeInterface $doctrineRelationTagValueNode */
|
||||||
$doctrineRelationTagValueNode = $this->getDoctrineRelationTagValueNode($property);
|
$doctrineRelationTagValueNode = $this->getDoctrineRelationTagValueNode($property);
|
||||||
|
|
||||||
$joinTableName = $this->uuidTableNameResolver->resolveManyToManyTableNameForProperty($property);
|
$currentJoinTableName = $this->joinTableNameResolver->resolveManyToManyTableNameForProperty($property);
|
||||||
|
$uuidJoinTableName = $currentJoinTableName . '_uuid';
|
||||||
|
|
||||||
if ($doctrineRelationTagValueNode instanceof ToManyTagNodeInterface) {
|
if ($doctrineRelationTagValueNode instanceof ToManyTagNodeInterface) {
|
||||||
$this->uuidMigrationDataCollector->addClassToManyRelationProperty(
|
$this->uuidMigrationDataCollector->addClassToManyRelationProperty(
|
||||||
$className,
|
$className,
|
||||||
$propertyName,
|
$propertyName,
|
||||||
$joinTableName
|
$currentJoinTableName,
|
||||||
|
$uuidJoinTableName
|
||||||
);
|
);
|
||||||
} elseif ($doctrineRelationTagValueNode instanceof ToOneTagNodeInterface) {
|
} elseif ($doctrineRelationTagValueNode instanceof ToOneTagNodeInterface) {
|
||||||
$this->uuidMigrationDataCollector->addClassToOneRelationProperty($className, $propertyName);
|
$this->uuidMigrationDataCollector->addClassToOneRelationProperty($className, $propertyName);
|
||||||
|
|
|
@ -10,7 +10,7 @@ use Rector\Exception\ShouldNotHappenException;
|
||||||
use Rector\NodeContainer\ParsedNodesByType;
|
use Rector\NodeContainer\ParsedNodesByType;
|
||||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||||
|
|
||||||
final class UuidTableNameResolver
|
final class JoinTableNameResolver
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var DoctrineDocBlockResolver
|
* @var DoctrineDocBlockResolver
|
||||||
|
@ -31,7 +31,7 @@ final class UuidTableNameResolver
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates unique many-to-many table name like: first_table_uuid_second_table_uuid
|
* Guessed many-to-many table name like: first_table_second_table
|
||||||
*/
|
*/
|
||||||
public function resolveManyToManyTableNameForProperty(Property $property): string
|
public function resolveManyToManyTableNameForProperty(Property $property): string
|
||||||
{
|
{
|
||||||
|
@ -52,7 +52,7 @@ final class UuidTableNameResolver
|
||||||
$targetTableName = $this->resolveTableNameFromClass($targetEntityClass);
|
$targetTableName = $this->resolveTableNameFromClass($targetEntityClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
return strtolower($currentTableName . '_' . $targetTableName . '_uuid');
|
return strtolower($currentTableName . '_' . $targetTableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function resolveShortClassName(string $currentClass): string
|
private function resolveShortClassName(string $currentClass): string
|
Loading…
Reference in New Issue
Block a user