README.md in scenic-1.7.0 vs README.md in scenic-1.8.0

- old
+ new

@@ -2,11 +2,10 @@ ![Scenic Landscape](https://user-images.githubusercontent.com/152152/49344534-a8817480-f646-11e8-8431-3d95d349c070.png) [![Build Status](https://github.com/scenic-views/scenic/actions/workflows/ci.yml/badge.svg)](https://github.com/scenic-views/scenic/actions/workflows/ci.yml) [![Documentation Quality](http://inch-ci.org/github/scenic-views/scenic.svg?branch=master)](http://inch-ci.org/github/scenic-views/scenic) -[![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com) Scenic adds methods to `ActiveRecord::Migration` to create and manage database views in Rails. Using Scenic, you can bring the power of SQL views to your Rails application @@ -84,40 +83,37 @@ update to the version 2 schema. All that's left for you to do is tweak the schema in the new definition and run the `update_view` migration. ## What if I want to change a view without dropping it? -The `update_view` statement used by default will drop your view then create -a new version of it. +The `update_view` statement used by default will drop your view then create a +new version of it. This may not be desirable when you have complicated +hierarchies of dependent views. -This is not desirable when you have complicated hierarchies of views, especially -when some of those views may be materialized and take a long time to recreate. +Scenic offers a `replace_view` schema statement, resulting in a `CREATE OR +REPLACE VIEW` SQL query which will update the supplied view in place, retaining +all dependencies. Materialized views cannot be replaced in this fashion. -You can use `replace_view` to generate a CREATE OR REPLACE VIEW SQL statement -instead by adding the `--replace` option to the generate command: +You can generate a migration that uses the `replace_view` schema statement by +passing the `--replace` option to the `scenic:view` generator: ```sh $ rails generate scenic:view search_results --replace create db/views/search_results_v02.sql create db/migrate/[TIMESTAMP]_update_search_results_to_version_2.rb ``` -See Postgres documentation on how this works: -http://www.postgresql.org/docs/current/static/sql-createview.html - The migration will look something like this: ```ruby class UpdateSearchResultsToVersion2 < ActiveRecord::Migration def change replace_view :search_results, version: 2, revert_to_version: 1 end end ``` -You can run the migration and the view will be replaced instead. - ## Can I use this view to back a model? You bet! Using view-backed models can help promote concepts hidden in your relational data to first-class domain objects and can clean up complex ActiveRecord or ARel queries. As far as ActiveRecord is concerned, a view is @@ -125,10 +121,15 @@ ```ruby class SearchResult < ApplicationRecord belongs_to :searchable, polymorphic: true + # If you want to be able to call +Model.find+, you + # must declare the primary key. It can not be + # inferred from column information. + # self.primary_key = :id + # this isn't strictly necessary, but it will prevent # rails from calling save, which would fail anyway. def readonly? true end @@ -246,9 +247,14 @@ * [`scenic-sqlserver-adapter`](<https://github.com/ClickMechanic/scenic_sqlserver_adapter>) * [`scenic-oracle_adapter`](<https://github.com/cdinger/scenic-oracle_adapter>) Please note that the maintainers of Scenic make no assertions about the quality or security of the above adapters. + +**Related projects** + +- [`fx`](<https://github.com/teoljungberg/fx>) Versioned database functions and + triggers for Rails ## About Scenic is used by some popular open source Rails apps: [Mastodon](<https://github.com/mastodon/mastodon/>),