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

MaxGiting's avatar

Running migrations on a pre migration database

I am currently working through Adams Wathans Testing-Driven Laravel series and I want to test interacting with my database so I am trying use the DatabaseMigrations trait.

The issue is my database predates the use of migrations so I don't have migrations to create every table and its structure. There are over 300 migrations from over 3 years and 160 database tables.

Currently the DatabaseMigrations trait can run the first 200 migrations until it runs one on a table that does not exist and even if they all ran I would still be missing 60 or so tables.

I cannot see a way to create the database with new migrations as any new migrations cannot be run in the production server and even if they could I do not know the database structure from over 3 years ago.

Another option I have thought about is taking a structural snapshot of the database and importing that at the very beginning of my tests. But then any new migrations I have would not be applied if I have to turn off the DatabaseMigrations trait.

What I am asking is. Does anyone think I can use DatabaseMigrations (Currently I do not).

What other method would anyone suggest to keep a large database in sync with it's tests without building it in each individual test?

0 likes
0 replies

Please or to participate in this conversation.