Closed paupino closed 6 years ago
Reproducing test: https://github.com/paupino/psqlpack/tree/bug/dependency_graph_generation
This is only really an issue due to the way that tables are created all at once. Ideally a table could be created all at once without concern, however worst case scenario is that we fall back to a micro transactional approach.
The graph generated for the above example is this:
Technically, the ordering is correct if you look at the individual components (i.e. fk_public_transaction__allocation_id
relies on public.allocation
implicitly via id
).
I suspect this happens due to natural ordering of table names via g.node_identifiers()
. It builds up the DFS starting from allocation therefore when it reverses the order it places transaction first.
Ordering is currently:
Table: public.transaction
Column: public.transaction.id
Column: public.transaction.allocation_id
Constraint: public.transaction.pk_public_transaction
Table: public.allocation
Column: public.allocation.id
Constraint: public.allocation.pk_public_allocation
Constraint: public.transaction.fk_public_transaction__allocation_id
I have replicated with a very basic example:
This gives the error:
relation "public.allocation" does not exist
.