Class: ActiveRecord::Materialized::MigrationBuilder
- Inherits:
-
Object
- Object
- ActiveRecord::Materialized::MigrationBuilder
- 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
- #column_definitions ⇒ Object
-
#index_definition ⇒ CacheTableSchema::IndexDefinition?
The partition-key index the migration should add (nil for a non-grouped view).
-
#initialize(view_class) ⇒ MigrationBuilder
constructor
A new instance of MigrationBuilder.
- #migration_class_name ⇒ Object
- #migration_version ⇒ Object
- #table_name ⇒ Object
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_definitions ⇒ Object
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_definition ⇒ CacheTableSchema::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_name ⇒ Object
17 18 19 |
# File 'lib/activerecord/materialized/migration_builder.rb', line 17 def migration_class_name "Create#{table_name.camelize}" end |
#migration_version ⇒ Object
21 22 23 |
# File 'lib/activerecord/materialized/migration_builder.rb', line 21 def migration_version ::ActiveRecord::Migration.current_version end |
#table_name ⇒ Object
13 14 15 |
# File 'lib/activerecord/materialized/migration_builder.rb', line 13 def table_name @view_class.table_name end |