README.md in scenic-0.2.0 vs README.md in scenic-0.2.1

- old
+ new

@@ -1,9 +1,13 @@ # Scenic ![Boston cityscape - it's scenic](http://www.california-tour.com/blog/wp-content/uploads/2011/11/skyline-boats-shutterstock-superreduced.jpg) +**Scenic (v0.2.0) is in an early stage of development. While it hasn't been +tested in an actual application, we are relatively confident in its readiness +and value, and stand ready to help resolve any issues it may have** + ## Description Scenic adds methods to ActiveRecord::Migration to create and manage database views in Rails. @@ -14,11 +18,11 @@ get full SQL syntax highlighting support in the editor of your choice. ## Great, how do I create a view? You've got this great idea for a view you'd like to call `searches`. Create a -definition file at `db/views/searches_v1.sql` which contains the query you'd +definition file at `db/views/searches_v01.sql` which contains the query you'd like to build your view with. Perhaps that looks something like this: ```sql SELECT statuses.id AS searchable_id, @@ -47,11 +51,11 @@ Run that migration and congrats, you've got yourself a view. The migration is reversible and it will be dumped into your `schema.rb` file. ## Cool, but what if I need to change that view? -Add the new query to `db/views/searches_v2.sql` and generate a new migration with +Add the new query to `db/views/searches_v02.sql` and generate a new migration with the following `change` method: ```ruby def change update_view :searches, version: 2, revert_to_version: 1 @@ -75,22 +79,52 @@ true end end ``` +## Can you make this easier? + +Sure thing. How about some generators? + +### Model generator + +The `scenic:model` generator builds you a model, view, and migration from +scratch. `db/views/[model]_v01.sql` wil be an empty file that you fill in only +the [query] portion of the view with. + +[query]: http://www.postgresql.org/docs/current/static/sql-createview.html + +``` +$ rails generate scenic:model search + create app/models/search.rb + create db/views/searches_v01.sql + create db/migrate/[TIMESTAMP]_create_searches.rb +``` + +### View generator + +The `scenic:view` generator is functionally equivalent to `scenic:model` except +that it doesn't create the model. Convenient. + +``` +$ rails generate scenic:view search + create db/views/searches_v01.sql + create db/migrate/[TIMESTAMP]_create_searches.rb +``` + +Subsequent invocations will create updated view versions and update migrations: + +``` +rails generate scenic:view search + create db/views/searches_v02.sql + create db/migrate/[TIMESTAMP]_update_searches_to_version_2.rb +``` + ## I don't need this view anymore. Make it go away. We give you `drop_view` too: ```ruby def change drop_view :searches, revert_to_version: 2 end ``` - -## Can you make this easier? - -Yeah, we're working on it. We're going to provide some generators that will take -some of the busy work of file creation away. We'll create the SQL file, the -migration, and optionally the model for you. - -Check out the issue tracker for our other plans.