diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 113d165..b238230 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -120,9 +120,16 @@ ON CONFLICT (tag_id) DO UPDATE SET -- the only place an item name is joined to a tag - so it must load AFTER tags -- (it references them) and BEFORE the fixtures (they are driven by it). -- Regenerate from the WRPS repo with scripts/gen_historian_items.py. +-- Columns are NAMED, not positional. hi_stage is LIKE historian_items, so it +-- inherits the LIVE table's column order - and ALTER TABLE appends, so a +-- migrated database orders its columns differently from a freshly created one. +-- A positional copy then loads the wrong column into the wrong place, or fails +-- with a type error if you are lucky. Migration 008 made that concrete. +-- The \copy line is long because psql meta-commands cannot be wrapped. CREATE TEMP TABLE hi_stage (LIKE historian_items EXCLUDING CONSTRAINTS); -\copy hi_stage FROM '/tmp/db/seed/historian_items.csv' WITH (FORMAT csv, HEADER true, NULL '') -INSERT INTO historian_items SELECT * FROM hi_stage +\copy hi_stage (item_name,tag_id,exclusion_reason,section_path,section,attribute,section_description,description,eng_unit,value_format,conv_type,has_sign,phys_low,phys_high,eng_gain,raw_to_eng,his_group,scan_interval_seconds,life_time,ci_station,ci_point,poll_group,iec_address,modbus_kind,modbus_address,data_type,point_time_zone) FROM '/tmp/db/seed/historian_items.csv' WITH (FORMAT csv, HEADER true, NULL '') +INSERT INTO historian_items (item_name,tag_id,exclusion_reason,section_path,section,attribute,section_description,description,eng_unit,value_format,conv_type,has_sign,phys_low,phys_high,eng_gain,raw_to_eng,his_group,scan_interval_seconds,life_time,ci_station,ci_point,poll_group,iec_address,modbus_kind,modbus_address,data_type,point_time_zone) +SELECT item_name,tag_id,exclusion_reason,section_path,section,attribute,section_description,description,eng_unit,value_format,conv_type,has_sign,phys_low,phys_high,eng_gain,raw_to_eng,his_group,scan_interval_seconds,life_time,ci_station,ci_point,poll_group,iec_address,modbus_kind,modbus_address,data_type,point_time_zone FROM hi_stage ON CONFLICT (item_name) DO UPDATE SET tag_id=EXCLUDED.tag_id, exclusion_reason=EXCLUDED.exclusion_reason, section_path=EXCLUDED.section_path, section=EXCLUDED.section,