Last active
May 18, 2022 18:45
-
-
Save malachaifrazier/82e635fb52c5a1216d0cde689359a422 to your computer and use it in GitHub Desktop.
AddIndexForSearchableFieldsInDevelopers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddIndexForSearchableFieldsInDevelopers < ActiveRecord::Migration[7.0] | |
def up | |
execute <<-SQL | |
ALTER TABLE developers | |
ADD COLUMN textsearchable_index_col tsvector | |
GENERATED ALWAYS AS (to_tsvector('simple', coalesce(hero, '') || ' ' || coalesce(bio, ''))) STORED; | |
SQL | |
add_index :developers, :textsearchable_index_col, using: :gin, name: :textsearchable_index | |
end | |
def down | |
remove_index :developers, name: :textsearchable_index | |
remove_column :developers, :textsearchable_index_col | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running
bundle exec rails db:migrate --trace
fails with this:`
** Invoke db:migrate (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:migrate
== 20220416144523 AddIndexForSearchableFieldsInDevelopers: migrating ==========
-- execute(" ALTER TABLE developers\n ADD COLUMN textsearchable_index_col tsvector\n GENERATED ALWAYS AS (to_tsvector('simple', coalesce(hero, '') || ' ' || coalesce(bio, ''))) STORED;\n")
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::SyntaxError: ERROR: syntax error at or near "("
LINE 3: GENERATED ALWAYS AS (to_tsvector('simple', coalesc...
`