papertank / envoy-deploy

Laravel Envoy Deployment
MIT License
424 stars 84 forks source link

How to avoid unnecessary migrate:rollback #24

Closed marco-acorte closed 5 months ago

marco-acorte commented 5 months ago

It's not a real issue, just a discussion to improve this fantastic product

with this deployment system made with Laravel Envoy we can manage the rollback (restore previous src folder) but not the rollback of the migration/s

It is not complete in my opinion because it should also rollback the (possible) migrations performed previously

The problem from cmdline is that I can't immediately understand if there have been migrations (should I check the migrations table before and after? sich)

Do any of you have forge/envoyer? How do THEY do it in this case?

marco-acorte commented 5 months ago

probably forge/envoyer don't cover this scenario https://laracasts.com/discuss/channels/envoyer/how-does-envoyer-handle-migration-rollbacks

davidrushton commented 5 months ago

@marco-acorte The current version of this script assumes that every deployment might have migrations, but in some of my projects (particularly SaaS with multiple tenant databases) I customise so that I have to pass a --migrate argument:

@task('deployment_migrate')
    @if ( isset($migrate) && $migrate )
    echo "Running migrations..."
        {{ $php }} {{ $release }}/artisan migrate --env={{ $env }} --force --no-interaction
    @else
    echo "Skipping migrations"
    @endif
@endtask

I'd be happy to accept a PR to the deployment_rollback task that does a similar condition for a --migrate-rollback option, but I don't think it should do this by default as it may lead to unexpected results. So if you knew that a deployment had migrations and you need to rollback, you'd have to run envoy run rollback --migrate-rollback