Class: Metka::Generators::Strategies::IndexGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Metka::Generators::SqlIdentifier, Rails::Generators::Migration
Defined in:
lib/generators/metka/strategies/index/index_generator.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_SOURCE_COLUMNS =
[ "tags" ].freeze

Constants included from Metka::Generators::SqlIdentifier

Metka::Generators::SqlIdentifier::IDENTIFIER

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dir) ⇒ Object



78
79
80
# File 'lib/generators/metka/strategies/index/index_generator.rb', line 78

def self.next_migration_number(dir)
  ::ActiveRecord::Generators::Base.next_migration_number(dir)
end

Instance Method Details

#generate_migrationObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/generators/metka/strategies/index/index_generator.rb', line 40

def generate_migration
  validate_sql_identifiers!(
    "--source-table-name" => [ source_table_name ],
    "--source-columns" => source_columns
  )

  unless sqlite?
    say_status :skipped,
      "the index strategy targets SQLite; PostgreSQL GIN indexes already serve tag queries",
      :yellow
    return
  end

  migration_template "migration.rb.erb", "db/migrate/#{migration_name}.rb"
end