【发布时间】:2020-03-10 14:21:47
【问题描述】:
我正在编写集成测试,并希望在每次测试后清理(postgres)数据库。所以我假设对所有(实际上只是大部分)表进行级联截断操作是可行的方法。
我正在开发一个使用 Kotlin、Spring 和 Jooq 的应用程序,这就是为什么我使用 truncateCascade 对 Truncator 类进行映像,我可以将其自动连接到我的 SpringBootTest 类中。
import org.jooq.DSLContext
import org.jooq.Table
@Service
class Truncator(private val dsl: DSLContext) {
fun truncateCascade(tables: List<Table<*>>) {
dsl.truncate ...
}
// single truncate work only for tables without foreign key constraints
// so I can't simply iterate over all tables and call this method.
// fun truncate(table: Table<*>) {
// dsl.truncate(table).execute()
// }
}
基本上我正在寻找truncateCascade 的实现(假设这不是错误的方法)。
我在 Jooq 的 TruncateCascadeStep 上找到了文档,并在调查此问题时提到了 continueIdentity 或 restartIdentity,但我对 Jooq 或一般数据库的经验不足,无法将其拼凑起来。
【问题讨论】:
标签: postgresql jooq truncate cascade