-- +goose Up

-- Drop the full-text search index that references the soon-to-be-removed
-- title_ru column.
DROP INDEX IF EXISTS idx_recipes_title_fts;

-- Remove legacy _ru columns from recipes now that the data lives in
-- recipe_translations (migration 009).
ALTER TABLE recipes
    DROP COLUMN IF EXISTS title_ru,
    DROP COLUMN IF EXISTS description_ru;

-- Remove the legacy Russian name column from ingredient_mappings.
ALTER TABLE ingredient_mappings
    DROP COLUMN IF EXISTS canonical_name_ru;

-- Recreate the FTS index on the English title only.
-- Cross-language search is now handled at the application level by querying
-- the appropriate translation row.
CREATE INDEX idx_recipes_title_fts ON recipes
    USING GIN (to_tsvector('simple', coalesce(title, '')));

-- +goose Down
DROP INDEX IF EXISTS idx_recipes_title_fts;

ALTER TABLE recipes
    ADD COLUMN title_ru       VARCHAR(500),
    ADD COLUMN description_ru TEXT;

ALTER TABLE ingredient_mappings
    ADD COLUMN canonical_name_ru VARCHAR(255);

-- Restore the bilingual FTS index.
CREATE INDEX idx_recipes_title_fts ON recipes
    USING GIN (to_tsvector('simple',
        coalesce(title_ru, '') || ' ' || coalesce(title, '')));
