mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-27 21:23: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
|
||||
|
||||
# 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"
|
||||
},
|
||||
"classmap": [
|
||||
"app",
|
||||
"packages/Symfony/tests/Rector/FrameworkBundle/AbstractToConstructorInjectionRectorSource",
|
||||
"packages/Symfony/tests/Rector/FrameworkBundle/ContainerGetToConstructorInjectionRector/Source",
|
||||
"packages/NodeTypeResolver/tests/PerNodeTypeResolver/ParamTypeResolver/Source",
|
||||
|
|
|
@ -14,11 +14,16 @@ final class UuidMigrationDataCollector
|
|||
$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'][] = [
|
||||
'property' => $property,
|
||||
'table_name' => $tableName,
|
||||
'current_table_name' => $currentTableName,
|
||||
'uuid_table_name' => $uuidTableName,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Rector\Doctrine\Extension;
|
||||
|
||||
use Nette\Utils\FileSystem;
|
||||
use Nette\Utils\Json;
|
||||
use Rector\Contract\Extension\FinishingExtensionInterface;
|
||||
use Rector\Doctrine\Collector\UuidMigrationDataCollector;
|
||||
|
@ -41,6 +42,11 @@ final class ReportEntitiesWithAddedPropertiesFinishExtension implements Finishin
|
|||
|
||||
$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\Type\IdentifierTypeNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\AttributeAwarePhpDocTagNode;
|
||||
use Rector\Doctrine\Uuid\UuidTableNameResolver;
|
||||
use Rector\Doctrine\Uuid\JoinTableNameResolver;
|
||||
use Rector\Doctrine\ValueObject\DoctrineClass;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\ColumnTagValueNode;
|
||||
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\CustomIdGeneratorTagValueNode;
|
||||
|
@ -24,14 +24,14 @@ final class PhpDocTagNodeFactory
|
|||
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->uuidTableNameResolver = $uuidTableNameResolver;
|
||||
$this->joinTableNameResolver = $joinTableNameResolver;
|
||||
}
|
||||
|
||||
public function createVarTagUuidInterface(): PhpDocTagNode
|
||||
|
@ -78,9 +78,10 @@ final class PhpDocTagNodeFactory
|
|||
|
||||
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')]);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
|||
use Rector\Doctrine\Collector\UuidMigrationDataCollector;
|
||||
use Rector\Doctrine\PhpDocParser\Ast\PhpDoc\PhpDocTagNodeFactory;
|
||||
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\ToManyTagNodeInterface;
|
||||
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToOneTagNodeInterface;
|
||||
|
@ -43,9 +43,9 @@ final class AddUuidMirrorForRelationPropertyRector extends AbstractRector
|
|||
private $uuidMigrationDataCollector;
|
||||
|
||||
/**
|
||||
* @var UuidTableNameResolver
|
||||
* @var JoinTableNameResolver
|
||||
*/
|
||||
private $uuidTableNameResolver;
|
||||
private $joinTableNameResolver;
|
||||
|
||||
/**
|
||||
* @var EntityWithMissingUuidProvider
|
||||
|
@ -56,13 +56,13 @@ final class AddUuidMirrorForRelationPropertyRector extends AbstractRector
|
|||
DocBlockManipulator $docBlockManipulator,
|
||||
PhpDocTagNodeFactory $phpDocTagNodeFactory,
|
||||
UuidMigrationDataCollector $uuidMigrationDataCollector,
|
||||
UuidTableNameResolver $uuidTableNameResolver,
|
||||
JoinTableNameResolver $joinTableNameResolver,
|
||||
EntityWithMissingUuidProvider $entityWithMissingUuidProvider
|
||||
) {
|
||||
$this->docBlockManipulator = $docBlockManipulator;
|
||||
$this->phpDocTagNodeFactory = $phpDocTagNodeFactory;
|
||||
$this->uuidMigrationDataCollector = $uuidMigrationDataCollector;
|
||||
$this->uuidTableNameResolver = $uuidTableNameResolver;
|
||||
$this->joinTableNameResolver = $joinTableNameResolver;
|
||||
$this->entityWithMissingUuidProvider = $entityWithMissingUuidProvider;
|
||||
}
|
||||
|
||||
|
@ -221,13 +221,15 @@ final class AddUuidMirrorForRelationPropertyRector extends AbstractRector
|
|||
/** @var DoctrineRelationTagValueNodeInterface $doctrineRelationTagValueNode */
|
||||
$doctrineRelationTagValueNode = $this->getDoctrineRelationTagValueNode($property);
|
||||
|
||||
$joinTableName = $this->uuidTableNameResolver->resolveManyToManyTableNameForProperty($property);
|
||||
$currentJoinTableName = $this->joinTableNameResolver->resolveManyToManyTableNameForProperty($property);
|
||||
$uuidJoinTableName = $currentJoinTableName . '_uuid';
|
||||
|
||||
if ($doctrineRelationTagValueNode instanceof ToManyTagNodeInterface) {
|
||||
$this->uuidMigrationDataCollector->addClassToManyRelationProperty(
|
||||
$className,
|
||||
$propertyName,
|
||||
$joinTableName
|
||||
$currentJoinTableName,
|
||||
$uuidJoinTableName
|
||||
);
|
||||
} elseif ($doctrineRelationTagValueNode instanceof ToOneTagNodeInterface) {
|
||||
$this->uuidMigrationDataCollector->addClassToOneRelationProperty($className, $propertyName);
|
||||
|
|
|
@ -10,7 +10,7 @@ use Rector\Exception\ShouldNotHappenException;
|
|||
use Rector\NodeContainer\ParsedNodesByType;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
|
||||
final class UuidTableNameResolver
|
||||
final class JoinTableNameResolver
|
||||
{
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ final class UuidTableNameResolver
|
|||
$targetTableName = $this->resolveTableNameFromClass($targetEntityClass);
|
||||
}
|
||||
|
||||
return strtolower($currentTableName . '_' . $targetTableName . '_uuid');
|
||||
return strtolower($currentTableName . '_' . $targetTableName);
|
||||
}
|
||||
|
||||
private function resolveShortClassName(string $currentClass): string
|
Loading…
Reference in New Issue
Block a user