Search code examples
phppostgresqlpomm

Purge the database data with Pomm


Doctrine provides a simple way to purge a whole database keeping the schema

$purger = new ORMPurger($this->getEntityManager());
$purger->purge();

Is there a way to do so with Pomm ?

It would be specially useful to reset the test DB between each test scenarios without having to care about foreign keys.


Solution

  • When using Doctrine, it is the schema authority which means the database schema is drawn using PHP. In the case of Pomm, Postgres is the schema authority using SQL hence Pomm has no idea on how to drop / recreate the database structure. When using the Model Manager, it could be a way using a simple TRUNCATE my_table CASCADE .

    If you want to restore the database in a previous state, consider using PostgreSQL’s powerful transaction mechanism:

    BEGIN;
    -- do tests here
    ROLLBACK; -- restore the database as before