From 7ac37e235b257c5a9b5948e160bd24874cc620bd Mon Sep 17 00:00:00 2001 From: zhangfayuan <1137494466@qq.com> Date: Tue, 10 Dec 2019 14:03:28 +0800 Subject: [PATCH] catch-seed:run --- catchAdmin/CatchAdminService.php | 2 + catchAdmin/user/database/seeds/Abc.php | 19 ------ catchAdmin/user/database/seeds/UserSeeder.php | 30 +++++++++ extend/catcher/command/SeedRunCommand.php | 64 +++++++++++++++++++ 4 files changed, 96 insertions(+), 19 deletions(-) delete mode 100644 catchAdmin/user/database/seeds/Abc.php create mode 100644 catchAdmin/user/database/seeds/UserSeeder.php create mode 100644 extend/catcher/command/SeedRunCommand.php diff --git a/catchAdmin/CatchAdminService.php b/catchAdmin/CatchAdminService.php index cb46296..f9ac0c4 100644 --- a/catchAdmin/CatchAdminService.php +++ b/catchAdmin/CatchAdminService.php @@ -5,6 +5,7 @@ use catcher\command\InstallCommand; use catcher\command\MigrateRunCommand; use catcher\command\ModelGeneratorCommand; use catcher\command\ModuleCacheCommand; +use catcher\command\SeedRunCommand; use catcher\validates\Sometimes; use think\facade\Validate; use think\Service; @@ -23,6 +24,7 @@ class CatchAdminService extends Service ModuleCacheCommand::class, MigrateRunCommand::class, ModelGeneratorCommand::class, + SeedRunCommand::class ]); $this->registerValidates(); diff --git a/catchAdmin/user/database/seeds/Abc.php b/catchAdmin/user/database/seeds/Abc.php deleted file mode 100644 index 83cbbc5..0000000 --- a/catchAdmin/user/database/seeds/Abc.php +++ /dev/null @@ -1,19 +0,0 @@ - 'wuyanwen', + 'password' => password_hash('password',PASSWORD_DEFAULT), + 'email' => 'njphper@gmail.com', + 'status' => 1, + 'last_login_ip' => ip2long('127.0.0.1'), + 'last_login_time' => time(), + 'created_at' => time(), + 'updated_at' => time(), + 'deleted_at' => '', + ]; + $this->table('users')->insert($row)->save(); + } +} \ No newline at end of file diff --git a/extend/catcher/command/SeedRunCommand.php b/extend/catcher/command/SeedRunCommand.php new file mode 100644 index 0000000..c9b756b --- /dev/null +++ b/extend/catcher/command/SeedRunCommand.php @@ -0,0 +1,64 @@ +setName('catch-seed:run') + ->setDescription('the catch-seed:run command to Run database seeders') + ->addArgument('module', Argument::REQUIRED, 'seed the module database') + ->addOption('--seed', '-s', InputOption::VALUE_REQUIRED, 'What is the name of the seeder?') + ->setHelp(<<catch-seed:run command runs all available or individual seeders +php think catch-seed:run module +php think catch-seed:run -s UserSeeder +php think catch-seed:run -v + +EOT + ); + + } + + protected function execute(Input $input, Output $output) + { + $this->module = strtolower($input->getArgument('module')); + $seed = $input->getOption('seed'); + + // run the seed(ers) + $start = microtime(true); + $this->seed($seed); + $end = microtime(true); + + $output->writeln(CatchAdmin::moduleSeedsDirectory($this->module)); + $output->writeln('All Done. Took ' . sprintf('%.4fs', $end - $start) . ''); + + } + + /** + * + * 获取 seeder path + * @return string + * @param $module + * @date: 2019/12/10 14:01 + */ + protected function getPath() + { + return CatchAdmin::moduleSeedsDirectory($this->module); + } + + +}