Class: CreateMatViewDefinitions

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/mat_views/install/templates/create_mat_view_definitions.rb

Overview

This migration creates the mat_view_definitions table, which stores definitions for materialised views. It includes fields for the view name, SQL definition, refresh strategy, schedule, unique index columns, dependencies, last refreshed timestamp, and timestamps for creation and updates.

Instance Method Summary collapse

Instance Method Details

#changeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/generators/mat_views/install/templates/create_mat_view_definitions.rb', line 12

def change
  create_table :mat_view_definitions do |t|
    t.string :name, null: false, comment: 'The name of the materialised view'
    t.text :sql, null: false, comment: 'The SQL query defining the materialised view'
    # refresh_strategy can be
    # regular: 0 - Default strategy, in-place refresh.
    # concurrent: 1 - Concurrent refresh, requires at least one unique index.
    # swap: 2 - Swap the materialised view with a new one, uses more memory.
    t.integer :refresh_strategy, default: 0, null: false,
                                 comment: 'Strategy for refreshing the materialised view. Options: regular, concurrent, swap'
    t.string :schedule_cron, comment: 'Cron schedule for automatic refresh of the materialised view'
    t.jsonb :unique_index_columns, default: [], comment: 'Columns used for unique indexing, if any'
    t.jsonb :dependencies, default: [],
                           comment: 'Dependencies of the materialised view, such as other views or tables'
    t.timestamps
  end
end