-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from okvpn/feature/configure-path
Allow configure path & table name for migrations This closes #17
- Loading branch information
Showing
24 changed files
with
232 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Okvpn\Bundle\MigrationBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class Configuration implements ConfigurationInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
$rootNode = $treeBuilder->root('okvpn_migration'); | ||
|
||
$rootNode | ||
->children() | ||
->scalarNode('migrations_path')->end() | ||
->scalarNode('migrations_table')->end() | ||
->end(); | ||
return $treeBuilder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Okvpn\Bundle\MigrationBundle\EventListener; | ||
|
||
use Doctrine\ORM\Event\LoadClassMetadataEventArgs; | ||
use Doctrine\ORM\Mapping\ClassMetadata; | ||
use Okvpn\Bundle\MigrationBundle\Entity\DataMigration; | ||
|
||
class DoctrineMetadataListener | ||
{ | ||
const DEFAULT_TABLE = 'okvpn_fixture_data'; | ||
|
||
private $migrationTable; | ||
|
||
/** | ||
* @param string $migrationTable | ||
*/ | ||
public function __construct(string $migrationTable) | ||
{ | ||
$this->migrationTable = $migrationTable; | ||
} | ||
|
||
/** | ||
* @param LoadClassMetadataEventArgs $eventArgs | ||
*/ | ||
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs) | ||
{ | ||
/** @var ClassMetadata $metadata */ | ||
$metadata = $eventArgs->getClassMetadata(); | ||
if ($metadata->getName() === DataMigration::class) { | ||
$table = $metadata->table; | ||
$table['name'] = $this->migrationTable; | ||
$metadata->setPrimaryTable($table); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Okvpn\Bundle\MigrationBundle\EventListener; | ||
|
||
use Okvpn\Bundle\MigrationBundle\Event\PreMigrationEvent; | ||
use Okvpn\Bundle\MigrationBundle\Migration\CreateMigrationTableMigration; | ||
|
||
class PreUpMigrationListener | ||
{ | ||
private $migrationTable; | ||
|
||
/** | ||
* @param string $migrationTable | ||
*/ | ||
public function __construct(string $migrationTable) | ||
{ | ||
$this->migrationTable = $migrationTable; | ||
} | ||
|
||
/** | ||
* @param PreMigrationEvent $event | ||
*/ | ||
public function onPreUp(PreMigrationEvent $event) | ||
{ | ||
if ($event->isTableExist(CreateMigrationTableMigration::MIGRATION_TABLE)) { | ||
if ($event->isTableExist($this->migrationTable)) { | ||
$data = $event->getData( | ||
sprintf( | ||
'select * from %s where id in (select max(id) from %s group by bundle)', | ||
CreateMigrationTableMigration::MIGRATION_TABLE, | ||
CreateMigrationTableMigration::MIGRATION_TABLE | ||
$this->migrationTable, | ||
$this->migrationTable | ||
) | ||
); | ||
foreach ($data as $val) { | ||
$event->setLoadedVersion($val['bundle'], $val['version']); | ||
} | ||
} else { | ||
$event->addMigration(new CreateMigrationTableMigration()); | ||
$event->addMigration(new CreateMigrationTableMigration($this->migrationTable)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Okvpn\Bundle\MigrationBundle\Exception; | ||
|
||
interface MigrationExceptionInterface extends \Throwable | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.