From b111afc07add99833b3524dfb7c32c5e26a0fb69 Mon Sep 17 00:00:00 2001 From: tale Date: Mon, 27 Mar 2017 15:26:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E5=B1=80=E5=A2=9E=E5=8A=A0config?= =?UTF-8?q?=E5=8F=82=E6=95=B0=EF=BC=8C=E7=94=A8=E4=BA=8E=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E9=85=8D=E7=BD=AE=E9=A1=B9=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=EF=BC=8C=E5=8F=AF=E6=A0=B9=E6=8D=AEconfig=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=8B=AC=E7=AB=8B=E6=89=A7=E8=A1=8C=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9A=84=E8=BF=81=E7=A7=BB=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Command.php | 11 +++++++---- src/Migrator.php | 2 +- src/Seeder.php | 2 +- src/command/Migrate.php | 27 ++++++++++++++++++++++++--- src/command/Seed.php | 2 +- src/command/migrate/Breakpoint.php | 2 +- src/db/Column.php | 2 +- src/db/Table.php | 2 +- 8 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/Command.php b/src/Command.php index e2f19c9..c9c78bd 100644 --- a/src/Command.php +++ b/src/Command.php @@ -6,16 +6,18 @@ // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- -// | Author: yunwuxin <448901948@qq.com>  +// | Author: yunwuxin <448901948@qq.com> // +---------------------------------------------------------------------- namespace think\migration; use InvalidArgumentException; use Phinx\Db\Adapter\AdapterFactory; use think\Config; +use think\Db; abstract class Command extends \think\console\Command { + protected $config = 'database'; public function getAdapter() { @@ -42,7 +44,8 @@ abstract class Command extends \think\console\Command */ protected function getDbConfig() { - $config = Config::get('database'); + $config = Db::connect($this->config)->getConfig(); + if ($config['deploy'] == 0) { $dbConfig = [ 'adapter' => $config['type'], @@ -52,7 +55,7 @@ abstract class Command extends \think\console\Command 'pass' => $config['password'], 'port' => $config['hostport'], 'charset' => $config['charset'], - 'table_prefix' => $config['prefix'] + 'table_prefix' => $config['prefix'], ]; } else { $dbConfig = [ @@ -63,7 +66,7 @@ abstract class Command extends \think\console\Command 'pass' => explode(',', $config['password'])[0], 'port' => explode(',', $config['hostport'])[0], 'charset' => explode(',', $config['charset'])[0], - 'table_prefix' => explode(',', $config['prefix'])[0] + 'table_prefix' => explode(',', $config['prefix'])[0], ]; } diff --git a/src/Migrator.php b/src/Migrator.php index 5e37e68..6f5674a 100644 --- a/src/Migrator.php +++ b/src/Migrator.php @@ -6,7 +6,7 @@ // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- -// | Author: yunwuxin <448901948@qq.com>  +// | Author: yunwuxin <448901948@qq.com> // +---------------------------------------------------------------------- namespace think\migration; diff --git a/src/Seeder.php b/src/Seeder.php index 19f438c..a1c46db 100644 --- a/src/Seeder.php +++ b/src/Seeder.php @@ -6,7 +6,7 @@ // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- -// | Author: yunwuxin <448901948@qq.com>  +// | Author: yunwuxin <448901948@qq.com> // +---------------------------------------------------------------------- namespace think\migration; diff --git a/src/command/Migrate.php b/src/command/Migrate.php index 3e32885..e5b3d26 100644 --- a/src/command/Migrate.php +++ b/src/command/Migrate.php @@ -6,7 +6,7 @@ // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- -// | Author: yunwuxin <448901948@qq.com>  +// | Author: yunwuxin <448901948@qq.com> // +---------------------------------------------------------------------- namespace think\migration\command; @@ -16,6 +16,9 @@ use Phinx\Db\Adapter\ProxyAdapter; use Phinx\Migration\AbstractMigration; use Phinx\Migration\MigrationInterface; use Phinx\Util\Util; +use think\console\Input; +use think\console\input\Option as InputOption; +use think\console\Output; use think\migration\Command; use think\migration\Migrator; @@ -26,9 +29,27 @@ abstract class Migrate extends Command */ protected $migrations; + public function __construct($name = null) + { + + parent::__construct($name); + + $this->addOption('--config', null, InputOption::VALUE_REQUIRED, 'The database config name', 'database'); + } + + /** + * 初始化 + * @param Input $input An InputInterface instance + * @param Output $output An OutputInterface instance + */ + protected function initialize(Input $input, Output $output) + { + $this->config = $input->getOption('config'); + } + protected function getPath() { - return $this->getConfig('path', ROOT_PATH . 'database') . DS . 'migrations'; + return $this->getConfig('path', ROOT_PATH . 'database') . DS . 'migrations' . ($this->config !== 'database' ? DS . $this->config : ''); } protected function executeMigration(MigrationInterface $migration, $direction = MigrationInterface::UP) @@ -75,7 +96,7 @@ abstract class Migrate extends Command // Record it in the database $this->getAdapter() - ->migrated($migration, $direction, date('Y-m-d H:i:s', $startTime), date('Y-m-d H:i:s', time())); + ->migrated($migration, $direction, date('Y-m-d H:i:s', $startTime), date('Y-m-d H:i:s', time())); $end = microtime(true); diff --git a/src/command/Seed.php b/src/command/Seed.php index fd746b7..da5e97b 100644 --- a/src/command/Seed.php +++ b/src/command/Seed.php @@ -6,7 +6,7 @@ // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- -// | Author: yunwuxin <448901948@qq.com>  +// | Author: yunwuxin <448901948@qq.com> // +---------------------------------------------------------------------- namespace think\migration\command; diff --git a/src/command/migrate/Breakpoint.php b/src/command/migrate/Breakpoint.php index bbadf15..0010080 100644 --- a/src/command/migrate/Breakpoint.php +++ b/src/command/migrate/Breakpoint.php @@ -6,7 +6,7 @@ // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- -// | Author: yunwuxin <448901948@qq.com>  +// | Author: yunwuxin <448901948@qq.com> // +---------------------------------------------------------------------- namespace think\migration\command\migrate; diff --git a/src/db/Column.php b/src/db/Column.php index e177d82..3b5cb04 100644 --- a/src/db/Column.php +++ b/src/db/Column.php @@ -6,7 +6,7 @@ // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- -// | Author: yunwuxin <448901948@qq.com>  +// | Author: yunwuxin <448901948@qq.com> // +---------------------------------------------------------------------- namespace think\migration\db; diff --git a/src/db/Table.php b/src/db/Table.php index bad50f1..881cbc5 100644 --- a/src/db/Table.php +++ b/src/db/Table.php @@ -6,7 +6,7 @@ // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- -// | Author: yunwuxin <448901948@qq.com>  +// | Author: yunwuxin <448901948@qq.com> // +---------------------------------------------------------------------- namespace think\migration\db;