使用 Pomm 清除数据库数据

Purge the database data with Pomm

Doctrine 提供了一种简单的方法来清除保留模式的整个数据库

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

有没有办法用 Pomm 做到这一点?

在每个测试场景之间重置测试数据库而不用关心外键会特别有用。

使用Doctrine时,是schema authority,表示数据库schema是使用PHP绘制的。对于 Pomm,Postgres 是使用 SQL 的架构权威,因此 Pomm 不知道如何删除/重新创建数据库结构。使用模型管理器时,可以使用简单的 TRUNCATE my_table CASCADE .

如果要将数据库恢复到之前的状态,可以考虑使用PostgreSQL强大的事务机制:

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