Sha256: 673c4723e212c7b02103fd318385369e3ea25920279c10a63a1156b7c325d26a

Contents?: true

Size: 948 Bytes

Versions: 3

Compression:

Stored size: 948 Bytes

Contents

require 'active_record'

module Fuzzily
  module Migration
    def self.extended(by)
      by.singleton_class.class_eval do
        def trigrams_table_name=(custom_name)
          @trigrams_table_name = custom_name
        end

        def trigrams_table_name
          @trigrams_table_name ||= :trigrams
        end

        def up
          create_table trigrams_table_name do |t|
            t.string  :trigram, :limit => 3
            t.integer :score
            t.integer :owner_id
            t.string  :owner_type
            t.string  :fuzzy_field
          end

          add_index trigrams_table_name,
            [:owner_type, :fuzzy_field, :trigram, :owner_id, :score],
            :name => :index_for_match
          add_index trigrams_table_name,
            [:owner_type, :owner_id],
            :name => :index_by_owner
        end

        def down
          drop_table trigrams_table_name
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fuzzily-0.1.0 lib/fuzzily/migration.rb
fuzzily-0.0.3 lib/fuzzily/migration.rb
fuzzily-0.0.2 lib/fuzzily/migration.rb