【问题标题】:Repopulating Postgres database with seed data for testing使用种子数据重新填充 Postgres 数据库以进行测试
【发布时间】:2018-05-01 10:17:10
【问题描述】:

我正在尝试为我的应用创建一些集成测试, 其中一部分我想每次都播种我的应用程序 测试运行。然而,数据库需要保持连接, 所以dropdb / createdb 不是一个选项。

我目前正在做:

pg_dump -F custom -O -x -d test-db > ./tests/test-db

测试前,并且:

pg_restore --clean -d test-db ./tests/test-db

在每次测试运行后恢复数据库。

这似乎不起作用,因为pg_restore 命令会引发很多错误:

pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 3771; 2618 175960 RULE skilled_outcome_group _RETURN dan
pg_restore: [archiver (db)] could not execute query: ERROR:  cannot drop rule _RETURN on view public.skilled_outcome_group because view public.skilled_outcome_group requires it
pg_restore: [archiver (db)] Error from TOC entry 184; 1259 174070 TABLE outcome_group_skill dan
pg_restore: [archiver (db)] could not execute query: ERROR:  cannot drop table public.outcome_group_skill because other objects depend on it

它就这样继续下去......我以为--clean 是为了彻底放弃一切, 但是pg_restore 抱怨它不能删除表/视图?我在 pg_dump / pg_restore 中的标志组合有问题吗?

【问题讨论】:

    标签: postgresql testing database-restore


    【解决方案1】:

    pg_restore 可用于生成导出脚本,在这种情况下可以使用一些标志,例如--cleandoc

    这个脚本输出等价于纯文本输出格式 pg_dump。因此,一些控制输出的选项是 类似于 pg_dump 选项。

    当你运行pg_restore恢复数据库时,它只能应用脚本中存在的命令。

    您需要使用--clean 选项运行pg_dump,以便在恢复数据库时应用此命令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      • 2015-01-18
      • 2020-03-04
      • 2011-02-08
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      相关资源
      最近更新 更多