|
|
@@ -3,9 +3,7 @@ declare(strict_types=1);
|
|
|
|
|
|
namespace App\Service\Doctrine;
|
|
|
|
|
|
-use App\Entity\Access\Access;
|
|
|
use App\Service\ApiLegacy\ApiLegacyRequestService;
|
|
|
-use App\Service\Rest\ApiRequestService;
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
use Doctrine\ORM\Mapping\MappingException;
|
|
|
|
|
|
@@ -18,13 +16,18 @@ use Doctrine\ORM\Mapping\MappingException;
|
|
|
class SchemaValidationService
|
|
|
{
|
|
|
public function __construct(
|
|
|
- private EntityManagerInterface $entityManager, private readonly ApiRequestService $apiRequestService, private readonly ApiLegacyRequestService $apiLegacyRequestService,
|
|
|
+ private EntityManagerInterface $entityManager,
|
|
|
+ private readonly ApiLegacyRequestService $apiLegacyRequestService,
|
|
|
)
|
|
|
{}
|
|
|
|
|
|
public function validateSchema() {
|
|
|
$schemaV1 = $this->getV1Schema();
|
|
|
$schemaV2 = $this->getV2Schema();
|
|
|
+
|
|
|
+ $diff = $this->getDiff($schemaV1, $schemaV2);
|
|
|
+
|
|
|
+ dd($diff);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -39,14 +42,14 @@ class SchemaValidationService
|
|
|
$schema = [];
|
|
|
|
|
|
foreach ($metadata as $entityMetadata) {
|
|
|
- $schema[$entityMetadata->getName()] = [];
|
|
|
+ $schema[$entityMetadata->getTableName()] = [];
|
|
|
|
|
|
foreach ($entityMetadata->getFieldNames() as $field) {
|
|
|
- $schema[$entityMetadata->getName()][$field] = $entityMetadata->getTypeOfField($field);
|
|
|
+ $schema[$entityMetadata->getTableName()][$field] = $entityMetadata->getTypeOfField($field);
|
|
|
}
|
|
|
|
|
|
foreach ($entityMetadata->getAssociationNames() as $association) {
|
|
|
- $schema[$entityMetadata->getName()][$association] = $entityMetadata->getAssociationMapping($association);
|
|
|
+ $schema[$entityMetadata->getTableName()][$association] = $entityMetadata->getAssociationMapping($association);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -55,23 +58,44 @@ class SchemaValidationService
|
|
|
|
|
|
/**
|
|
|
* Retrieve the V1 schema
|
|
|
- * @return void
|
|
|
*/
|
|
|
- protected function getV1Schema() {
|
|
|
+ protected function getV1Schema(): array {
|
|
|
$response = $this->apiLegacyRequestService->get('/_internal/doctrine/schema');
|
|
|
|
|
|
- $schema = json_decode($response->getContent(), true);
|
|
|
-
|
|
|
- dd($schema);
|
|
|
-
|
|
|
- return $schema;
|
|
|
+ return json_decode($response->getContent(), true);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get a list of differences between V1 and V2 doctrine schemas
|
|
|
* @return void
|
|
|
*/
|
|
|
- protected function getDiff() {
|
|
|
+ protected function getDiff(array $schemaV1, array $schemaV2): array {
|
|
|
+ $diff = [
|
|
|
+ 'missing-entity' => [],
|
|
|
+ 'entities' => []
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach ($schemaV1 as $entity => $fields) {
|
|
|
+ if (!isset($schemaV2[$entity])) {
|
|
|
+ $diff['missing-entity'][] = $entity;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $diff['entities'][$entity] = [];
|
|
|
+
|
|
|
+ foreach ($fields as $field => $type) {
|
|
|
+ if (!isset($schemaV2[$entity][$field])) {
|
|
|
+ $diff['entities'][$entity][$field] = 'missing';
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($schemaV2[$entity][$field] !== $type) {
|
|
|
+ $diff['entities'][$entity][$field] = 'type-diff';
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ return $diff;
|
|
|
}
|
|
|
}
|