I am using phpunit to create dev db. I wrote a short script that fetches XML data from a live database, and I used it on a table, dragging something sensitive and deleting. I donβt need it. The schema for my dev database never changes and never restores. Only data is deleted and recreated every phpunit run.
It may not be the right solution for everyone, because Dev will never be well synchronized to the stage / production, but I do not need to do this.
The main advantage is how little data I need for dev db. This is about 12,000 xml lines and processes 30 different tables. Some small main tables are preserved because I do not write them, and many tables are empty because I do not use them.
The database is a representative sample and is very small. Not enough to edit as a text file and only a few seconds to fill up every time I run the tests.
Here's what it looks like at the top of every PHPUnit test. There is good documentation for PHPUnit and DbUnit
<?php require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'top.php'; require_once "PHPUnit/Extensions/Database/TestCase.php"; class SomeTest extends PHPUnit_Extensions_Database_TestCase { public function getConnection() { $database = MY_DB $hostname = MY_HOST $user = MY_USER $password = MY_PASS $pdo = new PDO("mysql:host=$hostname;dbname=$database", $user, $password); return $this->createDefaultDBConnection($pdo, $database); } public function getDataSet() { return $this->createXMLDataSet(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Tests/_files/seed.xml'); } }
So, now you only need the initial file that DbUnit reads to re-populate your database every time unit tests are called.
Start by copying your complete database twice. One of them will be your dev database, and the second will be your "primordial" database, which you can use to upload XML data if you encounter key problems.
Then use something like my xml dumper again in the prisine database to get your xml dumps and start creating your semester file.
generate_flat_xml.php -tcatalog_product_entity -centity_id,entity_type_id,attribute_set_id,type_id,sku,has_options,required_options -oentity_id >> my_seed_file.xml
Edit the seed file to use only what you need. The small size of dev db means that you can analyze the differences just by looking at your database compared to text files. Not to mention that it is much faster than less data.