How can I automate running laravel database migrations?

I am moving one of my clients from using php forge + a colo server to github actions + fly.

I have set up a github workflow to do deploys on PR merges, per the docs. It works fine. What I can’t figure out how to do (which forge does) is run db migrations on deploy.

I was hoping I could add to the Dockerfile that fly creates for laravel:

RUN composer install --optimize-autoloader --no-dev \
    && mkdir -p storage/logs \
    && php artisan optimize:clear \
    && php artisan migrate --force \    # <-- this

…however, it appears that the environment hasn’t been injected which this runs, so it’s not actually able to access the db cluster.

Is there a better pattern for this?

Hi,

Handily there is indeed :slightly_smiling_face:

Fly have thought of that. Check out this linked part of the docs (Migrate on Deploy) for how:

Great, that works (or at least takes me to the next problem). Thanks!

(Talk about buried docs though :frowning: )

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.