Update to Doctrine Migrations 3.x.

This commit is contained in:
Buster "Silver Eagle" Neece 2020-06-25 03:47:49 -05:00
parent 6f26bcf1f3
commit 0dea2de081
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
6 changed files with 85 additions and 96 deletions

View File

@ -30,7 +30,7 @@
"doctrine/annotations": "^1.6",
"doctrine/data-fixtures": "^1.3",
"doctrine/dbal": "^2.8",
"doctrine/migrations": "^2",
"doctrine/migrations": "^3.0",
"doctrine/orm": "~2.6",
"gettext/gettext": "^4.4",
"guzzlehttp/guzzle": ">6.0",

53
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "33ae14d64a24ebe5d16485f244165473",
"content-hash": "30fb1823a2fd210b7eb08ccbe9bab99c",
"packages": [
{
"name": "aws/aws-sdk-php",
@ -2079,42 +2079,45 @@
},
{
"name": "doctrine/migrations",
"version": "2.2.1",
"version": "3.0.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/migrations.git",
"reference": "a3987131febeb0e9acb3c47ab0df0af004588934"
"reference": "69eaf2ca5bc48357b43ddbdc31ccdffc0e2a0882"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/migrations/zipball/a3987131febeb0e9acb3c47ab0df0af004588934",
"reference": "a3987131febeb0e9acb3c47ab0df0af004588934",
"url": "https://api.github.com/repos/doctrine/migrations/zipball/69eaf2ca5bc48357b43ddbdc31ccdffc0e2a0882",
"reference": "69eaf2ca5bc48357b43ddbdc31ccdffc0e2a0882",
"shasum": ""
},
"require": {
"doctrine/dbal": "^2.9",
"doctrine/dbal": "^2.10",
"doctrine/event-manager": "^1.0",
"ocramius/package-versions": "^1.3",
"ocramius/proxy-manager": "^2.0.2",
"php": "^7.1",
"php": "^7.2",
"psr/log": "^1.1.3",
"symfony/console": "^3.4||^4.0||^5.0",
"symfony/stopwatch": "^3.4||^4.0||^5.0"
},
"require-dev": {
"doctrine/coding-standard": "^6.0",
"doctrine/coding-standard": "^7.0",
"doctrine/orm": "^2.6",
"doctrine/persistence": "^1.3||^2.0",
"doctrine/sql-formatter": "^1.0",
"ext-pdo_sqlite": "*",
"jdorn/sql-formatter": "^1.1",
"mikey179/vfsstream": "^1.6",
"phpstan/phpstan": "^0.10",
"phpstan/phpstan-deprecation-rules": "^0.10",
"phpstan/phpstan-phpunit": "^0.10",
"phpstan/phpstan-strict-rules": "^0.10",
"phpunit/phpunit": "^7.0",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-deprecation-rules": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"phpstan/phpstan-symfony": "^0.12",
"phpunit/phpunit": "^8.4",
"symfony/process": "^3.4||^4.0||^5.0",
"symfony/yaml": "^3.4||^4.0||^5.0"
},
"suggest": {
"jdorn/sql-formatter": "Allows to generate formatted SQL with the diff command.",
"doctrine/sql-formatter": "Allows to generate formatted SQL with the diff command.",
"symfony/yaml": "Allows the use of yaml for migration configuration files."
},
"bin": [
@ -2123,7 +2126,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.2.x-dev"
"dev-master": "3.0.x-dev"
}
},
"autoload": {
@ -2157,7 +2160,21 @@
"migrations",
"php"
],
"time": "2019-12-04T06:09:14+00:00"
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fmigrations",
"type": "tidelift"
}
],
"time": "2020-06-21T08:55:42+00:00"
},
{
"name": "doctrine/orm",

View File

@ -23,35 +23,28 @@ return function (\App\EventDispatcher $dispatcher) {
Doctrine\ORM\Tools\Console\ConsoleRunner::addCommands($console);
// Add Doctrine Migrations
$defaults = [
'table_name' => 'app_migrations',
'directory' => $settings[Settings::BASE_DIR] . '/src/Entity/Migration',
'namespace' => 'App\Entity\Migration',
];
$user_options = $settings[Settings::DOCTRINE_OPTIONS]['migrations'] ?? [];
$options = array_merge($defaults, $user_options);
/** @var Doctrine\ORM\EntityManager $em */
$em = $di->get(Doctrine\ORM\EntityManager::class);
$connection = $em->getConnection();
$helper_set = $console->getHelperSet();
$doctrine_helpers = Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($em);
$helper_set->set($doctrine_helpers->get('db'), 'db');
$helper_set->set($doctrine_helpers->get('em'), 'em');
$migrate_config = new Doctrine\Migrations\Configuration\Configuration($connection);
$migrate_config->setMigrationsTableName($options['table_name']);
$migrate_config->setMigrationsDirectory($options['directory']);
$migrate_config->setMigrationsNamespace($options['namespace']);
$migrateConfig = new Doctrine\Migrations\Configuration\Migration\ConfigurationArray([
'migrations_paths' => [
'App\Entity\Migration' => $settings[Settings::BASE_DIR] . '/src/Entity/Migration',
],
'table_storage' => [
'table_name' => 'app_migrations',
],
]);
$migrate_config_helper = new Doctrine\Migrations\Tools\Console\Helper\ConfigurationHelper($connection,
$migrate_config);
$helper_set->set($migrate_config_helper, 'configuration');
Doctrine\Migrations\Tools\Console\ConsoleRunner::addCommands($console);
$migrateFactory = Doctrine\Migrations\DependencyFactory::fromEntityManager(
$migrateConfig,
new Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager($em)
);
Doctrine\Migrations\Tools\Console\ConsoleRunner::addCommands($console, $migrateFactory);
}
call_user_func(include(__DIR__ . '/cli.php'), $console);

View File

@ -56,76 +56,55 @@ return [
// Doctrine Entity Manager
Doctrine\ORM\EntityManager::class => function (
Doctrine\Common\Cache\Cache $doctrine_cache,
Doctrine\Common\Cache\Cache $doctrineCache,
Doctrine\Common\Annotations\Reader $reader,
App\Settings $settings,
App\Doctrine\Event\StationRequiresRestart $eventRequiresRestart,
App\Doctrine\Event\AuditLog $eventAuditLog
) {
$defaults = [
'cache' => $doctrine_cache,
'autoGenerateProxies' => !$settings->isProduction(),
'proxyNamespace' => 'AppProxy',
'proxyPath' => $settings->getTempDirectory() . '/proxies',
'modelPath' => $settings->getBaseDirectory() . '/src/Entity',
'useSimpleAnnotations' => false,
'conn' => [
'host' => $_ENV['MYSQL_HOST'] ?? 'mariadb',
'port' => $_ENV['MYSQL_PORT'] ?? 3306,
'dbname' => $_ENV['MYSQL_DATABASE'],
'user' => $_ENV['MYSQL_USER'],
'password' => $_ENV['MYSQL_PASSWORD'],
'driver' => 'pdo_mysql',
$connectionOptions = [
'host' => $_ENV['MYSQL_HOST'] ?? 'mariadb',
'port' => $_ENV['MYSQL_PORT'] ?? 3306,
'dbname' => $_ENV['MYSQL_DATABASE'],
'user' => $_ENV['MYSQL_USER'],
'password' => $_ENV['MYSQL_PASSWORD'],
'driver' => 'pdo_mysql',
'charset' => 'utf8mb4',
'defaultTableOptions' => [
'charset' => 'utf8mb4',
'defaultTableOptions' => [
'charset' => 'utf8mb4',
'collate' => 'utf8mb4_general_ci',
],
'driverOptions' => [
// PDO::MYSQL_ATTR_INIT_COMMAND = 1002;
1002 => 'SET NAMES utf8mb4 COLLATE utf8mb4_general_ci',
],
'platform' => new Doctrine\DBAL\Platforms\MariaDb1027Platform(),
'collate' => 'utf8mb4_general_ci',
],
'driverOptions' => [
// PDO::MYSQL_ATTR_INIT_COMMAND = 1002;
1002 => 'SET NAMES utf8mb4 COLLATE utf8mb4_general_ci',
],
'platform' => new Doctrine\DBAL\Platforms\MariaDb1027Platform(),
];
if (!$settings[App\Settings::IS_DOCKER]) {
$defaults['conn']['host'] = $_ENV['db_host'] ?? 'localhost';
$defaults['conn']['port'] = $_ENV['db_port'] ?? '3306';
$defaults['conn']['dbname'] = $_ENV['db_name'] ?? 'azuracast';
$defaults['conn']['user'] = $_ENV['db_username'] ?? 'azuracast';
$defaults['conn']['password'] = $_ENV['db_password'];
$connectionOptions['host'] = $_ENV['db_host'] ?? 'localhost';
$connectionOptions['port'] = $_ENV['db_port'] ?? '3306';
$connectionOptions['dbname'] = $_ENV['db_name'] ?? 'azuracast';
$connectionOptions['user'] = $_ENV['db_username'] ?? 'azuracast';
$connectionOptions['password'] = $_ENV['db_password'];
}
$app_options = $settings[App\Settings::DOCTRINE_OPTIONS] ?? [];
$options = array_merge($defaults, $app_options);
try {
// Fetch and store entity manager.
$config = new Doctrine\ORM\Configuration;
$config = \Doctrine\ORM\Tools\Setup::createConfiguration(
Doctrine\Common\Proxy\AbstractProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS,
$settings->getTempDirectory() . '/proxies',
$doctrineCache
);
if ($options['useSimpleAnnotations']) {
$metadata_driver = $config->newDefaultAnnotationDriver((array)$options['modelPath'],
$options['useSimpleAnnotations']);
} else {
$metadata_driver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver(
$reader,
(array)$options['modelPath']
);
}
$config->setMetadataDriverImpl($metadata_driver);
$annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver(
$reader,
[$settings->getBaseDirectory() . '/src/Entity']
);
$config->setMetadataDriverImpl($annotationDriver);
$config->setMetadataCacheImpl($options['cache']);
$config->setQueryCacheImpl($options['cache']);
$config->setResultCacheImpl($options['cache']);
$config->setProxyDir($options['proxyPath']);
$config->setProxyNamespace($options['proxyNamespace']);
$config->setAutoGenerateProxyClasses(Doctrine\Common\Proxy\AbstractProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS);
if (isset($options['conn']['debug']) && $options['conn']['debug']) {
$config->setSQLLogger(new Doctrine\DBAL\Logging\EchoSQLLogger);
}
// Debug mode:
// $config->setSQLLogger(new Doctrine\DBAL\Logging\EchoSQLLogger);
$config->addCustomNumericFunction('RAND', App\Doctrine\Functions\Rand::class);
@ -133,7 +112,7 @@ return [
$eventManager->addEventSubscriber($eventRequiresRestart);
$eventManager->addEventSubscriber($eventAuditLog);
return Doctrine\ORM\EntityManager::create($options['conn'], $config, $eventManager);
return Doctrine\ORM\EntityManager::create($connectionOptions, $config, $eventManager);
} catch (Exception $e) {
throw new App\Exception\BootstrapException($e->getMessage());
}

View File

@ -1,4 +1,4 @@
<?php //[STAMP] 9b41b0db9e61d4ba9485515e72bd57d5
<?php //[STAMP] 92e19f77305b46463f217dcbd3e2b8eb
namespace _generated;
// This class was automatically generated by build task

View File

@ -1,4 +1,4 @@
<?php //[STAMP] b52e4ffd1eac82e3a1b7d8c495f5aca3
<?php //[STAMP] 686236301b61c9586400be10904453f0
namespace _generated;
// This class was automatically generated by build task