Skip to content

Commit

Permalink
Allow to have mig definitions in different directories depending on s…
Browse files Browse the repository at this point in the history
…iteaccess
  • Loading branch information
gggeek committed Apr 26, 2018
1 parent a46bee1 commit faac2d2
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ protected function getMigrationDirectory($bundleName)
}

$bundle = $this->getApplication()->getKernel()->getBundle($bundleName);
$migrationDirectory = $bundle->getPath() . '/' . $this->getContainer()->getParameter('kaliop_bundle_migration.version_directory');
$migrationDirectory = $bundle->getPath() . '/' . $this->getContainer()->get('ez_migration_bundle.helper.config.resolver')->getParameter('kaliop_bundle_migration.version_directory');

return $migrationDirectory;
}
Expand Down
12 changes: 10 additions & 2 deletions Core/Loader/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Kaliop\eZMigrationBundle\API\LoaderInterface;
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition;
use Kaliop\eZMigrationBundle\API\Collection\MigrationDefinitionCollection;
use Kaliop\eZMigrationBundle\API\ConfigResolverInterface;
use Symfony\Component\HttpKernel\KernelInterface;

/**
Expand All @@ -19,10 +20,17 @@ class Filesystem implements LoaderInterface
protected $versionDirectory;
protected $kernel;

public function __construct(KernelInterface $kernel, $versionDirectory = 'Migrations')
/**
* Filesystem constructor.
* @param KernelInterface $kernel
* @param string $versionDirectoryParameter name of folder when $configResolver is null; name of parameter when it is not
* @param ConfigResolverInterface $configResolver
* @throws \Exception
*/
public function __construct(KernelInterface $kernel, $versionDirectoryParameter = 'Migrations', ConfigResolverInterface $configResolver = null)
{
$this->versionDirectory = $versionDirectory;
$this->kernel = $kernel;
$this->versionDirectory = $configResolver ? $configResolver->getParameter($versionDirectoryParameter) : $versionDirectoryParameter;
}

/**
Expand Down
18 changes: 11 additions & 7 deletions Core/StorageHandler/Database/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

namespace Kaliop\eZMigrationBundle\Core\StorageHandler\Database;

use Kaliop\eZMigrationBundle\API\StorageHandlerInterface;
use Kaliop\eZMigrationBundle\API\Collection\MigrationCollection;
use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\DBAL\Schema\Schema;
use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
use eZ\Publish\Core\Persistence\Database\SelectQuery;
use Kaliop\eZMigrationBundle\API\StorageHandlerInterface;
use Kaliop\eZMigrationBundle\API\Collection\MigrationCollection;
use Kaliop\eZMigrationBundle\API\Value\Migration as APIMigration;
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;

use Kaliop\eZMigrationBundle\API\ConfigResolverInterface;

/**
* Database-backed storage for info on executed migrations
Expand All @@ -22,11 +24,13 @@ class Migration extends TableStorage implements StorageHandlerInterface

/**
* @param DatabaseHandler $dbHandler
* @param string $tableName
* @param string $tableNameParameter
* @param ConfigResolverInterface $configResolver
* @throws \Exception
*/
public function __construct(DatabaseHandler $dbHandler, $tableName = 'kaliop_migrations')
public function __construct(DatabaseHandler $dbHandler, $tableNameParameter = 'kaliop_migrations', ConfigResolverInterface $configResolver = null)
{
parent::__construct($dbHandler, $tableName);
parent::__construct($dbHandler, $tableNameParameter, $configResolver);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions Core/StorageHandler/Database/TableStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Kaliop\eZMigrationBundle\Core\StorageHandler\Database;

use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
use Kaliop\eZMigrationBundle\API\ConfigResolverInterface;

abstract class TableStorage
{
Expand All @@ -28,12 +29,14 @@ abstract class TableStorage

/**
* @param DatabaseHandler $dbHandler
* @param string $tableName
* @param string $tableNameParameter name of table when $configResolver is null, name of parameter otherwise
* @param ConfigResolverInterface $configResolver
* @throws \Exception
*/
public function __construct(DatabaseHandler $dbHandler, $tableName)
public function __construct(DatabaseHandler $dbHandler, $tableNameParameter, ConfigResolverInterface $configResolver = null)
{
$this->dbHandler = $dbHandler;
$this->tableName = $tableName;
$this->tableName = $configResolver ? $configResolver->getParameter($tableNameParameter) : $tableNameParameter;
}

abstract function createTable();
Expand Down
2 changes: 1 addition & 1 deletion MigrationVersions/20100101000200_MigrateV1ToV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private function __construct(ContainerInterface $container)
private function goForIt()
{
$this->legacyTableName = $this->container->getParameter('kaliop_bundle_migration.table_name');
$this->legacyMigrationsDir = $this->container->getParameter('kaliop_bundle_migration.version_directory');
$this->legacyMigrationsDir = $this->container->get('ez_migration_bundle.helper.config.resolver')->getParameter('kaliop_bundle_migration.version_directory');

$migrationStorageService = $this->container->get('ez_migration_bundle.storage_handler');
$this->dbHandler = $this->container->get('ezpublish.connection');
Expand Down
31 changes: 25 additions & 6 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
parameters:
# Set to false to disable completely the debug output of executed migration steps in verbose mode
ez_migration_bundle.enable_debug_output: true

# The directory (inside each bundle) where to look for migrations definitions
# NB: this parameter will be renamed in the future
# NB: supports per-siteaccess configuration as an override of global configuration. For that, just define parameters:
# kaliop_bundle_migration.<siteaccess_group>.version_directory
kaliop_bundle_migration.version_directory: 'MigrationVersions'
# The database tables used to store migration information. Will be created automatically
# NB: supports per-siteaccess configuration as an override of global configuration. For that, just define parameters:
# ez_migration_bundle.<siteaccess_group>.table_name
ez_migration_bundle.table_name: 'kaliop_migrations'
# NB: supports per-siteaccess configuration as an override of global configuration. For that, just define parameters:
# ez_migration_bundle.<siteaccess_group>.context_table_name
ez_migration_bundle.context_table_name: 'kaliop_migrations_contexts'

# Used to discriminate valid migration definitions
ez_migration_bundle.valid_databases:
# names have to correspond to doctrine 'platform', short of version numbers and lowercase
Expand All @@ -16,8 +26,6 @@ parameters:
- 'drizzle'
- 'sqlserver'
- 'sqlanywhere'
# Set to false to disable completely the debug output of executed migration steps in verbose mode
ez_migration_bundle.enable_debug_output: true

# Deprecated parameter. Left in for the v1-to-v2 migration to work.
kaliop_bundle_migration.table_name: 'kaliop_versions'
Expand Down Expand Up @@ -104,6 +112,7 @@ parameters:
ez_migration_bundle.helper.limitation_converter.class: Kaliop\eZMigrationBundle\Core\Helper\LimitationConverter
ez_migration_bundle.helper.sort_converter.class: Kaliop\eZMigrationBundle\Core\Helper\SortConverter
ez_migration_bundle.helper.console_io.class: Kaliop\eZMigrationBundle\Core\Helper\ConsoleIO
ez_migration_bundle.helper.config.resolver: Kaliop\eZMigrationBundle\Core\Helper\ConfigResolver

ez_migration_bundle.step_executed_listener.tracing.class: Kaliop\eZMigrationBundle\Core\EventListener\TracingStepExecutedListener

Expand All @@ -129,13 +138,15 @@ services:
class: '%ez_migration_bundle.loader.filesystem.class%'
arguments:
- '@kernel'
- '%kaliop_bundle_migration.version_directory%'
- 'kaliop_bundle_migration.version_directory'
- '@ez_migration_bundle.helper.config.resolver'

ez_migration_bundle.loader.filesystem_recursive:
class: '%ez_migration_bundle.loader.filesystem_recursive.class%'
arguments:
- '@kernel'
- '%kaliop_bundle_migration.version_directory%'
- 'kaliop_bundle_migration.version_directory'
- '@ez_migration_bundle.helper.config.resolver'

### parsers

Expand Down Expand Up @@ -173,7 +184,8 @@ services:
class: '%ez_migration_bundle.storage_handler.database.class%'
arguments:
- '@ezpublish.connection'
- '%ez_migration_bundle.table_name%'
- 'ez_migration_bundle.table_name'
- '@ez_migration_bundle.helper.config.resolver'

ez_migration_bundle.context_storage_handler:
alias: ez_migration_bundle.context_storage_handler.database
Expand All @@ -182,7 +194,8 @@ services:
class: '%ez_migration_bundle.context_storage_handler.database.class%'
arguments:
- '@ezpublish.connection'
- '%ez_migration_bundle.context_table_name%'
- 'ez_migration_bundle.context_table_name'
- '@ez_migration_bundle.helper.config.resolver'

### executors

Expand Down Expand Up @@ -705,3 +718,9 @@ services:
class: '%ez_migration_bundle.helper.console_io.class%'
tags:
- { name: kernel.event_listener, event: console.command }

ez_migration_bundle.helper.config.resolver:
class: '%ez_migration_bundle.helper.config.resolver%'
arguments:
- '@ezpublish.config.resolver'
- '@container'
12 changes: 11 additions & 1 deletion WHATSNEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Version 4.7
* New: migration step `file/prepend`, works just like `file/append` but adds content at beginning instead of end of file

* New: migration steps `file/append`, `file/prepend` and `file/save` can load the file contents from a template file on
disk besides having it inline in the migration definition
disk besides having it inline in the migration definition

* New: all migration steps that deal with the content repository, as well as sql, php class, sf services, files, mail,
http calls, process execution have gained support for being skipped via an `if` tag. The semantics are the same
Expand All @@ -16,6 +16,16 @@ Version 4.7
_operator_: value # allowed operators: eq, gt, gte, lt, lte, ne, count, length, regexp
```

* New: it is now possible to define the following parameters using siteaccess-aware configuration:

`kaliop_bundle_migration.version_directory`, `ez_migration_bundle.table_name`, `ez_migration_bundle.context_table_name`

This is useful when you have multi-site eZPlatform installations which do not share a single Repository database, and
as such might need to execute different sets of migrations for each site.

As an example, just use this parameter format: `kaliop_bundle_migration.my_siteaccess_group.version_directory`


Version 4.6
===========

Expand Down

0 comments on commit faac2d2

Please sign in to comment.