Skip to content

Instantly share code, notes, and snippets.

@Mikulas
Last active March 17, 2016 18:49
Show Gist options
  • Save Mikulas/213604faa0b55e46588a to your computer and use it in GitHub Desktop.
Save Mikulas/213604faa0b55e46588a to your computer and use it in GitHub Desktop.
diff --git a/app/config/config.neon b/app/config/config.neon
index 9ad1d56..bae44d1 100644
--- a/app/config/config.neon
+++ b/app/config/config.neon
@@ -37,6 +37,13 @@ parameters:
gm:
executable: gm # defaults to executable in path
+ nextras:
+ migrations:
+ dir: %appDir%/../migrations
+ handlers:
+ sql: @nextras.migrations.sqlHandler
+ php: @nextras.migrations.phpHandler
+
geocoding:
google:
key: "..."
@@ -69,7 +76,7 @@ nextras.orm:
nextras.migrations:
- dir: %appDir%/../migrations
+ dir: %nextras.migrations.dir%
decorator:
@@ -230,6 +237,7 @@ kdyby.console:
- Bin\Commands\EncryptionEncrypt
- Bin\Commands\EncryptionGenerateKey
- Bin\Commands\HashSecurityToken
+ - Bin\Commands\MigrationsContinue(@migrationsDriver, %nextras.migrations.dir%, %nextras.migrations.handlers%)
- Bin\Commands\DataGenerate
- Bin\Commands\TestsRun
- Bin\Commands\TestsRemoveDatabases
diff --git a/bin/commands/MigrationsContinue.php b/bin/commands/MigrationsContinue.php
new file mode 100644
index 0000000..7d2c417
--- /dev/null
+++ b/bin/commands/MigrationsContinue.php
@@ -0,0 +1,84 @@
+<?php
+
+namespace Bin\Commands;
+
+use Nextras\Migrations\Bridges\SymfonyConsole\ContinueCommand;
+use Nextras\Migrations\Engine\Runner;
+use Nextras\Migrations\Entities\Group;
+use Nextras\Migrations\IDriver;
+use Nextras\Migrations\IPrinter;
+
+
+class MigrationsContinue extends ContinueCommand
+{
+
+ /** @var IDriver */
+ private $driver;
+
+ /** @var string path */
+ private $dir;
+
+
+ /**
+ * @param IDriver $driver
+ * @param string $dir
+ * @param array $extensionHandlers
+ */
+ public function __construct(IDriver $driver, $dir, $extensionHandlers = [])
+ {
+ parent::__construct($driver, $dir, $extensionHandlers);
+ $this->driver = $driver;
+ $this->dir = $dir;
+ }
+
+ /**
+ * @param string $mode Runner::MODE_*
+ * @param bool $withDummy include dummy data?
+ * @return void
+ */
+ protected function runMigrations($mode, $withDummy)
+ {
+ $printer = $this->getPrinter();
+
+ $this->runPatches($this->driver, $printer, $withDummy);
+
+ $runner = new Runner($this->driver, $printer);
+
+ foreach ($this->getGroups($withDummy) as $group) {
+ $runner->addGroup($group);
+ }
+
+ foreach ($this->getExtensionHandlers() as $ext => $handler) {
+ $runner->addExtensionHandler($ext, $handler);
+ }
+
+ $runner->run($mode);
+ }
+
+
+ private function runPatches(IDriver $driver, IPrinter $printer, $withDummy)
+ {
+ $runner = new Runner($driver, $printer);
+
+ $group = new Group();
+ $group->name = 'patches';
+ $group->enabled = TRUE;
+ $group->directory = $this->dir . '/patches';
+ $group->dependencies = [];
+
+ $runner->addGroup($group);
+
+ foreach ($this->getGroups($withDummy) as $group) {
+ $disabledGroup = clone $group;
+ $disabledGroup->enabled = FALSE;
+ $runner->addGroup($disabledGroup);
+ }
+
+ foreach ($this->getExtensionHandlers() as $ext => $handler) {
+ $runner->addExtensionHandler($ext, $handler);
+ }
+
+ $runner->run(Runner::MODE_CONTINUE);
+ }
+
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment