Class: ActiveRecord::Materialized::MigrationBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord/materialized/migration_builder.rb

Overview

The data a generated migration needs to provision a view's empty cache table: table name, migration class name, target version, and inferred columns/types. The file itself is produced by Rails' generator tooling.

Instance Method Summary collapse

Constructor Details

#initialize(view_class) ⇒ MigrationBuilder

Returns a new instance of MigrationBuilder.



9
10
11
# File 'lib/activerecord/materialized/migration_builder.rb', line 9

def initialize(view_class)
  @view_class = view_class
end

Instance Method Details

#column_definitionsObject



25
26
27
# File 'lib/activerecord/materialized/migration_builder.rb', line 25

def column_definitions
  CacheTableSchema.column_definitions(@view_class.connection, @view_class.resolved_source)
end

#index_definitionCacheTableSchema::IndexDefinition?

The partition-key index the migration should add (nil for a non-grouped view). Incremental maintenance is keyed on these columns, so the generated migration indexes them by default.



33
34
35
# File 'lib/activerecord/materialized/migration_builder.rb', line 33

def index_definition
  CacheTableSchema.index_definition(@view_class)
end

#migration_class_nameObject



17
18
19
# File 'lib/activerecord/materialized/migration_builder.rb', line 17

def migration_class_name
  "Create#{table_name.camelize}"
end

#migration_versionObject



21
22
23
# File 'lib/activerecord/materialized/migration_builder.rb', line 21

def migration_version
  ::ActiveRecord::Migration.current_version
end

#table_nameObject



13
14
15
# File 'lib/activerecord/materialized/migration_builder.rb', line 13

def table_name
  @view_class.table_name
end