我有一个关于与多个数据库相关的学说迁移的问题。因此,这个问题和法师作为部署工具(但不仅限于法师,因为法师只自动执行手动操作):Symfony: It's possible load different parameters.yml?
当我这样做时,在上面的链接发布的问题中提到,我如何在每个数据库上进行迁移?因为在我的视图中更改AppKernel加载器只能在所请求的URL上进行,因为您在shell上运行它,这不适用于doctrine迁移。
有人有提示,如何使用这种设置(一个应用程序源,每个多个参数有多个数据库),因为它不是我的选项,为此构建多个fullstack symfony应用程序,因为一个安装超过1GB,应用程序之间的唯一区别是userdata,我不想在一个数据库中保存,因为备份策略和其他(每个客户轻松备份而不是从一个带有customerid的数据库中提取)
Hopefuly我确实解释得足够清楚,我的问题是什么 - 更希望我确实对问题本身做出了决定并且有人有解决方案; - )
我最终得到了一个有效的解决方案,大多数任务都是自动运行。
首先,您必须在SymfonyApp内部定义一个文件夹结构(我的下面是
)_portals
|-mySUBPORTAL
|-app
|-config
|-parameters.yml.prod
|-parameters.yml.stage
|-bin
|-var
|-cache
|-.gitkeep
|-logs
|-.gitkeep
|-sessions
|-.gitkeep
|-vendor
|-.gitkeep
|-web
|-.gitkeep
|-createAppStructure.php
文件createAppStructure.php(如果需要,可以是opti-或自定义的)
createAppStructure.php
#!/usr/bin/php
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
/** Parameter Check */
if(!array_key_exists(1,$argv)) exit('Es muss das Environment angegeben werden (stage|prod)'."\r\n");
/** Funktionen */
function getFolders($path)
{
$portalsDir = scandir($path);
$portals=[];
foreach($portalsDir as $portaldir)
{
if(!in_array($portaldir, [".",".."])) {
if(is_dir($path.DIRECTORY_SEPARATOR.$portaldir)) {
$portals[] = $path.DIRECTORY_SEPARATOR.$portaldir;
}
}
}
return $portals;
}
/** Alle Customers auslesen */
$env = $argv[1];
$basepath = dirname(__FILE__);
$portals = getFolders($basepath);
/** Alle Customers durchlaufen und Directory Struktur aufbauen */
$cmd = [];
$returnCode = 0;
foreach($portals as $customer)
{
$cmd=[];
/* Full Link Folders */
$cmd['fulllink'][] = "cd $customer";
$cmd['fulllink'][] = "ln -sf ../../src ./";
$cmd['fulllink'][] = "ln -sf ../../tests ./";
/* Root Struktur */
$cmd['rootDir'][] = "cd $customer";
$cmd['rootDir'][] = "ln -sf ../../composer.json ./";
$cmd['rootDir'][] = "ln -sf ../../composer.lock ./";
$cmd['rootDir'][] = "ln -sf ../../composer.phar ./";
/* App Struktur bauen */
$cmd['appDir'][] = "cd ".$customer.DIRECTORY_SEPARATOR."app/";
$cmd['appDir'][] = "ln -sf ../../../app/AppDoc ./";
$cmd['appDir'][] = "ln -sf ../../../../app/config/config.yml ./config/";
$cmd['appDir'][] = "ln -sf ../../../../app/config/config_prod.yml ./config/";
$cmd['appDir'][] = "ln -sf ../../../../app/config/config_dev.yml ./config/";
$cmd['appDir'][] = "ln -sf ../../../../app/config/config_test.yml ./config/";
$cmd['appDir'][] = "ln -sf ../../../../app/config/routing.yml ./config/";
$cmd['appDir'][] = "ln -sf ../../../../app/config/routing_dev.yml ./config/";
$cmd['appDir'][] = "ln -sf ../../../../app/config/parameters.yml.dist ./config/";
$cmd['appDir'][] = "ln -sf ../../../../app/config/security.yml ./config/";
$cmd['appDir'][] = "ln -sf ../../../../app/config/services.yml ./config/";
$cmd['appDir'][] = "ln -sf ../../../app/db ./";
$cmd['appDir'][] = "ln -sf ../../../app/DoctrineMigrations ./";
$cmd['appDir'][] = "ln -sf ../../../app/Resources ./";
$cmd['appDir'][] = "ln -sf ../../../app/.htaccess ./";
$cmd['appDir'][] = "cp -f ../../../app/AppCache.php ./";
$cmd['appDir'][] = "cp -f ../../../app/AppKernel.php ./";
$cmd['appDir'][] = "cp -f ../../../app/autoload.php ./";
$cmd['appDir'][] = "cp -f ./config/parameters.yml.".$env." ./config/parameters.yml";
/* Bin Struktur */
$cmd['binDir'][] = "cd ".$customer.DIRECTORY_SEPARATOR."bin/";
$cmd['binDir'][] = "cp -f ../../../bin/console ./";
$cmd['binDir'][] = "cp -f ../../../bin/symfony_requirements ./";
$cmd['binDir'][] = "ln -sf ../../../bin/wkhtmltox ./";
/* Var Struktur */
$cmd['varDir'][] = "cd ".$customer.DIRECTORY_SEPARATOR."var/";
$cmd['varDir'][] = "cp -f ../../../var/bootstrap.php.cache ./";
$cmd['varDir'][] = "cp -f ../../../var/SymfonyRequirements.php ./";
$cmd['varDir'][] = "ln -sf ../../../var/data ./";
/* Vendor Structure */
$cmd['vendorDir'][] = "cd $customer";
$vendorDirs = getFolders(dirname(__FILE__).DIRECTORY_SEPARATOR.'../vendor');
foreach($vendorDirs as $vendor) {
$vendorName = end(explode("/", $vendor));
if($vendorName!='composer') {
$cmd['vendorDir'][] = "ln -sf $vendor ./vendor/";
}
}
$cmd['vendorDir'][] = "cp -rpP ../../vendor/composer/ ./vendor/composer";
/* Web Struktur */
$cmd['webDir'][] = "cd ".$customer.DIRECTORY_SEPARATOR."web/";
$cmd['webDir'][] = "ln -sf ../../../web/bundles ./";
$cmd['webDir'][] = "ln -sf ../../../web/cache ./";
$cmd['webDir'][] = "ln -sf ../../../web/logos ./";
$cmd['webDir'][] = "cp -f ../../../web/.htaccess ./";
$cmd['webDir'][] = "cp -f ../../../web/app.php ./";
$cmd['webDir'][] = "cp -f ../../../web/app_dev.php ./";
$cmd['webDir'][] = "cp -f ../../../web/config.php ./";
$cmd['webDir'][] = "ln -sf ../../../web/apple-touch-icon.png ./";
$cmd['webDir'][] = "ln -sf ../../../web/favicon.ico ./";
$cmd['webDir'][] = "ln -sf ../../../web/robots.txt ./";
/* Administrative Tasks */
$cmd['administrative'][] = "cd $customer";
$cmd['administrative'][] = "./composer.phar install";
$cmd['administrative'][] = "bin/console --no-interaction doc:mig:mig";
$cmd['administrative'][] = "bin/console cache:clear --no-warmup";
$cmd['administrative'][] = "bin/console cache:warmup";
/** Run Commands */
$returnCode = 0;
$output = [];
foreach($cmd as $key => $command)
{
echo "Kommando wird ausgeführt => ".implode(" && ", $cmd[$key])." \r\n";
exec(implode(" && ", $cmd[$key]), $output, $retval);
echo "Rückgabecode: $retval"."\r\n";
$returnCode = ($retval==1) ? 1 : $returnCode ;
foreach($output as $line) {
echo "Output: $line"."\r\n";
}
}
}
exit($returnCode);
?>
每次部署应用程序后都必须运行此脚本 - 我确实使用了mage(Magallanes)来部署我的应用程序。所以我确实添加了一个任务(execShell)并用mage启动这个脚本。但你也可以手动运行它。
创建结构后,您可以访问_portals / mySUBPortal /,并且您将找到具有所有功能的完整symfony应用程序结构。某些类型的文件被复制(因为否则,由于 DIR 或 FILE 的使用,它将无效),而其他文件也是符号链接的。
使用这种设置,您可以为SymfonyApp提供相同的源,但不同的数据库和工作原则迁移......
不要忘记自定义VHOST(APACHE / NGINX)文档_IOT在内部_PORTALS。