Migration Steps, for a second migration, fixing everyhing missed during the first
1. Backup DB
2. Delete problematic properties BOX_SIZE_PROPERTY and STORAGE_BOX_SIZE_1 as Orphan metadata, created by error
3. Delete problematic vocabulary STORAGE_BOX_POSITIONS as Orphan metadata, created by error
4. Update Database user id property used by the ELN storage from vocabulary to varchar

-- This should return no rows, meaning this property is empty and no values need to be fixed
SELECT *
FROM sample_properties sp LEFT JOIN sample_type_property_types stpt ON (sp.stpt_id = stpt.id)
WHERE stpt_id IN (SELECT id
FROM sample_type_property_types
WHERE prty_id IN
(SELECT id
FROM property_types
WHERE daty_id = 7 AND covo_id = 12 AND code LIKE 'STORAGE_USER_%'));

-- If no rows we can update to varchar
UPDATE property_types
SET covo_id = NULL, daty_id = 1
WHERE daty_id = 7 AND covo_id = 12 AND code LIKE 'STORAGE_USER_%';

5. Run Script

6. Weird things to Fix, labels without numbers or with underscores

- Storage groups have an underscore on the display name

UPDATE sample_type_property_types
SET section = 'Physical Storage ' || substring(section from (char_length('Physical Storage_')+1) for 2)
WHERE section LIKE 'Physical Storage_%';

- Storage properties labels have an underscore on the label name

UPDATE property_types
SET description = 'Storage Name ' || substring(code from (char_length('STORAGE_NAME_')+1) for 2), label = 'Location ' || substring(code from (char_length('STORAGE_NAME_')+1) for 2)
WHERE code LIKE 'STORAGE_NAME_%';

UPDATE property_types
SET description = 'Storage Row ' || substring(code from (char_length('STORAGE_ROW_')+1) for 2), label = 'Storage Row ' || substring(code from (char_length('STORAGE_ROW_')+1) for 2)
WHERE code LIKE 'STORAGE_ROW_%';

UPDATE property_types
SET description = 'Storage Column ' || substring(code from (char_length('STORAGE_COLUMN_')+1) for 2), label = 'Storage Column ' || substring(code from (char_length('STORAGE_COLUMN_')+1) for 2)
WHERE code LIKE 'STORAGE_COLUMN_%';

UPDATE property_types
SET description = 'Storage Column ' || substring(code from (char_length('STORAGE_COLUMN_')+1) for 2), label = 'Storage Column ' || substring(code from (char_length('STORAGE_COLUMN_')+1) for 2)
WHERE code LIKE 'STORAGE_COLUMN_%';

UPDATE property_types
SET description = 'Storage Box Name ' || substring(code from (char_length('STORAGE_BOX_NAME_')+1) for 2), label = 'Box Label ' || substring(code from (char_length('STORAGE_BOX_NAME_')+1) for 2)
WHERE code LIKE 'STORAGE_BOX_NAME_%';

UPDATE property_types
SET description = 'Storage User Id ' || substring(code from (char_length('STORAGE_USER_')+1) for 2), label = 'Frozen By ' || substring(code from (char_length('STORAGE_USER_')+1) for 2)
WHERE code LIKE 'STORAGE_USER_%';

UPDATE property_types
SET description = 'Storage Box Size ' || substring(code from (char_length('STORAGE_BOX_SIZE_')+1) for 2), label = 'Box Size ' || substring(code from (char_length('STORAGE_BOX_SIZE_')+1) for 2)
WHERE code LIKE 'STORAGE_BOX_SIZE_%';

UPDATE property_types
SET description = 'Storage Box Position ' || substring(code from (char_length('STORAGE_BOX_POSITION_')+1) for 2), label = 'Box Position ' || substring(code from (char_length('STORAGE_BOX_POSITION_')+1) for 2)
WHERE code LIKE 'STORAGE_BOX_POSITION_%';