migrations
migrations copied to clipboard
Raise exception when there are migrations yet to be run
From @aaronstillwell on June 6, 2017 17:46
This is a (multiple allowed):
-
[ ] bug
-
[x] enhancement
-
[ ] feature-discussion (RFC)
-
CakePHP Version: 3.x
-
Platform and Target: -
What you did
Developing with co-worker, co-worker creates a migration, commits, I pull changes, forget to migrate / don't realise a migration has been added.
What happened
Hitting errors as the development schema is not up to date. A small but noteworthy productivity hit.
What you expected to happen
If CakePHP were to raise an exception when running in development mode, this situation would be mostly avoided.
I'll be happy to personally file a PR for this feature. Happy to hear thoughts on whether this would be a wanted / desirable feature by other Cake developers.
Copied from original issue: cakephp/cakephp#10727
This could be done if the migrations plugin included middleware during debug mode.
@markstory That could be in the realm of possibility.
@markstory interesting idea, I like that.
@markstory if you'd like to assign this issue to me I'll follow up with a PR in due course?
Wow.. this would be a cool feature... Can you direct me to the right area when you say "included middleware", @markstory ? I would like to send a PR this weekend.
@karmicdice when an application is in debug mode, the migrations plugin could add a middleware that checks for pending migrations and throws a helpful error if there are migrations that need to be run. This is similar to how rails works.
Thanks, on it!
Created a folder - config under migrations plugin....
tl;dr:
Do we support middleware in plugins? I hope we do. How do we invoke it? Tried calling it via bootstrap and changed the plugin load with a config 'bootstrap' => true
, didn't work. Also, cannot find the docs. Traced the working of RoR and Laravel middleware via plugins.
Can someone please suggest how we are doing it differently?
I really want this feature :)
Do we support middleware in plugins? I really want this feature :)
don't worry , you have it :)
only add your middleware
namespace YourPluginName;
use Cake\Core\BasePlugin;
/**
* Plugin class for CakePHP plugin collection.
*/
class Plugin extends BasePlugin
{
public function middleware($middleware)
{
// add your middleware
return $middleware;
}
https://github.com/cakephp/debug_kit/blob/325a2a653f72af24489026300e4dc3169f2e15f1/src/Plugin.php#L63-L70
Yes, I did.
Sorry, actually I had a typo. It is working. The return must be MiddlewareQueue
the Queue part
@karmicdice middleware
hook added to bake to generate it when create new plugin with bake
return types added to branch 4 only , yes if you are using cake/plugin/4 you have to add return types according to cake core
@karmicdice Do you want to follow up on this still?
@dereuromark Thanks for the bump. Yea. I had fix logic in my head. Will get this happening.
Hi. What should be the canonical exception status? 500 doesn't seem to be helpful.
@karmicdice In this case there is no fitting HTTP status code to reflect that issue, as it is a very internal one. So 500 Internal error isn't totally wrong.
But if we want to go with another one, 503 Service Unavailable could be one.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503
Now someone just has to implement the middleware to ship with the plugin, and people can use it as opt-in for their apps.