Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel migration deployment

Just a quick one really

I have an existing Laravel app

I want to use a migration to add some columns to an existing table

So i do the following:

php artisan make:migration add_columns_to_table

Which creates a file in my migrations folder called:

2017_10_25_124938_add_column_to_table.php

And also creates an entry in my migrations table in the database. All good.

I can edit the migration file (adding the columns etc) and run

php artisan migrate

And everything works great

Now - my question is this:

When i come to deploy to live i am presuming I would log onto the live box and run the create migration command again:

php artisan make:migration add_columns_to_table

But this will create a migration with a different name to the one i created / tested locally?

So - do i then need to manually copy the code from my local 2017_10_25_124938_add_column_to_table.php migration file to the one created on the live box?

That seems a bit backwards and fiddly

What is the best way of creating and testing a migration locally and then deploying it to live when the create migration command creates a different named migration file (and DB entry) on the live box?

Or have i got the wrong end of the stick?

like image 695
Robi Avatar asked Oct 20 '25 18:10

Robi


1 Answers

The best practice is to keep migration files with the repo. While deploying the application on any environment you have to execute all migrations.

php artisan migrate

This command will run all the migrations which are not already executed in the current environment. Laravel use a table called 'migrations' to keep track of all the migrations it has run.

like image 113
Jithin Jose Avatar answered Oct 22 '25 10:10

Jithin Jose



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!