Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

trevorpan's avatar

Forge: script for adding column to production database table

Was reading this post below and feel I have a good understanding of the process of creating a new migration which then adds a column to an existing table. I know I'll have to test the nullable or default values for previous users, e.g. to ensure there are no errors.

https://laracasts.com/discuss/channels/laravel/what-is-the-typical-process-to-add-a-field-to-a-production-database-without-loosing-existing-data

This doc: https://laravel.com/docs/5.8/migrations#columns states you need to add this dependency composer require doctrine/dbal. I've done that locally.

When I get ready to push this to production does the below script cover this dbal?

It seems like a yes, as it's in the composer.json which would be pushed to master, but it's not something I want to get wrong.

cd /home/forge/bidbird.co
git pull origin master
composer install --no-interaction --prefer-dist --optimize-autoloader
php artisan config:cache -q --no-interaction
php artisan route:cache
npm run production
echo "" | sudo -S service php7.1-fpm reload

if [ -f artisan ]
then
    php artisan migrate --force
fi

Thank you for any tips..

0 likes
4 replies
rawilk's avatar
rawilk
Best Answer
Level 47

It should work since you have composer install included in the script. Although it doesn't hurt to have dbal installed, I don't think you'll actually need it since I'm pretty sure you really only need it if you want to change column names or column definitions.

1 like
Dalma's avatar

If you have run composer require xxx/xxx in your development environment then this will update composer.json and composer.lock which when pushed to your repository via git will be pulled when the forge script runs.

git pull origin master <--- will download all of your changes including composer.json and composer.lock composer install --no-interaction --prefer-dist --optimize-autoloader <--- will download xxx/xxx package on your server

trevorpan's avatar

@wilk_randall

Ok, it's one of those things - just want to be SURE that nothing screws up. It seems like eventually some really cool things could be done with the forge script, just getting my feet wet. Thank you!

trevorpan's avatar

@dalma

Thank you, the next thing I need to go through is the new testing server series of laracasts to test out that stuff.

Going to read up on all those scripts some more. Appreciated!

Please or to participate in this conversation.