Module: ActiveRecord::Materialized::CacheTableSchema Private

Extended by:
T::Sig
Defined in:
lib/activerecord/materialized/cache_table_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.

Infers a view’s cache-table columns from its source relation and provisions the table.

Defined Under Namespace

Classes: ColumnDefinition

Class Method Summary collapse

Class Method Details

.column_definitions(connection, relation) ⇒ 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.



37
38
39
40
41
42
43
# File 'lib/activerecord/materialized/cache_table_schema.rb', line 37

def column_definitions(connection, relation)
  result = connection.exec_query(relation.limit(1).to_sql)
  sample = result.rows.first
  result.columns.each_with_index.map do |name, index|
    ColumnDefinition.new(name: name, type: type_for_value(sample&.at(index)))
  end
end

.create_table!(view_class, table_name, relation) ⇒ 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.



30
31
32
# File 'lib/activerecord/materialized/cache_table_schema.rb', line 30

def create_table!(view_class, table_name, relation)
  build_table!(view_class.connection, table_name, relation)
end

.ensure_table!(view_class, relation) ⇒ 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.



22
23
24
25
26
27
# File 'lib/activerecord/materialized/cache_table_schema.rb', line 22

def ensure_table!(view_class, relation)
  return if view_class.table_exists?

  build_table!(view_class.connection, view_class.table_name, relation)
  view_class.reset_column_information
end