Views
Simple way to manage database views in rails.
Why
I did this gem to:
- Keep views definitions into separate sql files without versioning.
- Register views into schema.
- Control views from migrations.
Install
Put this line in your Gemfile:
gem 'views'
Then bundle:
$ bundle
Usage
Definitions
To generate a view:
$ bundle exec rails g view guitars
Edit the generated sql file db/views/guitars.sql:
SELECT
products.*
WHERE
products.category = 'Guitar'
Run the migration:
$ bundle exec rake db:migrate
Modifications
If you need to make a change, update the sql and run a migration with:
class ChangeGuitarsView < ActiveRecord::Migration
def change
change_view :guitars
end
end
If you want to drop it:
class DropGuitarsView < ActiveRecord::Migration
def change
drop_view :guitars
end
end
Contributing
Any issue, pull request, comment of any kind is more than welcome!
I will mainly ensure compatibility to Rails, AWS, PostgreSQL, Redis, Elasticsearch and FreeBSD.
Credits
This gem is maintained and funded by mmontossi.
License
It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.