whatisgithub

What is scenic?

scenic-views/scenic — explained in plain English

Analysis updated 2026-05-18

3,621RubyAudience · developerComplexity · 2/5Setup · moderate

In one sentence

A Ruby gem that lets Rails apps manage database views with versioned SQL files and regular, reversible migrations.

Mindmap

mindmap
  root((Scenic))
    What it does
      Adds database views to Rails
      Versions view SQL files
      Reversible migrations
    Tech stack
      Ruby
      Rails
      PostgreSQL
    Use cases
      Create versioned SQL views
      Back models with views
      Use materialized views
    Audience
      Rails developers
      Backend engineers

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Create a versioned database view with a generator instead of writing raw SQL in a migration.

USE CASE 2

Back an ActiveRecord model with a view to expose complex joined or calculated data as a first-class model.

USE CASE 3

Add a materialized view to speed up an expensive query and refresh it on a schedule.

USE CASE 4

Update an existing view's definition while keeping migration history reversible.

What is it built with?

RubyRailsActiveRecordPostgreSQL

How does it compare?

scenic-views/scenicfatfreecrm/fat_free_crmnesquena/rabl
Stars3,6213,6263,631
LanguageRubyRubyRuby
Setup difficultymoderatemoderateeasy
Complexity2/53/53/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Requires a Rails app already using PostgreSQL, other databases need a third-party adapter.

Not stated in the explanation provided.

So what is it?

Scenic is a Ruby gem for Rails applications that adds database views to your project without giving up the standard Rails migration workflow. A database view is a saved SQL query that, from the application's perspective, looks and behaves like a regular table: you can query it, sort it, and filter it the same way, but the database computes the data from a SQL statement rather than storing it directly. Without a tool like Scenic, adding a view to a Rails project typically means writing raw SQL strings inside migration files, which can become fragile and hard to maintain. Scenic introduces a versioning system: each version of a view gets its own SQL file stored in db/views/, named with a version number. When you update a view, a new version file is created alongside the old one, and a Rails migration records the transition. Rollbacks work correctly, and the history stays readable. Rails generators are included for creating both views and view-backed models. Running a generator creates the SQL file and the accompanying migration at the same time. You write the actual query in the SQL file and get full syntax highlighting in your editor of choice. A view can back a regular ActiveRecord model, meaning the model reads from the view just as it would from a plain database table. This is useful for surfacing complex calculated or joined data as first-class objects in your application code rather than embedding long queries throughout the codebase. Scenic also supports materialized views, which store query results as a cached snapshot in the database that can be refreshed on a schedule. Materialized views can be indexed, which makes them practical for expensive queries that would be slow to compute on every request. Scenic supports both concurrent and non-concurrent refresh strategies. The gem ships with PostgreSQL support, and the adapter interface is configurable for other databases.

Copy-paste prompts

Prompt 1
Help me set up Scenic in my Rails app to create a database view backed by ActiveRecord.
Prompt 2
Show me how to use Scenic's generator to create a materialized view with a refresh schedule.
Prompt 3
Explain how Scenic versions view SQL files and keeps migrations reversible.
Prompt 4
Write a Scenic view-backed model for combining data from two tables in my Rails app.

Frequently asked questions

What is scenic?

A Ruby gem that lets Rails apps manage database views with versioned SQL files and regular, reversible migrations.

What language is scenic written in?

Mainly Ruby. The stack also includes Ruby, Rails, ActiveRecord.

What license does scenic use?

Not stated in the explanation provided.

How hard is scenic to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is scenic for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.