Skip to content

Commit

Permalink
Allow skip of app.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Dec 6, 2024
1 parent 53b969d commit 2f060a4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Middleware/PendingMigrationsMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Cake\Core\InstanceConfigTrait;
use Cake\Core\Plugin;
use Cake\Datasource\ConnectionManager;
use Cake\Utility\Hash;
use Migrations\Config\Config;
use Migrations\Migration\Manager;
use Migrations\Util\Util;
Expand All @@ -21,6 +22,8 @@ class PendingMigrationsMiddleware implements MiddlewareInterface
{
use InstanceConfigTrait;

protected const SKIP_QUERY_KEY = 'skip-middleware-check';

protected array $_defaultConfig = [
'paths' => [
'migrations' => ROOT . DS . 'config' . DS . 'Migrations' . DS,
Expand All @@ -29,6 +32,7 @@ class PendingMigrationsMiddleware implements MiddlewareInterface
'connection' => 'default',
'migration_table' => 'phinxlog',
],
'app' => null,
'plugins' => null,
];

Expand All @@ -54,7 +58,7 @@ public function __construct(array $config = [])
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (!Configure::read('debug')) {
if (!Configure::read('debug') || $this->isSkipped($request)) {
return $handler->handle($request);
}

Expand Down Expand Up @@ -95,6 +99,10 @@ protected function pendingMigrations(): array
*/
protected function checkAppMigrations(): bool
{
if ($this->_config['app'] === false) {
return true;
}

$connection = ConnectionManager::get($this->_config['environment']['connection']);
$database = $connection->config()['database'];
$this->_config['environment']['database'] = $database;
Expand Down Expand Up @@ -149,4 +157,13 @@ protected function checkPluginMigrations(string $plugin): bool

return true;
}

/**
* @param \Psr\Http\Message\ServerRequestInterface $request
* @return bool
*/
protected function isSkipped(ServerRequestInterface $request): bool
{
return (bool)Hash::get($request->getQueryParams(), static::SKIP_QUERY_KEY);
}
}

0 comments on commit 2f060a4

Please sign in to comment.