db:import_dump does not clean existing database prior to re-importing
It might be lack of my understanding / docs, but trying to use backup and restore on another server, the sequence that I've done was:
1. backup old server (as described in the manual)
2. create a new server, run foreman installer (so new database gets created) followed by a db restore (and recovering /etc/foreman and puppet ssl dir).
at that point, the recovery fails, as the existing database already is migrated (even if its the same version) so fk errors are present, for example:
pg_restore: [archiver (db)] could not execute query: ERROR: constraint "tokens_host_id_fk" for relation "tokens" already exists Command was: ALTER TABLE ONLY tokens ADD CONSTRAINT tokens_host_id_fk FOREIGN KEY (host_id) REFERENCES hosts(id);
the solution was to add --clean to the backup rake task prior.