Module: ActiveRecord::Materialized::Metadata::Schema Private

Extended by:
T::Sig
Defined in:
lib/activerecord/materialized/metadata/schema.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Lazily provisions and migrates the materialized-view metadata table.

Class Method Summary collapse

Class Method Details

.create_metadata_table!(connection) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/activerecord/materialized/metadata/schema.rb', line 26

def (connection)
  connection.create_table(::ActiveRecord::Materialized., force: :cascade) do |t|
    t.string :view_name, null: false
    t.datetime :last_refreshed_at
    t.boolean :refreshing, null: false, default: false
    t.boolean :dirty, null: false, default: true
    t.boolean :warm, null: false, default: false
    t.integer :row_count
    t.integer :refresh_duration_ms
    t.text :last_error
    t.text :maintenance_payload
    t.timestamps
  end
  connection.add_index(::ActiveRecord::Materialized., :view_name, unique: true)
end

.ensure_dirty_column!(connection) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/activerecord/materialized/metadata/schema.rb', line 43

def ensure_dirty_column!(connection)
  return unless MetadataRecord.table_exists?
  return if MetadataRecord.column_names.include?("dirty")

  connection.add_column(
    ::ActiveRecord::Materialized.,
    :dirty,
    :boolean,
    default: true,
    null: false
  )
end

.ensure_maintenance_payload_column!(connection) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
60
61
62
63
64
65
66
# File 'lib/activerecord/materialized/metadata/schema.rb', line 57

def ensure_maintenance_payload_column!(connection)
  return unless MetadataRecord.table_exists?
  return if MetadataRecord.column_names.include?("maintenance_payload")

  connection.add_column(
    ::ActiveRecord::Materialized.,
    :maintenance_payload,
    :text
  )
end

.ensure_table!(view_class) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
19
20
21
22
23
# File 'lib/activerecord/materialized/metadata/schema.rb', line 16

def ensure_table!(view_class)
  connection = view_class.connection
  (connection) unless MetadataRecord.table_exists?
  ensure_dirty_column!(connection)
  ensure_maintenance_payload_column!(connection)
  ensure_warm_column!(connection)
  MetadataRecord.reset_column_information
end

.ensure_warm_column!(connection) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/activerecord/materialized/metadata/schema.rb', line 69

def ensure_warm_column!(connection)
  return unless MetadataRecord.table_exists?
  return if MetadataRecord.column_names.include?("warm")

  connection.add_column(
    ::ActiveRecord::Materialized.,
    :warm,
    :boolean,
    default: false,
    null: false
  )
end