mezis/fuzzily

How do you change the VARCAR to ENUM in the database?

Closed this issue · 1 comments

In the project readme a way to increase performance is to change the data type of VARCHAR of owner_type and fuzzy_field to an ENUM. I researched this online and wasn't sure how to implement this. Do I create an enum with a few values? eg ENUM(1,2,3) or ENUM ('one', 'two', 'three')? Sorry, I don't know the code enough to know what I should change it to. Thank you!

Changing to an ENUM is usually achieved through a migration. Typically

class MyMigration < ActiveRecord::Migration
  def up
    execute "ALTER TABLE trigrams MODIFY COLUMN owner_type ENUM('ClassA','ClassB');"
    execute "ALTER TABLE trigrams MODIFY COLUMN fuzzy_field ENUM('field_one','field_two');"
  end

  def down
    execute "ALTER TABLE trigrams MODIFY COLUMN owner_type VARCHAR(255);"
    execute "ALTER TABLE trigrams MODIFY COLUMN fuzzy_field VARCHAR(255);"
  end
end