Dependency Ordering
Published 05 June 2025
When changes are made to schema objects robust comparison engines need to consider dependencies in order to avoid violating constraints or referencing objects that haven't been created.
- Views depend on the table(s) they select from
- Triggers depend on the table it is attached to
- A foreign key depends on the parent table
Without strong dependency ordered scripts, the output of a comparison tool can't be relied on to generate scripts that will deploy successfully.
Tools such as pgAdmin Schema Diff are limited in this capacity, and frequently generates scripts which can't run due to incorrect dependency order. This limitation is recognized in the comment included at the top of pgAdmin's script:
-- For the circular dependencies, the order in which Schema Diff writes the objects is not very sophisticated
-- and may require manual changes to the script to ensure changes are applied in the correct order.
-- Please report an issue for any failure with the reproduction steps.
The comparison engine that powers pgCompare builds an accurate dependency graph based on analysing the dependencies of all the schema objects, which is built up from both meta data in the database as well as additional parsing of the SQL for code objects. This ensures that pgCompare can be relied on to produce robust and reliable deployment scripts, minimising deployment issues and downtime.