Skip to content

Conversation

@JackTYM
Copy link

@JackTYM JackTYM commented Dec 30, 2025

Summary

  • Add .dependsOn() to pgMaterializedView to capture view dependencies.
  • Persist dependsOn in snapshots/serialization for PG views.
  • Order CREATE/DROP view statements topologically and recreate dependent views when a base view changes.

Usage

const baseView = pgMaterializedView('base_view', { id: integer('id') }).as(sql`SELECT "id" FROM ${users}`);
const aggView = pgMaterializedView('agg_view', { id: integer('id') })
  .dependsOn(baseView)
  .as(sql`SELECT "id" FROM "base_view"`);

Tests

   ✓ create materialized views in dependency order 1ms
   ✓ drop materialized views in dependency order 1ms
   ✓ recreate dependent materialized views when base changes 2ms

Fixes #4520

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Creating a Materialized View that depends on another fails because of creation order

1 participant