-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Thanks for fixing functions-before-tables ordering in v1.7.2 — that works great now.
However, view-to-view dependencies within a schema are still ordered alphabetically. This causes failures when a view depends on another view that sorts later in the alphabet.
Reproduction
Given these views in the same schema:
-- item_summary.sql
CREATE VIEW item_summary AS
SELECT ... FROM membership m JOIN item i ON ...;
-- dashboard.sql (depends on item_summary)
CREATE VIEW dashboard AS
SELECT ... FROM item_summary s JOIN ...;pgschema emits CREATE VIEW dashboard before CREATE VIEW item_summary because "dashboard" < "item_summary" alphabetically. This fails with:
ERROR: relation "item_summary" does not exist
Impact
When a foundational view has a name that sorts after the views that depend on it, there's no naming workaround. In our schema, several views depend on a single base view whose name sorts after all of them alphabetically.
Current workaround
We split the schema into multiple sub-phases and run pgschema apply multiple times for one schema:
- Functions + the foundational view only
- + intermediate dependent views
- Full schema
This works but defeats the purpose of declarative schema management.
Expected behavior
pgschema should resolve view dependencies (via pg_depend or by parsing FROM clauses) and emit CREATE VIEW statements in dependency order.