Class: MatViews::MatViewDefinition
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- MatViews::MatViewDefinition
- Defined in:
- app/models/mat_views/mat_view_definition.rb
Overview
Represents a **materialised view definition** managed by the engine.
A definition stores the canonical name and SQL for a materialised view and drives lifecycle operations (create, refresh, delete) via background jobs and services. It also tracks operational history through associated run models.
Validations ensure a sane PostgreSQL identifier for ‘name` and that `sql` begins with `SELECT` (case-insensitive).
Instance Attribute Summary collapse
-
#name ⇒ Object
validates :name that must be present, unique, and a valid identifier.
-
#refresh_strategy ⇒ String
One of ‘“regular”`, `“concurrent”`, `“swap”`.
-
#sql ⇒ Object
validates :sql that must be present and begin with SELECT.
-
#unique_index_columns ⇒ Object
validates :unique_index_columns to be non-empty when using ‘refresh_strategy=concurrent`.
Instance Method Summary collapse
- #last_run ⇒ Object
-
#mat_view_runs ⇒ ActiveRecord::Relation<MatViews::MatViewRun>
Historical create runs linked to this definition.
Methods included from MatViewsI18n
hint_for, human_enum_name, human_enum_options, human_name, placeholder_for
Instance Attribute Details
#name ⇒ Object
validates :name that must be present, unique, and a valid identifier.
64 65 66 67 |
# File 'app/models/mat_views/mat_view_definition.rb', line 64 validates :name, presence: true, uniqueness: true, format: { with: /\A[a-zA-Z_][a-zA-Z0-9_]*\z/ } |
#refresh_strategy ⇒ String
Returns one of ‘“regular”`, `“concurrent”`, `“swap”`.
97 |
# File 'app/models/mat_views/mat_view_definition.rb', line 97 enum :refresh_strategy, { regular: 0, concurrent: 1, swap: 2 } |
#sql ⇒ Object
validates :sql that must be present and begin with SELECT.
72 73 74 |
# File 'app/models/mat_views/mat_view_definition.rb', line 72 validates :sql, presence: true, format: { with: /\A\s*SELECT/i, message: :invalid } |
#unique_index_columns ⇒ Object
validates :unique_index_columns to be non-empty when using ‘refresh_strategy=concurrent`.
79 80 81 |
# File 'app/models/mat_views/mat_view_definition.rb', line 79 validates :unique_index_columns, length: { minimum: 1, message: :at_least_one }, if: -> { refresh_strategy == 'concurrent' } |
Instance Method Details
#last_run ⇒ Object
99 100 101 |
# File 'app/models/mat_views/mat_view_definition.rb', line 99 def last_run mat_view_runs.order(created_at: :desc).first end |
#mat_view_runs ⇒ ActiveRecord::Relation<MatViews::MatViewRun>
Historical create runs linked to this definition.
53 54 55 |
# File 'app/models/mat_views/mat_view_definition.rb', line 53 has_many :mat_view_runs, dependent: :destroy, class_name: 'MatViews::MatViewRun' |