Pattern 24 — Create a Consumer View
Class: Create (consumer view) | Test: test_cookbook_24_create_consumer_view
When to use
Expose a stream table through a stable, schema-qualified view for application or API consumption. The application always connects to the stable view name; the underlying stream table can be replaced transparently.
Migration file
-- migrations/consumers/c24_orders_view.sql
-- @aqueduct:kind = consumer
-- @aqueduct:source = public.c24_orders
-- @aqueduct:expose_as = api.orders
SELECT customer_id, total FROM public.c24_orders WHERE total > 0;
Plan output
+ api.orders [consumer create] exposes public.c24_orders
Benefits
- Applications connect to
api.orders— the name never changes. - On blue/green deployments, the view is swapped atomically with
ACCESS EXCLUSIVEon the view (not the underlying table), making the cutover sub-millisecond.
Notes
- Consumer views are tracked in
aqueduct.consumer_viewsand listed withaqueduct consumers list. - The
@aqueduct:expose_asschema must exist beforeaqueduct applyruns. Create it with a pre-hook or Atlas migration.