Skip to content

Commit

Permalink
Support app level migration scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHash committed Aug 1, 2016
1 parent c3d0a07 commit b1ef600
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

use Honeybee\FrameworkBinding\Agavi\App\Base\Action;
use Honeybee\Common\Error\RuntimeError;
use Honeybee\Common\Util\JsonToolkit;

class Honeybee_Core_Fixture_GenerateAction extends Action
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

use Honeybee\FrameworkBinding\Agavi\App\Base\Action;
use Honeybee\Common\Error\RuntimeError;
use Honeybee\Common\Util\JsonToolkit;

class Honeybee_Core_Fixture_ImportAction extends Action
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace {{ vendor_prefix }}\{{ package_prefix }}\Migration\CouchDb;
use Honeybee\Infrastructure\Migration\CouchDbMigration;
use Honeybee\Infrastructure\Migration\MigrationTargetInterface;
use Honeybee\Infrastructure\Migration\MigrationInterface;
use Honeybee\Infrastructure\Migration\MigrationTargetInterface;
class Migration_{{ timestamp }}_{{ name }} extends CouchDbMigration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@ public function executeConsole(AgaviRequestDataHolder $request_data)
$migration_dir = $this->getAttribute('migration_dir');

// Bit of a hack to build namespace
if (!preg_match('#.+/app/modules/(\w+_?)/.+#', $migration_dir, $matches)) {
if (!preg_match('#.+/app/(?:modules|migration)/(\w+_?)(?:$|/.+)#', $migration_dir, $matches)) {
throw new RuntimeError(sprintf('Could not find namespace info in path %s', $migration_dir));
}

$namespace_parts = explode('_', $matches[1]);
if (count($namespace_parts) == 1) {
// @todo app migration - introduce a project root namespace setting
$namespace_parts = [ 'Your', 'Application' ];
}

// And a hack to determine the technology namespace
if (strpos($request_data->getParameter('target'), 'event_source')) {
$target = $request_data->getParameter('target');
if (strpos($target, 'event_source')) {
$technology = 'CouchDb';
} else {
} elseif (strpos($target, 'view_store')) {
$technology = 'Elasticsearch';
} else {
$technology = 'RabbitMq';
}

$migration_filepath = sprintf(
Expand All @@ -35,11 +44,9 @@ public function executeConsole(AgaviRequestDataHolder $request_data)
$migration_slug
);

$twig_renderer = TwigRenderer::create(
[
'template_paths' => [ __DIR__ ]
]
);
$twig_renderer = TwigRenderer::create([
'template_paths' => [ __DIR__ ]
]);

$twig_renderer->renderToFile(
$technology . 'Migration.tpl.twig',
Expand All @@ -52,7 +59,8 @@ public function executeConsole(AgaviRequestDataHolder $request_data)
'filepath' => $migration_filepath,
'vendor_prefix' => $namespace_parts[0],
'package_prefix' => $namespace_parts[1],
'technology' => $technology
'technology' => $technology,
'project_prefix' => AgaviConfig::get('core.project_prefix')
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace {{ vendor_prefix }}\{{ package_prefix }}\Migration\Elasticsearch;
use Honeybee\Infrastructure\Migration\ElasticsearchMigration;
use Honeybee\Infrastructure\Migration\MigrationTargetInterface;
use Honeybee\Infrastructure\Migration\MigrationInterface;
use Honeybee\Infrastructure\Migration\MigrationTargetInterface;
class Migration_{{ timestamp }}_{{ name }} extends ElasticsearchMigration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
namespace {{ vendor_prefix }}\{{ package_prefix }}\Migration\RabbitMq;
use Honeybee\Infrastructure\Migration\MigrationInterface;
use Honeybee\Infrastructure\Migration\MigrationTargetInterface;
use Honeybee\Infrastructure\Migration\RabbitMqMigration;
class Migration_{{ timestamp }}_{{ name }} extends RabbitMqMigration
{
public function getDescription($direction = MigrationInterface::MIGRATE_UP)
{
if ($direction === MigrationInterface::MIGRATE_UP) {
return '{{ description }}';
}
return 'Reversal of {{ description }}';
}
public function isReversible()
{
return true;
}
public function up(MigrationTargetInterface $migration_target)
{
/*
* Create a version list and domain events pipeline if this is the initial migration
*
* $this->createVersionList($migration_target, '{{ project_prefix }}.domain.version_list');
* $this->createExchangePipeline($migration_target, '{{ project_prefix }}.domain.events');
*/
/*
* Create a queue and register on an exchange. Event bus events for an async channel will be sent
* as messages routed to the given queue.
*
* Add a configuration in jobs.xml and register the job to an event handler, then run a worker
* to process the messages according to configured retry/fail strategies.
*
* $this->createQueue($migration_target, '{{ project_prefix }}.domain.events', 'my.queue', 'my_routing_key');
*/
}
public function down(MigrationTargetInterface $migration_target)
{
// @todo implement
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

use Honeybee\FrameworkBinding\Agavi\App\Base\Action;
use Honeybee\FrameworkBinding\Agavi\CodeGen\Config\AccessControlXmlConfigGenerator;
use Honeybee\FrameworkBinding\Agavi\CodeGen\Config\AggregateRootTypeMapGenerator;
use Honeybee\FrameworkBinding\Agavi\CodeGen\Config\ConfigurationScanner;
use Honeybee\FrameworkBinding\Agavi\CodeGen\Config\TrellisAutoloadGenerator;
use Honeybee\FrameworkBinding\Agavi\CodeGen\Config\DefaultXmlConfigGenerator;
use Honeybee\FrameworkBinding\Agavi\CodeGen\Config\ProjectionTypeMapGenerator;
use Honeybee\FrameworkBinding\Agavi\CodeGen\Config\NamespaceAutoloadGenerator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use Honeybee\FrameworkBinding\Agavi\App\Base\Action;
use Honeybee\FrameworkBinding\Agavi\Filter\ResourcePacker;
use Honeybee\Model\Aggregate\AggregateRootTypeInterface;

class Honeybee_Core_Util_ReplayEventsAction extends Action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use Honeybee\Ui\WebSocket\EventPusher;
use Ratchet\Http\HttpServer;
use Ratchet\Server\IoServer;
use Ratchet\Wamp\WampServer;
use Ratchet\WebSocket\WsServer;
use React\EventLoop\Factory as EventLoopFactory;
use React\Socket\Server;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use Honeybee\FrameworkBinding\Agavi\App\Base\Action;
use Honeybee\Infrastructure\Config\ArrayConfig;
use Honeybee\Infrastructure\Job\Worker\Worker;
use Honeybee\Infrastructure\Event\Bus\Transport\JobQueueTransport;

class Honeybee_Core_Worker_StartAction extends Action
{
Expand Down

0 comments on commit b1ef600

Please sign in to comment.