Adds methods to ActiveRecord::Migration for creating and managing versioned database views in Rails applications.
Scenic is a Ruby gem that adds methods to ActiveRecord::Migration for creating and managing versioned database views in Rails applications. It solves the problem of managing complex SQL views within Rails migrations by providing a convention for versioning, reversible migrations, and keeping SQL definitions in separate files. This allows developers to leverage the power of SQL views without switching their schema format to SQL.
Rails developers working with PostgreSQL who need to manage complex queries, aggregate data, or create view-backed models for cleaner domain logic. It's particularly useful for teams maintaining large applications with intricate database relationships.
Developers choose Scenic because it seamlessly integrates SQL views into Rails' migration system, providing versioning, reversibility, and SQL file management out of the box. Its support for materialized views and view-backed models makes it a robust solution for optimizing database performance and organization.
Versioned database views for Rails
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Keeps view definitions in separate, versioned SQL files with full syntax highlighting, making complex queries easier to manage and test during development.
Provides built-in support for materialized views with options for concurrent refreshes and unique indexes, optimizing query performance in PostgreSQL.
Enables ActiveRecord models to be backed by database views, promoting clean domain objects and simplifying complex ActiveRecord or ARel queries.
Offers replace_view for in-place updates and side_by_side for materialized views to minimize downtime and locking issues during schema changes.
First-party support is only for PostgreSQL; other databases rely on unvetted third-party adapters, which the maintainers explicitly do not endorse for quality or security.
View-backed models require manual primary key configuration, as views lack inherent primary keys, causing errors with standard ActiveRecord methods like find, first, and last.
Views do not automatically reflect schema changes in underlying tables; adding columns requires manually updating the view definition, adding maintenance overhead.