I am porting a MongoDB database over to a PostgreSQL (relational) database. I would like to perform this task concurrently, and I have developed code with parallelism in mind, but dependencies between tables (foreign keys) are not allowing it. This happens when a row (containing a foreign key) is added, but the table it points to hasn't had that record (primary key) added, throwing the following error:
insert or update on table "observernodeoccurrence" violates foreign key constraint "observernodeoccurrence_canonical_id_fkey" DETAIL: Key (canonical_id)=(ba956ef88bcc366fa7d1d5fb696fe98d) is not present in table "canonical".
This is logical, since the record being added, which contains a FK, is pointing to a record from another table which hasn't been added yet.
Possible solution: I thought about a solution consisting of declaring the foreign keys as regular TEXT attributes, containing no dependencies to other tables. As soon as the port was completed, those attributes would be converted back to foreign keys. This way, every foreign key would have a record in the destiny table.
Is there a way to achieve this in Postgresql? If not, is there any other thing I can try to achieve parallelism in populating the database?