ViewModel
Some model magic for ActiveRecord Models & Postgresql >= 8.2
Usage: In your Model:
class MyView < ActiveRecord::Base
include ViewModel
@view_definition = "SELECT * from table1 join table2 on table2.id = table1.test_id"
end
Migrate this model:
# MyView.migrate!
Warning: There is no automatic versioning support and no fallback functionality. It is highly recommended to store changes in SVN or similar.
Depending Views:
If you have depending views which would block a “DROP VIEW”, ViewModel automatically searches the models, checks if they have a view_definition, drops them and recreates them after the current view is migrated.
Creating an Adapter for your database:
- check how to get view dependencies on your desired database
- create a new adapter under adapters/
- name the class after the ActiveRecord adapter name
Get it with:
ActiveRecord::Base.connection.class.to_s.demodulize
- require view_model
TODO:
-
document code!
-
create tests!
-
support more databases?