Commit 1483d646 authored by Thomas Müller's avatar Thomas Müller
Browse files

Adding doctrine/migrations

parent 7e67946b
This diff is collapsed.
<?php
/**
* @author Thomas Müller
* @copyright 2015 Thomas Müller deepdiver@owncloud.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OC\Core\Command\Db\Migrations;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand as DBALExecuteCommand;
use OCP\IConfig;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ExecuteCommand extends DBALExecuteCommand {
use MigrationTrait;
/** @var Connection */
private $ocConnection;
/**
* @param \OCP\IConfig $config
*/
public function __construct(IConfig $config, Connection $connection) {
$this->config = $config;
$this->ocConnection = $connection;
parent::__construct();
}
protected function configure() {
$this->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on');
parent::configure();
}
public function execute(InputInterface $input, OutputInterface $output) {
$appName = $input->getArgument('app');
$mc = $this->buildConfiguration($appName, $this->ocConnection);
$this->setMigrationConfiguration($mc);
parent::execute($input, $output);
}
}
<?php
/**
* @author Thomas Müller
* @copyright 2015 Thomas Müller deepdiver@owncloud.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OC\Core\Command\Db\Migrations;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand as DBALGenerateCommand;
use OCP\IConfig;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class GenerateCommand extends DBALGenerateCommand {
use MigrationTrait;
/** @var Connection */
private $ocConnection;
/**
* @param \OCP\IConfig $config
*/
public function __construct(IConfig $config, Connection $connection) {
$this->config = $config;
$this->ocConnection = $connection;
parent::__construct();
}
protected function configure() {
$this->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on');
parent::configure();
}
public function execute(InputInterface $input, OutputInterface $output) {
$appName = $input->getArgument('app');
$mc = $this->buildConfiguration($appName, $this->ocConnection);
$this->setMigrationConfiguration($mc);
parent::execute($input, $output);
}
}
<?php
/**
* @author Thomas Müller
* @copyright 2015 Thomas Müller deepdiver@owncloud.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OC\Core\Command\Db\Migrations;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand as DBALMigrateCommand;
use OCP\IConfig;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class MigrateCommand extends DBALMigrateCommand {
use MigrationTrait;
/** @var Connection */
private $ocConnection;
/**
* @param \OCP\IConfig $config
*/
public function __construct(IConfig $config, Connection $connection) {
$this->config = $config;
$this->ocConnection = $connection;
parent::__construct();
}
protected function configure() {
$this->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on');
parent::configure();
}
public function execute(InputInterface $input, OutputInterface $output) {
$appName = $input->getArgument('app');
$mc = $this->buildConfiguration($appName, $this->ocConnection);
$this->setMigrationConfiguration($mc);
parent::execute($input, $output);
}
}
<?php
/**
* @author Thomas Müller
* @copyright 2015 Thomas Müller deepdiver@owncloud.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OC\Core\Command\Db\Migrations;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use InvalidArgumentException;
trait MigrationTrait {
/**
* @param $appName
* @return Configuration
*/
protected function buildConfiguration($appName, $connection) {
if ($appName === 'core') {
$mc = new Configuration($connection);
$mc->setMigrationsDirectory(\OC::$SERVERROOT."/core/migrations");
$mc->setMigrationsNamespace("OC\\Migrations");
$mc->setMigrationsTableName("core_migration_versions");
return $mc;
}
$appPath = \OC_App::getAppPath($appName);
if (!$appPath) {
throw new InvalidArgumentException('Path to app is not defined.');
}
$mc = new Configuration($connection);
$mc->setMigrationsDirectory(\OC::$SERVERROOT."/$appPath/appinfo/migrations");
$mc->setMigrationsNamespace("OCA\\$appName\\Migrations");
$mc->setMigrationsTableName("{$appName}_migration_versions");
return $mc;
}
}
<?php
/**
* @author Thomas Müller
* @copyright 2015 Thomas Müller deepdiver@owncloud.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OC\Core\Command\Db\Migrations;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand as DBALStatusCommand;
use OCP\IConfig;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class StatusCommand extends DBALStatusCommand {
use MigrationTrait;
/** @var Connection */
private $ocConnection;
/**
* @param \OCP\IConfig $config
*/
public function __construct(IConfig $config, Connection $connection) {
$this->config = $config;
$this->ocConnection = $connection;
parent::__construct();
}
protected function configure() {
parent::configure();
$this->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on');
}
public function execute(InputInterface $input, OutputInterface $output) {
$appName = $input->getArgument('app');
$mc = $this->buildConfiguration($appName, $this->ocConnection);
$this->setMigrationConfiguration($mc);
parent::execute($input, $output);
}
}
......@@ -82,6 +82,10 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
$application->add(new OC\Core\Command\Db\GenerateChangeScript());
$application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory()));
$application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager()));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment