Class: MatViews::Services::CreateView
- Inherits:
-
BaseService
- Object
- BaseService
- MatViews::Services::CreateView
- Defined in:
- lib/mat_views/services/create_view.rb
Overview
Service responsible for creating PostgreSQL materialised views.
The service validates the view definition, handles existence checks, executes ‘CREATE MATERIALIZED VIEW … WITH DATA`, and, when the refresh strategy is `:concurrent`, ensures a supporting UNIQUE index.
Options:
-
‘force:` (Boolean, default: false) → drop and recreate if the view already exists
-
‘row_count_strategy:` (Symbol, default: :none) → one of `:estimated`, `:exact`, or `:none or nil` to control row count reporting
Returns a MatViews::ServiceResponse
Constant Summary
Constants inherited from BaseService
BaseService::ALLOWED_ROW_STRATEGIES, BaseService::DEFAULT_NIL_STRATEGY, BaseService::DEFAULT_ROW_STRATEGY, BaseService::UNKNOWN_ROW_COUNT
Instance Attribute Summary collapse
-
#force ⇒ Boolean
readonly
Whether to force recreation (drop+create if exists).
Attributes inherited from BaseService
#definition, #request, #response, #row_count_strategy, #use_transaction
Instance Method Summary collapse
-
#initialize(definition, force: false, row_count_strategy: :estimated) ⇒ CreateView
constructor
Supports optional row count strategies: - ‘:estimated` → approximate, using `pg_class.reltuples` - `:exact` → accurate, using `COUNT(*)` - `nil` → skip row count.
Methods inherited from BaseService
Constructor Details
#initialize(definition, force: false, row_count_strategy: :estimated) ⇒ CreateView
Supports optional row count strategies:
-
‘:estimated` → approximate, using `pg_class.reltuples`
-
‘:exact` → accurate, using `COUNT(*)`
-
‘nil` → skip row count
54 55 56 57 58 59 60 61 |
# File 'lib/mat_views/services/create_view.rb', line 54 def initialize(definition, force: false, row_count_strategy: :estimated) super(definition, row_count_strategy: row_count_strategy) @force = force # Transactions are disabled if unique_index_columns are present because # PostgreSQL does not allow creating a UNIQUE INDEX CONCURRENTLY inside a transaction block. # If a unique index is required (for concurrent refresh), we must avoid wrapping the operation in a transaction. @use_transaction = definition.unique_index_columns.none? end |
Instance Attribute Details
#force ⇒ Boolean (readonly)
Whether to force recreation (drop+create if exists).
43 44 45 |
# File 'lib/mat_views/services/create_view.rb', line 43 def force @force end |