Files
cannery/priv/repo/migrations/20230415033450_add_pack_lot_number_to_search.exs
shibao 334d841d57
Some checks failed
continuous-integration/drone/push Build is failing
add pack lot number to search
2023-04-14 23:38:28 -04:00

35 lines
1.2 KiB
Elixir

defmodule Cannery.Repo.Migrations.AddPackLotNumberToSearch do
use Ecto.Migration
def up do
execute "ALTER TABLE packs DROP COLUMN search"
execute """
ALTER TABLE packs
ADD COLUMN search tsvector
GENERATED ALWAYS AS (
setweight(to_tsvector('english', coalesce("notes", '')), 'A') ||
setweight(to_tsvector('english', coalesce("lot_number", '')), 'A') ||
setweight(to_tsvector('english', immutable_to_string("price_paid", '')), 'B') ||
setweight(to_tsvector('english', immutable_to_string("purchased_on", '')), 'B') ||
setweight(to_tsvector('english', immutable_to_string("count", '')), 'C')
) STORED
"""
end
def down do
execute "ALTER TABLE packs DROP COLUMN search"
execute """
ALTER TABLE packs
ADD COLUMN search tsvector
GENERATED ALWAYS AS (
setweight(to_tsvector('english', coalesce("notes", '')), 'A') ||
setweight(to_tsvector('english', immutable_to_string("price_paid", '')), 'B') ||
setweight(to_tsvector('english', immutable_to_string("purchased_on", '')), 'B') ||
setweight(to_tsvector('english', immutable_to_string("count", '')), 'C')
) STORED
"""
end
end