Skip to content

Commit

Permalink
Update description migration
Browse files Browse the repository at this point in the history
  • Loading branch information
milesmcc committed May 25, 2024
1 parent 6c4f935 commit ce947b9
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,31 @@ defmodule Platform.Repo.Migrations.MoveDescriptionToTextField do
use Ecto.Migration

def change do
# Drop the 'searchable' column from the 'media' table
execute "ALTER TABLE media DROP COLUMN searchable;"

alter table(:media) do
modify :attr_description, :text
end

# Add the 'searchable' column to the 'media' table
execute """
ALTER TABLE media
ADD COLUMN searchable tsvector
GENERATED ALWAYS AS (
setweight(to_tsvector('simple', coalesce(slug, '')), 'A') ||
setweight(to_tsvector('simple', coalesce(attr_description, '')), 'A') ||
setweight(to_tsvector('simple', coalesce(attr_more_info, '')), 'B') ||
setweight(to_tsvector('simple', coalesce(attr_general_location, '')), 'C') ||
setweight(to_tsvector('simple', imm_array_to_string(attr_restrictions, ' ', ' ')), 'C') ||
setweight(to_tsvector('simple', imm_array_to_string(attr_sensitive, ' ', ' ')), 'C') ||
setweight(to_tsvector('simple', coalesce(attr_status, '')), 'C') ||
setweight(jsonb_to_tsvector('simple', coalesce(auto_metadata, '{}'), '"string"'), 'D')
) STORED
""",
""

# Add an index to the 'media' table on searchable
create index(:media, ["searchable"], using: "GIN")
end
end

0 comments on commit ce947b9

Please sign in to comment.