I just begin to work on this big project that has zero tests. The idea is to TDD every new feature and/or bug, and with time we will increase the test coverage.
I don't make tests using SQLite in-memory DB. I do prefer to use MySql because it's the same DB that I use in production. Normally, in small projects, it's no problem, but with a big project, it is!
The problem that I faced is related to performance, a normal MySql instance running in-disk (M.2 SSD) takes around 90 secs to run all the migrations of this big project. There are over 200 tables to migrate, with a lot of relationships.
The solution for this problem was to set up MySql in memory too, using tmpfs with docker. This trick allowed me to decrease the migration time to only 10 secs, not bad, but really annoying if you just want to run 1 test! 10 secs to migrate, few milliseconds to test.
Laravel 8 just brought a new feature called Schema Dump: https://github.com/laravel/framework/pull/32275
I just saw this new feature and it really amused me, very nice! It will help a lot of people and save a lot of time. If you have a lot of migrations you can significantly reduce the time to migrate them all. This otherwise, does not resolve my problem. The number of migrations of the project is pretty close to 1 migration per table. No need to optimize anything here.
For curiosity sake, I took a Schema snapshot of the database and try to restore it with the MySql command line. It took around 3 secs to run the schema restore and set up everything:
mysql -h 127.0.0.1 -u root -P 3331 -p default < database/migrations.sql
For the time being, the test database stays migrated all the time, this way my test flow (one test one run) stays super fast!
I like to think that a single test should be like a button that you push and it lights green or red instantly.
My question: - It is possible to decrease even more the migration time for projects with a large number of tables? (only for testing)
I don't have inside out knowledge about MySql, perhaps I'm missing something...