CodeIgniter Forums
Running test on existing database? - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Support (
+--- Thread: Running test on existing database? (/thread-81021.html)

Running test on existing database? - tgix - 01-14-2022

need some input on testing database-related code. Every night we mirror the production database to a local database server. I know that this may not be 100% kosher, but we would like to run CI4 tests using this database and not having to go through the hassle of setting up migrations and seeds for a pure testing database. Our CI/CO systems also have connectivity to the database mirror.
Setting up the testing database as described on nukes the database after one run, not good.
We have tried defining migrations and seeds, but with 100+ tables and relations, this is getting complex very quickly. We have also tried adding mysql restore commands but the database is 18 GB in size and it gets pretty slow.
Any input Greatly Appreciated!

RE: Running test on existing database? - kenjis - 01-14-2022

You can turn off migrations and seeders.

But if you changes the database data in your testing, you have to restore all the changed data after test executions.
If not, next time you run the test, it may fail.

RE: Running test on existing database? - MGatner - 01-17-2022

If this were me I would generate a SQLite3 database from the data to test (since it is a flat file) and then copy it in or `git restore` (depending on your CI\CD) the database between classes or tests (again, depends on what your tests modify). If your database is on another platform there are some slick conversion tools like to get it into SQLite3 format quickly.