Skip to content

Instantly share code, notes, and snippets.

@Ji-Yuhang
Created October 17, 2017 05:29
Show Gist options
  • Save Ji-Yuhang/072bf7316b726d690f7915e5d2c75a15 to your computer and use it in GitHub Desktop.
Save Ji-Yuhang/072bf7316b726d690f7915e5d2c75a15 to your computer and use it in GitHub Desktop.
pg_trgm gin postgre
class AddPgTrgmExtensionToDb < ActiveRecord::Migration[5.0]
# def change
# # execute "remove extension pg_trgm;"
# execute "create extension IF NOT EXISTS pg_trgm;"
# execute "CREATE EXTENSION IF NOT EXISTS btree_gin;"
#
# remove_index :words, :word
# add_index :words, :word, using: :btree_gin
# end
def up
execute "create extension IF NOT EXISTS pg_trgm;"
execute "CREATE EXTENSION IF NOT EXISTS btree_gin;"
remove_index :words, :word if index_exists?(:words, :word)
add_index :words, :word, using: :gin
end
def down
execute "drop extension IF EXISTS pg_trgm;"
execute "drop EXTENSION IF EXISTS btree_gin;"
remove_index :words, :word if index_exists?(:words, :word)
# add_index :words, :word, using: :btree_gin
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment