Module: ScenicMigrationHelpers
- Defined in:
- lib/scenic_migration_helpers.rb
Overview
Migration mix-in that wraps the Scenic gem's create_view /
replace_view helpers with index management and column-comment
application, so SQL-defined materialised views can be evolved
without losing their attached indexes or db/comments/*.yml doc.
Instance Method Summary collapse
-
#create_materialized_view(view_name, version: nil, async_indexing: true) ⇒ Object
Create a new materialized view with indexes.
-
#update_materialized_view(view_name, version: nil, revert_to_version: nil, async_indexing: true) ⇒ Object
Update an existing materialized view to a new version with indexes Scenic's update_view drops and recreates the view, so indexes need to be reapplied.
Instance Method Details
#create_materialized_view(view_name, version: nil, async_indexing: true) ⇒ Object
Create a new materialized view with indexes
8 9 10 11 12 13 14 15 |
# File 'lib/scenic_migration_helpers.rb', line 8 def create_materialized_view(view_name, version: nil, async_indexing: true) version ||= latest_version(view_name) create_view(view_name, version: version, materialized: true) apply_comments(view_name) apply_indexes(view_name, async_indexing: async_indexing) end |
#update_materialized_view(view_name, version: nil, revert_to_version: nil, async_indexing: true) ⇒ Object
Update an existing materialized view to a new version with indexes
Scenic's update_view drops and recreates the view, so indexes need to be reapplied
19 20 21 22 23 24 25 26 27 |
# File 'lib/scenic_migration_helpers.rb', line 19 def update_materialized_view(view_name, version: nil, revert_to_version: nil, async_indexing: true) version ||= latest_version(view_name) revert_to_version ||= version - 1 update_view(view_name, version: version, revert_to_version: revert_to_version, materialized: true) apply_comments(view_name) apply_indexes(view_name, async_indexing: async_indexing) end |