winter icon indicating copy to clipboard operation
winter copied to clipboard

Add support for --force on artisan migrate

Open LukeTowers opened this issue 9 months ago • 4 comments

LukeTowers avatar Mar 26 '25 06:03 LukeTowers

@LukeTowers I am thinking of tackling this one. I am wondering if this is missing because this repo is older than the artisan migrate --force option in Laravel? Or are there any technical limitations to the way it is in Laravel, that need to be considered when adding it to Winter?

Personally I have really only used --force for automatic deployments, like when you push to master or something like that. Are there any other use cases that might be non trivial? Is the expected solution just to copy the code for it from a Laravel project I have on my computer?

IsaiahPaget avatar Jun 08 '25 15:06 IsaiahPaget

@IsaiahPaget we use our own migration system entirely. Check the WinterUp command in the system module. I'm not opposed to either making our system more aligned with Laravel's implementation or just having "dummy" support for the force flag if it doesn't make sense for our system so that at least people's muscle memory from Laravel doesn't trip them up in Winter.

LukeTowers avatar Jun 08 '25 15:06 LukeTowers

@LukeTowers Okk, so I found where I can add the dummy force command. But I also found how it works in Laravel, basically there is a trait Illuminate\Console\ConfirmableTrait

class MigrateCommand extends BaseCommand implements Isolatable
{
    use ConfirmableTrait;
    // ...
    public function handle()
    {
        if (! $this->confirmToProceed()) {
            return 1;
        }
        // ...
    }
}

that gets called in the handle method of the MigrateCommand class, we could put this in the WinterUp class but this would mean any users that are using the APP_ENV=production option would now need to attach the --force option to their auto deploys or however they use it.

I am noticing that my .env.example doesn't have that APP_ENV= option in it, so maybe this isn't an issue for any users, I am not sure, what do you think?

I just went ahead an implemented it on my machine and it only brings up the confirmation when you have that APP_ENV= option set as production, anything else, or if its just not there is ignores the confirmation, so I don't think it would have many impacts.

Is there value in having protections on commands in production?

IsaiahPaget avatar Jun 08 '25 18:06 IsaiahPaget

@IsaiahPaget yes, there is. It would technically be a breaking change for anyone's workflow that makes use of artisan migrate without --force but with APP_ENV set to production but I'm fine with calling that out in the release notes and making people make that change to their deployment scripts as a part of updating to the latest version; it's relatively low effort and it helps us be more inline with Laravel.

LukeTowers avatar Jun 09 '25 09:06 LukeTowers