-- Wires up the normalized `manufacturers` catalog (organized-ideas.md §3: -- "manufacturer becomes a normalized, submittable catalog — the same -- public/user-defined pattern already used for device categories"). -- -- The table itself, its RLS policies, and device_templates.manufacturer_id -- have all existed unused since the initial schema / the manufacturer_text -- migration — this is the pass that actually populates and reads them. -- Scope matches what device_category has today: create-your-own-private-one -- only, no submission/admin-edit UI yet (that's a separate, already-tracked -- follow-up for both entities together). -- -- Any existing free-text manufacturer values (there's realistically at most -- a handful of dev-only rows at this point, nothing shipped) get backfilled -- into a manufacturers row each, grouped by (name, owner, is_public) so two -- different users' private "Fake" manufacturers don't collide into one row. insert into public.manufacturers (name, is_public, owner_id) select distinct dt.manufacturer, dt.is_public, dt.owner_id from public.device_templates dt where dt.manufacturer is not null; update public.device_templates dt set manufacturer_id = m.id from public.manufacturers m where dt.manufacturer is not null and m.name = dt.manufacturer and m.is_public = dt.is_public and m.owner_id is not distinct from dt.owner_id; alter table public.device_templates drop column manufacturer;