1

I came across a situation where having hundreds of database tables and rewriting them all into Laravel Migrations does not seems... a very nice task.

I know Laravel Migrations is a really cool feature top keep track of database changes among with some VCS such an GIT

BUT... Not being able to update the database with php artisan migrate in the production server technically drops away the use of migrations making it real pain... manually changing table by table adding columns, index or foreign keys.

QUESTION: Is there any way for Laravel Migrations to write the changes (SQL statements) to a file instead of doing it directly to the database?

David Lavieri
  • 1,060
  • 1
  • 8
  • 19
  • Maybe you can run migrations in raw SQL? So you don't have to write them into Laravel syntax http://stackoverflow.com/questions/28787293/run-this-raw-sql-in-migration – Claudio King May 13 '16 at 19:37

1 Answers1

0

I've come accross the same problem many times, and i did the following to solve it

First when you finally finish the mysql database/structure and you are about to publish the application you must set a "mark" on the database,export it correctly and declare that its the version 1 of database. After that you can start writing migrations and you will be more confident plus you will avoid many problems such us invalid data types, bad structure and other, others.

Another way is making use of toSql make it output under a folder lets say rawSqlDatabaseMigrations with timestamps and such.

Also you could just keep manually writing SQL and use migration only with DB::raw.

Gntem
  • 6,949
  • 2
  • 35
  • 48