-- 0045_taste_profile_eras.up.sql — era/decade taste facet (#1530,
-- milestone #160 Opt 2). A third taste facet alongside artists + tags:
-- signed weights over decade buckets ("1990s") derived from
-- albums.release_date, rebuilt daily by internal/taste next to the
-- artist/tag facets. Weight is a signed float — positive = drawn to
-- that era, negative = passively avoided; magnitude reflects decayed
-- engagement. Consumed by the recommendation scorer's taste match.
-- Mirrors taste_profile_tags: CASCADE on user delete, indexed by
-- (user_id, weight DESC) so "top eras" reads stay cheap.
CREATE TABLE taste_profile_eras (
    user_id    uuid             NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    era        text             NOT NULL,
    weight     double precision NOT NULL,
    updated_at timestamptz      NOT NULL DEFAULT now(),
    PRIMARY KEY (user_id, era)
);

CREATE INDEX taste_profile_eras_user_weight_idx
    ON taste_profile_eras (user_id, weight DESC);

-- Era-facet build knob, tunable in the lab (mirrors enriched_tag_scale,
-- #1520): scales how strongly a decade-play imprints on the profile.
-- DEFAULT 0.5 backfills the existing singleton and matches
-- taste.DefaultConfig().EraScale; 0 disables the era facet entirely.
ALTER TABLE taste_tuning
    ADD COLUMN era_scale double precision NOT NULL DEFAULT 0.5;
