mardi 1 mai 2018

Repopulating Postgres database with seed data for testing

I am trying to create some integration tests for my app, and part of this I want to seed my application every time the tests run. The database needs to remain connected however, so dropdb / createdb is not an option.

I am currently doing:

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

Before the test, and:

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

To restore the DB after every test runs.

This doesn't seem to work however as the pg_restore command throws lots of errors:

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

And it carries on like this... I thought --clean was meant to completely drop everything, however pg_restore is complaining that it cannot drop tables / views ? Is there something wrong with my combination of flags in pg_dump / pg_restore ?

Aucun commentaire:

Enregistrer un commentaire