数据库迁移工具phinx.php 配置读取config/database.php

lsmir2

文档https://www.workerman.net/doc/webman/db/migration.html 中的例子不太好.还要重新配一次数据库

这样数据库只要配置一次其他还有加载数据库的可以参考下面写法

/**
 * Phinx 迁移配置
 */
 require __DIR__ . '/vendor/autoload.php';
 require_once __DIR__ . '/support/bootstrap.php';
 $defaultConnection = config('database.connections');
return [
    'paths' => [
        'migrations' => __DIR__ . '/database/migrations',
        'seeds' => __DIR__ . '/database/seeds',
    ],
    'environments' => [
        'default_migration_table' => 'phinxlog',
        'default_environment' => 'development',
        'development' => [
            'adapter' => 'pgsql',
            'host' => getenv('DB_HOST') ?: '127.0.0.1',
            'port' => getenv('DB_PORT') ?: '5432',
            'name' => getenv('DB_NAME') ?: 'pi_memory_cloud',
            'user' => getenv('DB_USER') ?: 'pi_memory',
            'pass' => getenv('DB_PASSWORD') ?: '',
            'charset' => 'utf8',
        ],
        'production' => [
            'adapter' => 'pgsql',
            'host' => getenv('DB_HOST') ?: '127.0.0.1',
            'port' => getenv('DB_PORT') ?: '5432',
            'name' => getenv('DB_NAME') ?: 'pi_memory_cloud',
            'user' => getenv('DB_USER') ?: 'pi_memory',
            'pass' => getenv('DB_PASSWORD') ?: '',
            'charset' => 'utf8',
        ],
    ],
];
985 1 1
1个评论

yingzi1990

require __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/support/bootstrap.php';
$dbConfig = config('database', []);
$defaultConnection = $dbConfig['default'];
$connectionConfig = $dbConfig['connections'][$defaultConnection];

return
[
"paths" => [
"migrations" => "database/migrations",
"seeds" => "database/seeds"
],
"environments" => [
"default_migration_table" => "phinxlog",
"default_environment" => "dev",
"dev" => [
"adapter" => $connectionConfig['driver'],
"host" => $connectionConfig['host'],
"name" => $connectionConfig['database'],
"user" => $connectionConfig['username'],
"pass" => $connectionConfig['password'],
"port" => $connectionConfig['port'],
"charset" => $connectionConfig['charset']
]
]
];
你的解析不了env函数,用这个

lsmir2

2480
积分
0
获赞数
0
粉丝数
2024-01-29 加入
🔝