5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/fuzzily/migration.rb', line 5
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, :limit => 2
t.integer :owner_id
t.string :owner_type
t.string :fuzzy_field
end
add_index trigrams_table_name,
[:owner_id, :owner_type, :fuzzy_field, :trigram, :score],
:name => :index_for_match
add_index trigrams_table_name,
[:owner_id, :owner_type],
:name => :index_by_owner
end
def down
drop_table trigrams_table_name
end
end
end
|