26 Star 122 Fork 16

hunzhiwange/QueryPHP

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
phinx.php 3.19 KB
一键复制 编辑 原始数据 按行查看 历史
小牛New 提交于 2024-05-17 15:10 . 优化目录
<?php
declare(strict_types=1);
use App\Infra\Module\Phinx\PhinxLoad;
use Leevel\Di\Container;
use Leevel\Kernel\App;
use Symfony\Component\Console\Input\ArgvInput;
// 加载 Composer
require __DIR__.'/vendor/autoload.php';
// 创建应用
$container = Container::singletons();
$app = new App($container, (string) realpath(__DIR__));
// 载入环境
$input = new ArgvInput();
if ($input->hasParameterOption('--env')) {
$env = $input->getParameterOption('--env');
} else {
$env = 'env';
}
putenv('RUNTIME_ENVIRONMENT='.$env);
// 选择数据库
if ($input->hasParameterOption('--database')) {
$development = $input->getParameterOption('--database');
} else {
$development = 'development';
}
if ($input->hasParameterOption('--database-index')) {
$databaseIndex = (string) $input->getParameterOption('--database-index');
} else {
$databaseIndex = '';
}
if (!in_array($development, [
'production',
'production_common',
'development',
'development_common',
], true)) {
throw new \Exception('Database must be one of `production,production_common,development,development_common`.');
}
// 读取配置
(new PhinxLoad())->handle($app);
$migrationPath = str_contains($development, '_common') ? 'common' : 'data';
return [
'paths' => [
'migrations' => "database/{$migrationPath}/migrations",
'seeds' => "database/{$migrationPath}/seeds",
],
'environments' => [
'default_migration_table' => 'phinx_log',
'default_environment' => $development,
'production' => [
'adapter' => 'mysql',
'host' => Leevel::env('DATABASE_HOST', 'localhost'),
'name' => Leevel::env('DATABASE_NAME', '').$databaseIndex,
'user' => Leevel::env('DATABASE_USER', 'root'),
'pass' => Leevel::env('DATABASE_PASSWORD', ''),
'port' => Leevel::env('DATABASE_PORT', 3306),
'charset' => 'utf8',
],
'production_common' => [
'adapter' => 'mysql',
'host' => Leevel::env('DATABASE_COMMON_HOST', 'localhost'),
'name' => Leevel::env('DATABASE_COMMON_NAME', ''),
'user' => Leevel::env('DATABASE_COMMON_USER', 'root'),
'pass' => Leevel::env('DATABASE_COMMON_PASSWORD', ''),
'port' => Leevel::env('DATABASE_COMMON_PORT', 3306),
'charset' => 'utf8',
],
'development' => [
'adapter' => 'mysql',
'host' => Leevel::env('DATABASE_HOST', 'localhost'),
'name' => Leevel::env('DATABASE_NAME', '').$databaseIndex,
'user' => Leevel::env('DATABASE_USER', 'root'),
'pass' => Leevel::env('DATABASE_PASSWORD', ''),
'port' => Leevel::env('DATABASE_PORT', 3306),
'charset' => 'utf8',
],
'development_common' => [
'adapter' => 'mysql',
'host' => Leevel::env('DATABASE_COMMON_HOST', 'localhost'),
'name' => Leevel::env('DATABASE_COMMON_NAME', ''),
'user' => Leevel::env('DATABASE_COMMON_USER', 'root'),
'pass' => Leevel::env('DATABASE_COMMON_PASSWORD', ''),
'port' => Leevel::env('DATABASE_COMMON_PORT', 3306),
'charset' => 'utf8',
],
],
];
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/dyhb/queryphp.git
[email protected]:dyhb/queryphp.git
dyhb
queryphp
QueryPHP
master

搜索帮助