Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.5 Consolidate migrations w/ production database

Hopefully, I can explain this well.

I have a Laravel application that has been in production for a minute. So, I have a bunch of migration files with a lot of changes. I would like to consolidate these migration files without losing the database.

The way I think this would work:

  1. Get all production tables migrated to the desired state.
  2. Consolidate all the migration files into the minimum number of files needed.
  3. Clear the migrations table.
  4. Either run migrations or populate the migrations table.

Part of why I would like to do this is because I would like to make some of the service providers public with the cleanest migration set possible.

The difficult version might be to:

  1. Backup or duplicate tables.
  2. Run migrations.
  3. Write and run script to populate the "clean" tables.

Just hoping there's an easier way than that.

Edit (from comments): I have a production database that has about 50+ migration files - some minor changes, some large changes. If I consolidated, the number of migrations needed would be about 12 or so. I would like to consolidate the migration files, but still be able to perform migrate:rollback on production - not that I would.

like image 613
Josh Bruce Avatar asked Sep 05 '17 13:09

Josh Bruce


People also ask

What is the advantage of Laravel migrations?

Advantages and Disadvantages of Laravel MigrationIt is a new framework. Web applications can be built on it quickly. It is easy to learn. The documentation is easily available.

What is migration squashing in Laravel?

Migration SquashingLaravel will write the new schema file to database/schema . Then when you run your migrations, Laravel will run the SQL from the schema file first before moving on to anything created later in the migrations folder. Note: Migration squashing is currently only supported for MySQL and Postgres.

How Database migration is used in Laravel?

Laravel Migration is an essential feature in Laravel that allows you to create a table in your database. It allows you to modify and share the application's database schema. You can modify the table by adding a new column or deleting an existing column.


1 Answers

You could use the library "xethron/migrations-generator" . Here's the repo.

After installation, basic usage: php artisan migrate:generate

Some Discussions about this are found at laracast.

like image 71
marlo Avatar answered Oct 05 '22 23:10

marlo