x_org INTEGER;
org_list INTEGER[];
o INTEGER;
+ row_count NUMERIC;
BEGIN
EXECUTE 'SELECT EXISTS (
SELECT 1
|| ' ADD COLUMN x_shelf INTEGER';
IF x_org_found THEN
+ RAISE INFO 'Found x_org column';
EXECUTE 'UPDATE ' || quote_ident(table_name) || ' a'
|| ' SET x_shelf = b.id FROM asset_copy_location b'
|| ' WHERE BTRIM(UPPER(a.desired_shelf)) = BTRIM(UPPER(b.name))'
|| ' AND x_shelf IS NULL'
|| ' AND NOT b.deleted';
ELSE
+ RAISE INFO 'Did not find x_org column';
EXECUTE 'UPDATE ' || quote_ident(table_name) || ' a'
|| ' SET x_shelf = b.id FROM asset_copy_location b'
|| ' WHERE BTRIM(UPPER(a.desired_shelf)) = BTRIM(UPPER(b.name))'
END IF;
FOREACH o IN ARRAY org_list LOOP
+ RAISE INFO 'Considering org %', o;
EXECUTE 'UPDATE ' || quote_ident(table_name) || ' a'
|| ' SET x_shelf = b.id FROM asset.copy_location b'
|| ' WHERE BTRIM(UPPER(a.desired_shelf)) = BTRIM(UPPER(b.name))'
|| ' AND b.owning_lib = $1 AND x_shelf IS NULL'
|| ' AND NOT b.deleted'
USING o;
+ GET DIAGNOSTICS row_count = ROW_COUNT;
+ RAISE INFO 'Updated % rows', row_count;
END LOOP;
EXECUTE 'SELECT migration_tools.assert(