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) ⇒ void
Create a new materialized view with indexes.
-
#update_materialized_view(view_name, version: nil, revert_to_version: nil, async_indexing: true) ⇒ void
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) ⇒ void
This method returns an undefined value.
Create a new materialized view with indexes
9 10 11 12 13 14 15 16 |
# File 'lib/scenic_migration_helpers.rb', line 9 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) ⇒ void
This method returns an undefined value.
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
21 22 23 24 25 26 27 28 29 |
# File 'lib/scenic_migration_helpers.rb', line 21 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 |