Sha256: 79cfaf85f4fc872855b36aceadef27d209b22dd5e2d33803e10c91fdf0e49576

Contents?: true

Size: 952 Bytes

Versions: 1

Compression:

Stored size: 952 Bytes

Contents

require "active_record/connection_adapters/postgresql_adapter"
require "active_record/connection_adapters/postgresql/schema_creation"

module PgHaMigrations
  module ActiveRecordHacks
    module IndexAlgorithms
      def index_algorithms
        super.merge(only: "ONLY")
      end
    end

    module CreateIndexDefinition
      def visit_CreateIndexDefinition(o)
        if o.algorithm == "ONLY"
          o.algorithm = nil

          quoted_index = quote_column_name(o.index.name)
          quoted_table = quote_table_name(o.index.table)

          super.sub("#{quoted_index} ON #{quoted_table}", "#{quoted_index} ON ONLY #{quoted_table}")
        else
          super
        end
      end
    end
  end
end

ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(PgHaMigrations::ActiveRecordHacks::IndexAlgorithms)
ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaCreation.prepend(PgHaMigrations::ActiveRecordHacks::CreateIndexDefinition)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pg_ha_migrations-1.8.0 lib/pg_ha_migrations/hacks/add_index_on_only.rb