Updated to doctrine migrations 3.0.

This commit is contained in:
Jan Böhmer 2020-07-04 23:38:18 +02:00
parent c3d22556a0
commit 96acf0d858
16 changed files with 394 additions and 342 deletions

620
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
doctrine_migrations:
dir_name: '%kernel.project_dir%/src/Migrations'
migrations_paths:
# namespace is arbitrary but should be different from App\Migrations
# as migrations classes should NOT be autoloaded
namespace: DoctrineMigrations
'DoctrineMigrations': '%kernel.project_dir%/migrations'

View file

@ -39,6 +39,9 @@ services:
Swap\Swap:
alias: 'florianv_swap.swap'
Doctrine\Migrations\DependencyFactory:
alias: 'doctrine.migrations.dependency_factory'
####################################################################################################################
# Email
####################################################################################################################

0
migrations/.gitignore vendored Normal file
View file

View file

@ -22,10 +22,8 @@ declare(strict_types=1);
namespace DoctrineMigrations;
use App\Migrations\AbstractMultiPlatformMigration;
use Doctrine\DBAL\DBALException;
use App\Migration\AbstractMultiPlatformMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
@ -40,7 +38,7 @@ final class Version1 extends AbstractMultiPlatformMigration
public function mySQLUp(Schema $schema): void
{
$this->skipIf($this->getOldDBVersion() > 0, 'Old Part-DB Database detected! Continue with upgrade...');
$this->warnIf($this->getOldDBVersion() > 0, 'Old Part-DB Database detected! Continue with upgrade...');
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
@ -228,11 +226,11 @@ EOD;
public function sqLiteUp(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
public function sqLiteDown(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warIf(true, "Migration not needed for SQLite. Skipping...");
}
}

View file

@ -22,10 +22,9 @@ declare(strict_types=1);
namespace DoctrineMigrations;
use App\Migrations\AbstractMultiPlatformMigration;
use App\Migration\AbstractMultiPlatformMigration;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
@ -48,7 +47,7 @@ final class Version20190902140506 extends AbstractMultiPlatformMigration
$this->abortIf(26 !== $version, 'This database migration can only be used if the database version is 26! Install Part-DB 0.5.6 and update database there!');
} catch (DBALException $dBALException) {
//when the table was not found, then you can not use this migration
$this->skipIf(true, 'Empty database detected. Skip migration.');
$this->warnIf(true, 'Empty database detected. Skip migration.');
}
//Deactive SQL Modes (especially NO_ZERO_DATE, which prevents updating)
@ -320,11 +319,11 @@ final class Version20190902140506 extends AbstractMultiPlatformMigration
public function sqLiteUp(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
public function sqLiteDown(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
}

View file

@ -22,9 +22,8 @@ declare(strict_types=1);
namespace DoctrineMigrations;
use App\Migrations\AbstractMultiPlatformMigration;
use App\Migration\AbstractMultiPlatformMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
@ -84,11 +83,11 @@ final class Version20190913141126 extends AbstractMultiPlatformMigration
public function sqLiteUp(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
public function sqLiteDown(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
}

View file

@ -22,9 +22,8 @@ declare(strict_types=1);
namespace DoctrineMigrations;
use App\Migrations\AbstractMultiPlatformMigration;
use App\Migration\AbstractMultiPlatformMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
@ -173,11 +172,11 @@ final class Version20190924113252 extends AbstractMultiPlatformMigration
public function sqLiteUp(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
public function sqLiteDown(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
}

View file

@ -22,9 +22,8 @@ declare(strict_types=1);
namespace DoctrineMigrations;
use App\Migrations\AbstractMultiPlatformMigration;
use App\Migration\AbstractMultiPlatformMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
@ -59,11 +58,11 @@ final class Version20191214153125 extends AbstractMultiPlatformMigration
public function sqLiteUp(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
public function sqLiteDown(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
}

View file

@ -22,9 +22,8 @@ declare(strict_types=1);
namespace DoctrineMigrations;
use App\Migrations\AbstractMultiPlatformMigration;
use App\Migration\AbstractMultiPlatformMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
@ -62,11 +61,11 @@ final class Version20200126191823 extends AbstractMultiPlatformMigration
public function sqLiteUp(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
public function sqLiteDown(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
}

View file

@ -4,9 +4,8 @@ declare(strict_types=1);
namespace DoctrineMigrations;
use App\Migrations\AbstractMultiPlatformMigration;
use App\Migration\AbstractMultiPlatformMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
@ -52,11 +51,11 @@ final class Version20200311204104 extends AbstractMultiPlatformMigration
public function sqLiteUp(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
public function sqLiteDown(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
}

View file

@ -4,9 +4,8 @@ declare(strict_types=1);
namespace DoctrineMigrations;
use App\Migrations\AbstractMultiPlatformMigration;
use App\Migration\AbstractMultiPlatformMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
@ -36,11 +35,11 @@ final class Version20200409130946 extends AbstractMultiPlatformMigration
public function sqLiteUp(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
public function sqLiteDown(Schema $schema): void
{
$this->skipIf(true, "Migration not needed for SQLite. Skipping...");
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
}
}

View file

@ -4,9 +4,8 @@ declare(strict_types=1);
namespace DoctrineMigrations;
use App\Migrations\AbstractMultiPlatformMigration;
use App\Migration\AbstractMultiPlatformMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!

View file

@ -45,8 +45,10 @@ namespace App\EventSubscriber\LogSystem;
use App\Entity\LogSystem\DatabaseUpdatedLogEntry;
use App\Services\LogSystem\EventLogger;
use Doctrine\Common\EventSubscriber;
use Doctrine\Migrations\DependencyFactory;
use Doctrine\Migrations\Event\MigrationsEventArgs;
use Doctrine\Migrations\Events;
use Doctrine\Migrations\Version\AliasResolver;
/**
* This subscriber logs databaseMigrations to Event log.
@ -57,21 +59,24 @@ class LogDBMigrationSubscriber implements EventSubscriber
protected $new_version = null;
protected $eventLogger;
protected $aliasResolver;
public function __construct(EventLogger $eventLogger)
public function __construct(EventLogger $eventLogger, DependencyFactory $dependencyFactory)
{
$this->eventLogger = $eventLogger;
$this->aliasResolver = $dependencyFactory->getVersionAliasResolver();
}
public function onMigrationsMigrated(MigrationsEventArgs $args): void
{
//Dont do anything if this was a dry run
if ($args->isDryRun()) {
if ($args->getMigratorConfiguration()->isDryRun()) {
return;
}
//Save the version after the migration
$this->new_version = $args->getConfiguration()->getCurrentVersion();
//$this->new_version = $args->getMigratorConfiguration()->getCurrentVersion();
$this->new_version = (string) $this->aliasResolver->resolveVersionAlias('current');
//After everything is done, write the results to DB log
$this->old_version = empty($this->old_version) ? 'legacy/empty' : $this->old_version;
@ -89,7 +94,8 @@ class LogDBMigrationSubscriber implements EventSubscriber
{
// Save the version before any migration
if (null === $this->old_version) {
$this->old_version = $args->getConfiguration()->getCurrentVersion();
//$this->old_version = $args->getConfiguration()->getCurrentVersion();
$this->old_version = (string) $this->aliasResolver->resolveVersionAlias('current');
}
}

View file

@ -1,12 +1,14 @@
<?php
namespace App\Migrations;
namespace App\Migration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Psr\Log\LoggerInterface;
abstract class AbstractMultiPlatformMigration extends AbstractMigration
{
@ -15,6 +17,14 @@ abstract class AbstractMultiPlatformMigration extends AbstractMigration
protected $permissions_updated = false;
protected $admin_pw = "";
protected $logger;
public function __construct(Connection $connection, LoggerInterface $logger)
{
$this->logger = $logger;
AbstractMigration::__construct($connection, $logger);
}
public function up(Schema $schema): void
{
$db_type = $this->connection->getDatabasePlatform()->getName();
@ -95,11 +105,12 @@ abstract class AbstractMultiPlatformMigration extends AbstractMigration
public function postUp(Schema $schema): void
{
parent::postUp($schema);
$this->write('<question>[!!!] Permissions were updated! Please check if they fit your expectations!</question>');
$this->logger->warning('<question>[!!!] Permissions were updated! Please check if they fit your expectations!</question>');
if (!empty($this->admin_pw)) {
$this->write('');
$this->write('<bg=yellow;fg=black>The initial password for the "admin" user is: ' . $this->admin_pw . '</>');
$this->logger->warning('');
$this->logger->warning('<bg=yellow;fg=black>The initial password for the "admin" user is: ' . $this->admin_pw . '</>');
$this->logger->warning('');
}
}

View file

@ -90,16 +90,16 @@
]
},
"doctrine/doctrine-migrations-bundle": {
"version": "1.2",
"version": "2.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "1.2",
"ref": "c1431086fec31f17fbcfe6d6d7e92059458facc1"
"version": "2.2",
"ref": "baaa439e3e3179e69e3da84b671f0a3e4a2f56ad"
},
"files": [
"./config/packages/doctrine_migrations.yaml",
"./src/Migrations/.gitignore"
"./migrations/.gitignore"
]
},
"doctrine/event-manager": {