DEV Community

Cover image for Laravel migration squashing and use of SQLite in automated testing
Damilola Emmanuel Olowookere
Damilola Emmanuel Olowookere

Posted on

Laravel migration squashing and use of SQLite in automated testing

I recently started taking more conscious efforts of improving the confidence I have in my deployments by writing automated tests.

However, since the introduction of Laravel's migration squashing, I have been having a hard time writing tests that use the RefreshDatabase trait. This is particularly because my development is typically with MySQL and testing is with SQLite.

The pains that this new squashing feature brings to sqlite testing is well documented, and Taylor himself acknowledges this, because he recommended against using in-memory sqlite db during testing (btw, in-memory sqlite db is usually the go-to solution for db testing in Laravel.)

Assuming you have already squashed your migrations into dump file and you have something like your mysql-schema.dump file, then the way I approach tests that includes migration is to:

Step 1. Convert the mysql-schema.dump SQL content to SQLite's SQL, and save the file. I typically use this tool

$ mysql2sqlite.sh mysql-schema.dump > converted.sql
Enter fullscreen mode Exit fullscreen mode

Step 2. Move the new dump to Laravel's schema dump folder, and ensure to name it appropriately with the connection name.

When I follow these steps, it is now much more comfortable writing tests that use the RefreshDatabase trait with SQLite as testing db. For as long as I do not come across a better way to handle this migration-squashing-sqlite-testing thingy, I may end up re-visiting this post. So, it is a note to future self!

I hope this post saves you a few minutes of debug time. See you in the next 😎

Top comments (0)