init
This commit is contained in:
56
backend/vendor/doctrine/migrations/src/Provider/DBALSchemaDiffProvider.php
vendored
Normal file
56
backend/vendor/doctrine/migrations/src/Provider/DBALSchemaDiffProvider.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Migrations\Provider;
|
||||
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Schema\AbstractSchemaManager;
|
||||
use Doctrine\DBAL\Schema\ComparatorConfig;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
use function class_exists;
|
||||
|
||||
/**
|
||||
* The SchemaDiffProvider class is responsible for providing a Doctrine\DBAL\Schema\Schema instance that
|
||||
* represents the current state of your database. A clone of this Schema instance is passed to each of your migrations
|
||||
* so that you can manipulate the Schema object. Your manipulated Schema object is then compared to the original Schema
|
||||
* object to produce the SQL statements that need to be executed.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @see Doctrine\Migrations\Version\DbalExecutor
|
||||
*/
|
||||
class DBALSchemaDiffProvider implements SchemaDiffProvider
|
||||
{
|
||||
/** @param AbstractSchemaManager<AbstractPlatform> $schemaManager- */
|
||||
public function __construct(
|
||||
private readonly AbstractSchemaManager $schemaManager,
|
||||
private readonly AbstractPlatform $platform,
|
||||
) {
|
||||
}
|
||||
|
||||
public function createFromSchema(): Schema
|
||||
{
|
||||
return $this->schemaManager->introspectSchema();
|
||||
}
|
||||
|
||||
public function createToSchema(Schema $fromSchema): Schema
|
||||
{
|
||||
return clone $fromSchema;
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getSqlDiffToMigrate(Schema $fromSchema, Schema $toSchema): array
|
||||
{
|
||||
if (class_exists(ComparatorConfig::class)) {
|
||||
$comparator = $this->schemaManager->createComparator((new ComparatorConfig())->withReportModifiedIndexes(false));
|
||||
} else {
|
||||
$comparator = $this->schemaManager->createComparator();
|
||||
}
|
||||
|
||||
return $this->platform->getAlterSchemaSQL(
|
||||
$comparator->compareSchemas($fromSchema, $toSchema),
|
||||
);
|
||||
}
|
||||
}
|
||||
28
backend/vendor/doctrine/migrations/src/Provider/EmptySchemaProvider.php
vendored
Normal file
28
backend/vendor/doctrine/migrations/src/Provider/EmptySchemaProvider.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Migrations\Provider;
|
||||
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Schema\AbstractSchemaManager;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* The EmptySchemaProvider class is responsible for creating a Doctrine\DBAL\Schema\Schema instance that
|
||||
* represents the empty state of your database.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class EmptySchemaProvider implements SchemaProvider
|
||||
{
|
||||
/** @param AbstractSchemaManager<AbstractPlatform> $schemaManager */
|
||||
public function __construct(private readonly AbstractSchemaManager $schemaManager)
|
||||
{
|
||||
}
|
||||
|
||||
public function createSchema(): Schema
|
||||
{
|
||||
return new Schema([], [], $this->schemaManager->createSchemaConfig());
|
||||
}
|
||||
}
|
||||
15
backend/vendor/doctrine/migrations/src/Provider/Exception/NoMappingFound.php
vendored
Normal file
15
backend/vendor/doctrine/migrations/src/Provider/Exception/NoMappingFound.php
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Migrations\Provider\Exception;
|
||||
|
||||
use UnexpectedValueException;
|
||||
|
||||
final class NoMappingFound extends UnexpectedValueException implements ProviderException
|
||||
{
|
||||
public static function new(): self
|
||||
{
|
||||
return new self('No mapping information to process');
|
||||
}
|
||||
}
|
||||
11
backend/vendor/doctrine/migrations/src/Provider/Exception/ProviderException.php
vendored
Normal file
11
backend/vendor/doctrine/migrations/src/Provider/Exception/ProviderException.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Migrations\Provider\Exception;
|
||||
|
||||
use Doctrine\Migrations\Exception\MigrationException;
|
||||
|
||||
interface ProviderException extends MigrationException
|
||||
{
|
||||
}
|
||||
18
backend/vendor/doctrine/migrations/src/Provider/LazySchema.php
vendored
Normal file
18
backend/vendor/doctrine/migrations/src/Provider/LazySchema.php
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Migrations\Provider;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Symfony\Component\VarExporter\LazyProxyTrait;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @phpstan-ignore class.extendsFinalByPhpDoc
|
||||
*/
|
||||
class LazySchema extends Schema
|
||||
{
|
||||
use LazyProxyTrait;
|
||||
}
|
||||
92
backend/vendor/doctrine/migrations/src/Provider/LazySchemaDiffProvider.php
vendored
Normal file
92
backend/vendor/doctrine/migrations/src/Provider/LazySchemaDiffProvider.php
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Migrations\Provider;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use ReflectionClass;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
/**
|
||||
* The LazySchemaDiffProvider is responsible for lazily generating the from schema when diffing two schemas
|
||||
* to produce a migration.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class LazySchemaDiffProvider implements SchemaDiffProvider
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SchemaDiffProvider $originalSchemaManipulator,
|
||||
) {
|
||||
}
|
||||
|
||||
public function createFromSchema(): Schema
|
||||
{
|
||||
$originalSchemaManipulator = $this->originalSchemaManipulator;
|
||||
|
||||
if (PHP_VERSION_ID < 80400) {
|
||||
/** @phpstan-ignore staticMethod.notFound */
|
||||
return LazySchema::createLazyProxy(static fn () => $originalSchemaManipulator->createFromSchema());
|
||||
}
|
||||
|
||||
$reflector = new ReflectionClass(Schema::class);
|
||||
|
||||
return $reflector->newLazyProxy(
|
||||
static fn () => $originalSchemaManipulator->createFromSchema(),
|
||||
);
|
||||
}
|
||||
|
||||
public function createToSchema(Schema $fromSchema): Schema
|
||||
{
|
||||
$originalSchemaManipulator = $this->originalSchemaManipulator;
|
||||
|
||||
/** @phpstan-ignore method.notFound */
|
||||
if ($fromSchema instanceof LazySchema && ! $fromSchema->isLazyObjectInitialized()) {
|
||||
/** @phpstan-ignore staticMethod.notFound */
|
||||
return LazySchema::createLazyProxy(static fn () => $originalSchemaManipulator->createToSchema($fromSchema));
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
$reflector = new ReflectionClass(Schema::class);
|
||||
|
||||
if ($reflector->isUninitializedLazyObject($fromSchema)) {
|
||||
return $reflector->newLazyProxy(
|
||||
static function () use ($originalSchemaManipulator, $fromSchema, $reflector) {
|
||||
/* $this->originalSchemaManipulator may return a lazy
|
||||
* object, for instance DBALSchemaDiffProvider just clones $fromSchema,
|
||||
* which we know is lazy at this point of execution */
|
||||
return $reflector->initializeLazyObject(
|
||||
$originalSchemaManipulator->createToSchema($fromSchema),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->originalSchemaManipulator->createToSchema($fromSchema);
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getSqlDiffToMigrate(Schema $fromSchema, Schema $toSchema): array
|
||||
{
|
||||
if (
|
||||
$toSchema instanceof LazySchema
|
||||
/** @phpstan-ignore method.notFound */
|
||||
&& ! $toSchema->isLazyObjectInitialized()
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID >= 80400) {
|
||||
$reflector = new ReflectionClass(Schema::class);
|
||||
|
||||
if ($reflector->isUninitializedLazyObject($toSchema)) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->originalSchemaManipulator->getSqlDiffToMigrate($fromSchema, $toSchema);
|
||||
}
|
||||
}
|
||||
41
backend/vendor/doctrine/migrations/src/Provider/OrmSchemaProvider.php
vendored
Normal file
41
backend/vendor/doctrine/migrations/src/Provider/OrmSchemaProvider.php
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Migrations\Provider;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
|
||||
use function usort;
|
||||
|
||||
/**
|
||||
* The OrmSchemaProvider class is responsible for creating a Doctrine\DBAL\Schema\Schema instance from the mapping
|
||||
* information provided by the Doctrine ORM. This is then used to diff against your current database schema to produce
|
||||
* a migration to bring your database in sync with the ORM mapping information.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class OrmSchemaProvider implements SchemaProvider
|
||||
{
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->entityManager = $em;
|
||||
}
|
||||
|
||||
public function createSchema(): Schema
|
||||
{
|
||||
/** @var array<int, ClassMetadata<object>> $metadata */
|
||||
$metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
|
||||
|
||||
usort($metadata, static fn (ClassMetadata $a, ClassMetadata $b): int => $a->getTableName() <=> $b->getTableName());
|
||||
|
||||
$tool = new SchemaTool($this->entityManager);
|
||||
|
||||
return $tool->getSchemaFromMetadata($metadata);
|
||||
}
|
||||
}
|
||||
23
backend/vendor/doctrine/migrations/src/Provider/SchemaDiffProvider.php
vendored
Normal file
23
backend/vendor/doctrine/migrations/src/Provider/SchemaDiffProvider.php
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Migrations\Provider;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* The SchemaDiffProvider defines the interface used to provide the from and to schemas and to produce
|
||||
* the SQL queries needed to migrate.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
interface SchemaDiffProvider
|
||||
{
|
||||
public function createFromSchema(): Schema;
|
||||
|
||||
public function createToSchema(Schema $fromSchema): Schema;
|
||||
|
||||
/** @return string[] */
|
||||
public function getSqlDiffToMigrate(Schema $fromSchema, Schema $toSchema): array;
|
||||
}
|
||||
16
backend/vendor/doctrine/migrations/src/Provider/SchemaProvider.php
vendored
Normal file
16
backend/vendor/doctrine/migrations/src/Provider/SchemaProvider.php
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Migrations\Provider;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* The SchemaProvider defines the interface used to create a Doctrine\DBAL\Schema\Schema instance that
|
||||
* represents the current state of your database.
|
||||
*/
|
||||
interface SchemaProvider
|
||||
{
|
||||
public function createSchema(): Schema;
|
||||
}
|
||||
26
backend/vendor/doctrine/migrations/src/Provider/StubSchemaProvider.php
vendored
Normal file
26
backend/vendor/doctrine/migrations/src/Provider/StubSchemaProvider.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Migrations\Provider;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* The StubSchemaProvider takes a Doctrine\DBAL\Schema\Schema instance through the constructor and returns it
|
||||
* from the createSchema() method.
|
||||
*/
|
||||
final class StubSchemaProvider implements SchemaProvider
|
||||
{
|
||||
private Schema $toSchema;
|
||||
|
||||
public function __construct(Schema $schema)
|
||||
{
|
||||
$this->toSchema = $schema;
|
||||
}
|
||||
|
||||
public function createSchema(): Schema
|
||||
{
|
||||
return $this->toSchema;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user