Scenic supports materialized views via the --materialized flag in the scenic:view or scenic:model generators.
Refreshing Materialized Views
If you use scenic:model, a .refresh method is added to the model class:
# Non-concurrent refresh (locks the view)
Model.refresh
# Concurrent refresh (requires Postgres 9.4+ and a unique index)
Model.refresh(concurrently: true)
# Cascading refresh (refreshes dependent views)
Model.refresh(cascade: true)
Updating Materialized Views with side_by_side strategy
Because materialized views cannot be updated in-place with REPLACE VIEW, use the --side-by-side option during generation. This creates a migration using the side_by_side strategy, which prepares the new version under a temporary name to minimize lock time.
$ rails generate scenic:view search_results --materialized --side-by-side