-- circ_lib, target_copy, usr, and *_renewal). User profiles and
-- circ modifiers must also be in place.
--
--- SELECT migration_tools.apply_circ_matrix('m_pioneer.action_circulation');
+-- SELECT migration_tools.apply_circ_matrix('m_pioneer.m_action_circulation');
--
DECLARE
-- circ_lib, target_copy, usr, and *_renewal). User profiles and
-- circ modifiers must also be in place.
--
--- SELECT migration_tools.apply_circ_matrix_to_specific_circ('m_nwrl.action_circulation', 18391960);
+-- SELECT migration_tools.apply_circ_matrix_to_specific_circ('m_nwrl.m_action_circulation', 18391960);
--
DECLARE
CREATE OR REPLACE FUNCTION migration_tools.create_cards( schemaname TEXT ) RETURNS VOID AS $$
--- USAGE: Make sure the patrons are staged in schemaname.actor_usr_legacy and have 'usrname' assigned.
+-- USAGE: Make sure the patrons are staged in schemaname.m_actor_usr_legacy and have 'usrname' assigned.
-- Then SELECT migration_tools.create_cards('m_foo');
DECLARE
- u TEXT := schemaname || '.actor_usr_legacy';
- c TEXT := schemaname || '.actor_card';
+ u TEXT := schemaname || '.m_actor_usr_legacy';
+ c TEXT := schemaname || '.m_actor_card';
BEGIN
BEGIN
EXECUTE $$COPY (SELECT * FROM actor.hours_of_operation WHERE id IN ($$ ||
ARRAY_TO_STRING(orgs, ',') || $$)$$ ||
- $$) TO '$$ || dir || $$/actor_hours_of_operation'$$;
+ $$) TO '$$ || dir || $$/m_actor_hours_of_operation'$$;
EXECUTE $$COPY (SELECT org_unit, close_start, close_end, reason FROM actor.org_unit_closed WHERE org_unit IN ($$ ||
ARRAY_TO_STRING(orgs, ',') || $$)$$ ||
- $$) TO '$$ || dir || $$/actor_org_unit_closed'$$;
+ $$) TO '$$ || dir || $$/m_actor_org_unit_closed'$$;
EXECUTE $$COPY (SELECT org_unit, name, value FROM actor.org_unit_setting WHERE org_unit IN ($$ ||
ARRAY_TO_STRING(orgs, ',') || $$)$$ ||
- $$) TO '$$ || dir || $$/actor_org_unit_setting'$$;
+ $$) TO '$$ || dir || $$/m_actor_org_unit_setting'$$;
EXECUTE $$COPY (SELECT name, owning_lib, holdable, hold_verify, opac_visible, circulate FROM asset.copy_location WHERE owning_lib IN ($$ ||
ARRAY_TO_STRING(orgs, ',') || $$)$$ ||
- $$) TO '$$ || dir || $$/asset_copy_location'$$;
+ $$) TO '$$ || dir || $$/m_asset_copy_location'$$;
EXECUTE $$COPY (SELECT grp, org_unit, penalty, threshold FROM permission.grp_penalty_threshold WHERE org_unit IN ($$ ||
ARRAY_TO_STRING(orgs, ',') || $$)$$ ||
- $$) TO '$$ || dir || $$/permission_grp_penalty_threshold'$$;
+ $$) TO '$$ || dir || $$/m_permission_grp_penalty_threshold'$$;
EXECUTE $$COPY (SELECT owning_lib, label, label_sortkey FROM asset.call_number_prefix WHERE owning_lib IN ($$ ||
ARRAY_TO_STRING(orgs, ',') || $$)$$ ||
- $$) TO '$$ || dir || $$/asset_call_number_prefix'$$;
+ $$) TO '$$ || dir || $$/m_asset_call_number_prefix'$$;
EXECUTE $$COPY (SELECT owning_lib, label, label_sortkey FROM asset.call_number_suffix WHERE owning_lib IN ($$ ||
ARRAY_TO_STRING(orgs, ',') || $$)$$ ||
- $$) TO '$$ || dir || $$/asset_call_number_suffix'$$;
- EXECUTE $$COPY config.rule_circ_duration TO '$$ || dir || $$/config_rule_circ_duration'$$;
- EXECUTE $$COPY config.rule_age_hold_protect TO '$$ || dir || $$/config_rule_age_hold_protect'$$;
- EXECUTE $$COPY config.rule_max_fine TO '$$ || dir || $$/config_rule_max_fine'$$;
- EXECUTE $$COPY config.rule_recurring_fine TO '$$ || dir || $$/config_rule_recurring_fine'$$;
- EXECUTE $$COPY permission.grp_tree TO '$$ || dir || $$/permission_grp_tree'$$;
+ $$) TO '$$ || dir || $$/m_asset_call_number_suffix'$$;
+ EXECUTE $$COPY config.rule_circ_duration TO '$$ || dir || $$/m_config_rule_circ_duration'$$;
+ EXECUTE $$COPY config.rule_age_hold_protect TO '$$ || dir || $$/m_config_rule_age_hold_protect'$$;
+ EXECUTE $$COPY config.rule_max_fine TO '$$ || dir || $$/m_config_rule_max_fine'$$;
+ EXECUTE $$COPY config.rule_recurring_fine TO '$$ || dir || $$/m_config_rule_recurring_fine'$$;
+ EXECUTE $$COPY permission.grp_tree TO '$$ || dir || $$/m_permission_grp_tree'$$;
END;
$FUNC$ LANGUAGE PLPGSQL;
CREATE OR REPLACE FUNCTION migration_tools.simple_import_library_config(dir TEXT) RETURNS VOID AS $FUNC$
BEGIN
- EXECUTE $$COPY actor.hours_of_operation FROM '$$ || dir || $$/actor_hours_of_operation'$$;
- EXECUTE $$COPY actor.org_unit_closed (org_unit, close_start, close_end, reason) FROM '$$ || dir || $$/actor_org_unit_closed'$$;
- EXECUTE $$COPY actor.org_unit_setting (org_unit, name, value) FROM '$$ || dir || $$/actor_org_unit_setting'$$;
- EXECUTE $$COPY asset.copy_location (name, owning_lib, holdable, hold_verify, opac_visible, circulate) FROM '$$ || dir || $$/asset_copy_location'$$;
- EXECUTE $$COPY permission.grp_penalty_threshold (grp, org_unit, penalty, threshold) FROM '$$ || dir || $$/permission_grp_penalty_threshold'$$;
- EXECUTE $$COPY asset.call_number_prefix (owning_lib, label, label_sortkey) FROM '$$ || dir || $$/asset_call_number_prefix'$$;
- EXECUTE $$COPY asset.call_number_suffix (owning_lib, label, label_sortkey) FROM '$$ || dir || $$/asset_call_number_suffix'$$;
+ EXECUTE $$COPY actor.hours_of_operation FROM '$$ || dir || $$/m_actor_hours_of_operation'$$;
+ EXECUTE $$COPY actor.org_unit_closed (org_unit, close_start, close_end, reason) FROM '$$ || dir || $$/m_actor_org_unit_closed'$$;
+ EXECUTE $$COPY actor.org_unit_setting (org_unit, name, value) FROM '$$ || dir || $$/m_actor_org_unit_setting'$$;
+ EXECUTE $$COPY asset.copy_location (name, owning_lib, holdable, hold_verify, opac_visible, circulate) FROM '$$ || dir || $$/m_asset_copy_location'$$;
+ EXECUTE $$COPY permission.grp_penalty_threshold (grp, org_unit, penalty, threshold) FROM '$$ || dir || $$/m_permission_grp_penalty_threshold'$$;
+ EXECUTE $$COPY asset.call_number_prefix (owning_lib, label, label_sortkey) FROM '$$ || dir || $$/m_asset_call_number_prefix'$$;
+ EXECUTE $$COPY asset.call_number_suffix (owning_lib, label, label_sortkey) FROM '$$ || dir || $$/m_asset_call_number_suffix'$$;
-- import any new circ rules
PERFORM migration_tools.simple_import_new_rows_by_value(dir, 'config', 'rule_circ_duration', 'id', 'name');
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'
+ || ' SET x_shelf = b.id FROM m_asset_copy_location b'
|| ' WHERE BTRIM(UPPER(a.desired_shelf)) = BTRIM(UPPER(b.name))'
|| ' AND b.owning_lib = x_org'
|| ' 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'
+ || ' SET x_shelf = b.id FROM m_asset_copy_location b'
|| ' WHERE BTRIM(UPPER(a.desired_shelf)) = BTRIM(UPPER(b.name))'
|| ' AND b.owning_lib = $1'
|| ' AND NOT b.deleted'
USING org;
EXECUTE 'UPDATE ' || quote_ident(table_name) || ' a'
- || ' SET x_shelf = b.id FROM asset_copy_location b'
+ || ' SET x_shelf = b.id FROM m_asset_copy_location b'
|| ' WHERE BTRIM(UPPER(a.desired_shelf)) = BTRIM(UPPER(b.name))'
|| ' AND b.owning_lib = $1'
|| ' AND x_shelf IS NULL'
SELECT INTO org_list ARRAY_ACCUM(id) FROM actor.org_unit_full_path( org );
-- caller responsible for their own truncates though we try to prevent duplicates
- EXECUTE 'INSERT INTO actor_stat_cat (owner, name)
+ EXECUTE 'INSERT INTO m_actor_stat_cat (owner, name)
SELECT DISTINCT
$1
,BTRIM('||sc||')
)
AND NOT EXISTS (
SELECT id
- FROM actor_stat_cat
+ FROM m_actor_stat_cat
WHERE owner = ANY ($2)
AND name = BTRIM('||sc||')
)
ORDER BY 2;'
USING org, org_list;
- EXECUTE 'INSERT INTO actor_stat_cat_entry (stat_cat, owner, value)
+ EXECUTE 'INSERT INTO m_actor_stat_cat_entry (stat_cat, owner, value)
SELECT DISTINCT
COALESCE(
(SELECT id
WHERE owner = ANY ($2)
AND BTRIM('||sc||') = BTRIM(name))
,(SELECT id
- FROM actor_stat_cat
+ FROM m_actor_stat_cat
WHERE owner = ANY ($2)
AND BTRIM('||sc||') = BTRIM(name))
)
)
AND NOT EXISTS (
SELECT id
- FROM actor_stat_cat_entry
+ FROM m_actor_stat_cat_entry
WHERE stat_cat = (
SELECT id
- FROM actor_stat_cat
+ FROM m_actor_stat_cat
WHERE owner = ANY ($2)
AND BTRIM('||sc||') = BTRIM(name)
) AND value = BTRIM('||sce||')
SET
x_sc' || field_suffix || ' = id
FROM
- (SELECT id, name, owner FROM actor_stat_cat
+ (SELECT id, name, owner FROM m_actor_stat_cat
UNION SELECT id, name, owner FROM actor.stat_cat) u
WHERE
BTRIM(UPPER(u.name)) = BTRIM(UPPER(' || sc || '))
SET
x_sce' || field_suffix || ' = id
FROM
- (SELECT id, stat_cat, owner, value FROM actor_stat_cat_entry
+ (SELECT id, stat_cat, owner, value FROM m_actor_stat_cat_entry
UNION SELECT id, stat_cat, owner, value FROM actor.stat_cat_entry) u
WHERE
u.stat_cat = x_sc' || field_suffix || '
SELECT INTO cur_id id FROM actor.org_unit_ancestor_at_depth(org_id,d);
SELECT INTO return_id id FROM
- (SELECT * FROM asset.copy_location UNION ALL SELECT * FROM asset_copy_location) x
+ (SELECT * FROM asset.copy_location UNION ALL SELECT * FROM m_asset_copy_location) x
WHERE owning_lib = cur_id AND name ILIKE shelf_name;
IF return_id IS NOT NULL THEN
RETURN return_id;
SELECT 1
FROM information_schema.columns
WHERE table_schema = $1
- AND table_name = ''asset_copy_legacy''
+ AND table_name = ''m_asset_copy_legacy''
and column_name = $2
)' INTO proceed USING table_schema, main_column_name;
IF NOT proceed THEN
- RAISE EXCEPTION 'No %.asset_copy_legacy with column %', table_schema, main_column_name;
+ RAISE EXCEPTION 'No %.m_asset_copy_legacy with column %', table_schema, main_column_name;
END IF;
EXECUTE 'ALTER TABLE '
IF btrim_desired THEN
EXECUTE 'UPDATE ' || quote_ident(table_name) || ' a'
- || ' SET x_item = b.id FROM asset_copy_legacy b'
+ || ' SET x_item = b.id FROM m_asset_copy_legacy b'
|| ' WHERE BTRIM(a.' || quote_ident(foreign_column_name)
|| ') = BTRIM(b.' || quote_ident(main_column_name) || ')';
ELSE
EXECUTE 'UPDATE ' || quote_ident(table_name) || ' a'
- || ' SET x_item = b.id FROM asset_copy_legacy b'
+ || ' SET x_item = b.id FROM m_asset_copy_legacy b'
|| ' WHERE a.' || quote_ident(foreign_column_name)
|| ' = b.' || quote_ident(main_column_name);
END IF;
SELECT 1
FROM information_schema.columns
WHERE table_schema = $1
- AND table_name = ''actor_usr_legacy''
+ AND table_name = ''m_actor_usr_legacy''
and column_name = $2
)' INTO proceed USING table_schema, main_column_name;
IF NOT proceed THEN
- RAISE EXCEPTION 'No %.actor_usr_legacy with column %', table_schema, main_column_name;
+ RAISE EXCEPTION 'No %.m_actor_usr_legacy with column %', table_schema, main_column_name;
END IF;
EXECUTE 'ALTER TABLE '
IF btrim_desired THEN
EXECUTE 'UPDATE ' || quote_ident(table_name) || ' a'
- || ' SET x_user = b.id FROM actor_usr_legacy b'
+ || ' SET x_user = b.id FROM m_actor_usr_legacy b'
|| ' WHERE BTRIM(a.' || quote_ident(foreign_column_name)
|| ') = BTRIM(b.' || quote_ident(main_column_name) || ')';
ELSE
EXECUTE 'UPDATE ' || quote_ident(table_name) || ' a'
- || ' SET x_user = b.id FROM actor_usr_legacy b'
+ || ' SET x_user = b.id FROM m_actor_usr_legacy b'
|| ' WHERE a.' || quote_ident(foreign_column_name)
|| ' = b.' || quote_ident(main_column_name);
END IF;
SELECT INTO org_list ARRAY_ACCUM(id) FROM actor.org_unit_full_path( org );
-- caller responsible for their own truncates though we try to prevent duplicates
- EXECUTE 'INSERT INTO asset_stat_cat (owner, name)
+ EXECUTE 'INSERT INTO m_asset_stat_cat (owner, name)
SELECT DISTINCT
$1
,BTRIM('||sc||')
)
AND NOT EXISTS (
SELECT id
- FROM asset_stat_cat
+ FROM m_asset_stat_cat
WHERE owner = ANY ($2)
AND name = BTRIM('||sc||')
)
ORDER BY 2;'
USING org, org_list;
- EXECUTE 'INSERT INTO asset_stat_cat_entry (stat_cat, owner, value)
+ EXECUTE 'INSERT INTO m_asset_stat_cat_entry (stat_cat, owner, value)
SELECT DISTINCT
COALESCE(
(SELECT id
WHERE owner = ANY ($2)
AND BTRIM('||sc||') = BTRIM(name))
,(SELECT id
- FROM asset_stat_cat
+ FROM m_asset_stat_cat
WHERE owner = ANY ($2)
AND BTRIM('||sc||') = BTRIM(name))
)
)
AND NOT EXISTS (
SELECT id
- FROM asset_stat_cat_entry
+ FROM m_asset_stat_cat_entry
WHERE stat_cat = (
SELECT id
- FROM asset_stat_cat
+ FROM m_asset_stat_cat
WHERE owner = ANY ($2)
AND BTRIM('||sc||') = BTRIM(name)
) AND value = BTRIM('||sce||')
SET
x_sc' || field_suffix || ' = id
FROM
- (SELECT id, name, owner FROM asset_stat_cat
+ (SELECT id, name, owner FROM m_asset_stat_cat
UNION SELECT id, name, owner FROM asset.stat_cat) u
WHERE
BTRIM(UPPER(u.name)) = BTRIM(UPPER(' || sc || '))
SET
x_sce' || field_suffix || ' = id
FROM
- (SELECT id, stat_cat, owner, value FROM asset_stat_cat_entry
+ (SELECT id, stat_cat, owner, value FROM m_asset_stat_cat_entry
UNION SELECT id, stat_cat, owner, value FROM asset.stat_cat_entry) u
WHERE
u.stat_cat = x_sc' || field_suffix || '
END;
$$ LANGUAGE PLPGSQL STRICT VOLATILE;
--- convenience function for handling item barcode collisions in asset_copy_legacy
+-- convenience function for handling item barcode collisions in m_asset_copy_legacy
CREATE OR REPLACE FUNCTION migration_tools.handle_asset_barcode_collisions(migration_schema TEXT) RETURNS VOID AS $function$
DECLARE
internal_collision_count NUMERIC := 0;
incumbent_collision_count NUMERIC := 0;
BEGIN
- FOR x_barcode IN SELECT barcode FROM asset_copy_legacy WHERE x_migrate GROUP BY 1 HAVING COUNT(*) > 1
+ FOR x_barcode IN SELECT barcode FROM m_asset_copy_legacy WHERE x_migrate GROUP BY 1 HAVING COUNT(*) > 1
LOOP
- FOR x_id IN SELECT id FROM asset_copy WHERE barcode = x_barcode
+ FOR x_id IN SELECT id FROM m_asset_copy WHERE barcode = x_barcode
LOOP
- UPDATE asset_copy SET barcode = migration_schema || '_internal_collision_' || id || '_' || barcode WHERE id = x_id;
+ UPDATE m_asset_copy SET barcode = migration_schema || '_internal_collision_' || id || '_' || barcode WHERE id = x_id;
GET DIAGNOSTICS row_count = ROW_COUNT;
internal_collision_count := internal_collision_count + row_count;
END LOOP;
END LOOP;
RAISE INFO '% internal collisions', internal_collision_count;
- FOR x_barcode IN SELECT a.barcode FROM asset.copy a, asset_copy_legacy b WHERE x_migrate AND a.deleted IS FALSE AND a.barcode = b.barcode
+ FOR x_barcode IN SELECT a.barcode FROM asset.copy a, m_asset_copy_legacy b WHERE x_migrate AND a.deleted IS FALSE AND a.barcode = b.barcode
LOOP
- FOR x_id IN SELECT id FROM asset_copy_legacy WHERE barcode = x_barcode
+ FOR x_id IN SELECT id FROM m_asset_copy_legacy WHERE barcode = x_barcode
LOOP
- UPDATE asset_copy_legacy SET barcode = migration_schema || '_incumbent_collision_' || id || '_' || barcode WHERE id = x_id;
+ UPDATE m_asset_copy_legacy SET barcode = migration_schema || '_incumbent_collision_' || id || '_' || barcode WHERE id = x_id;
GET DIAGNOSTICS row_count = ROW_COUNT;
incumbent_collision_count := incumbent_collision_count + row_count;
END LOOP;
END
$function$ LANGUAGE plpgsql;
--- convenience function for handling patron barcode/usrname collisions in actor_usr_legacy
--- this should be ran prior to populating actor_card
+-- convenience function for handling patron barcode/usrname collisions in m_actor_usr_legacy
+-- this should be ran prior to populating m_actor_card
CREATE OR REPLACE FUNCTION migration_tools.handle_actor_barcode_collisions(migration_schema TEXT) RETURNS VOID AS $function$
DECLARE
incumbent_barcode_collision_count NUMERIC := 0;
incumbent_usrname_collision_count NUMERIC := 0;
BEGIN
- FOR x_barcode IN SELECT usrname FROM actor_usr_legacy WHERE x_migrate GROUP BY 1 HAVING COUNT(*) > 1
+ FOR x_barcode IN SELECT usrname FROM m_actor_usr_legacy WHERE x_migrate GROUP BY 1 HAVING COUNT(*) > 1
LOOP
- FOR x_id IN SELECT id FROM actor_usr_legacy WHERE x_migrate AND usrname = x_barcode
+ FOR x_id IN SELECT id FROM m_actor_usr_legacy WHERE x_migrate AND usrname = x_barcode
LOOP
- UPDATE actor_usr_legacy SET usrname = migration_schema || '_internal_collision_' || id || '_' || usrname WHERE id = x_id;
+ UPDATE m_actor_usr_legacy SET usrname = migration_schema || '_internal_collision_' || id || '_' || usrname WHERE id = x_id;
GET DIAGNOSTICS row_count = ROW_COUNT;
internal_collision_count := internal_collision_count + row_count;
END LOOP;
RAISE INFO '% internal usrname/barcode collisions', internal_collision_count;
FOR x_barcode IN
- SELECT a.barcode FROM actor.card a, actor_usr_legacy b WHERE x_migrate AND a.barcode = b.usrname
+ SELECT a.barcode FROM actor.card a, m_actor_usr_legacy b WHERE x_migrate AND a.barcode = b.usrname
LOOP
- FOR x_id IN SELECT DISTINCT id FROM actor_usr_legacy WHERE x_migrate AND usrname = x_barcode
+ FOR x_id IN SELECT DISTINCT id FROM m_actor_usr_legacy WHERE x_migrate AND usrname = x_barcode
LOOP
- UPDATE actor_usr_legacy SET usrname = migration_schema || '_incumbent_barcode_collision_' || id || '_' || usrname WHERE id = x_id;
+ UPDATE m_actor_usr_legacy SET usrname = migration_schema || '_incumbent_barcode_collision_' || id || '_' || usrname WHERE id = x_id;
GET DIAGNOSTICS row_count = ROW_COUNT;
incumbent_barcode_collision_count := incumbent_barcode_collision_count + row_count;
END LOOP;
RAISE INFO '% incumbent barcode collisions', incumbent_barcode_collision_count;
FOR x_barcode IN
- SELECT a.usrname FROM actor.usr a, actor_usr_legacy b WHERE x_migrate AND a.usrname = b.usrname
+ SELECT a.usrname FROM actor.usr a, m_actor_usr_legacy b WHERE x_migrate AND a.usrname = b.usrname
LOOP
- FOR x_id IN SELECT DISTINCT id FROM actor_usr_legacy WHERE x_migrate AND usrname = x_barcode
+ FOR x_id IN SELECT DISTINCT id FROM m_actor_usr_legacy WHERE x_migrate AND usrname = x_barcode
LOOP
- UPDATE actor_usr_legacy SET usrname = migration_schema || '_incumbent_usrname_collision_' || id || '_' || usrname WHERE id = x_id;
+ UPDATE m_actor_usr_legacy SET usrname = migration_schema || '_incumbent_usrname_collision_' || id || '_' || usrname WHERE id = x_id;
GET DIAGNOSTICS row_count = ROW_COUNT;
incumbent_usrname_collision_count := incumbent_usrname_collision_count + row_count;
END LOOP;
END
$function$ LANGUAGE plpgsql;
--- alternate version: convenience function for handling item barcode collisions in asset_copy_legacy
+-- alternate version: convenience function for handling item barcode collisions in m_asset_copy_legacy
CREATE OR REPLACE FUNCTION migration_tools.handle_asset_barcode_collisions2(migration_schema TEXT) RETURNS VOID AS $function$
DECLARE
internal_collision_count NUMERIC := 0;
incumbent_collision_count NUMERIC := 0;
BEGIN
- FOR x_barcode IN SELECT barcode FROM asset_copy_legacy WHERE x_migrate GROUP BY 1 HAVING COUNT(*) > 1
+ FOR x_barcode IN SELECT barcode FROM m_asset_copy_legacy WHERE x_migrate GROUP BY 1 HAVING COUNT(*) > 1
LOOP
- FOR x_id IN SELECT id FROM asset_copy WHERE barcode = x_barcode
+ FOR x_id IN SELECT id FROM m_asset_copy WHERE barcode = x_barcode
LOOP
- UPDATE asset_copy SET barcode = migration_schema || '_internal_collision_' || id || '_' || barcode WHERE id = x_id;
+ UPDATE m_asset_copy SET barcode = migration_schema || '_internal_collision_' || id || '_' || barcode WHERE id = x_id;
GET DIAGNOSTICS row_count = ROW_COUNT;
internal_collision_count := internal_collision_count + row_count;
END LOOP;
END LOOP;
RAISE INFO '% internal collisions', internal_collision_count;
- FOR x_barcode IN SELECT a.barcode FROM asset.copy a, asset_copy_legacy b WHERE x_migrate AND a.deleted IS FALSE AND a.barcode = b.barcode
+ FOR x_barcode IN SELECT a.barcode FROM asset.copy a, m_asset_copy_legacy b WHERE x_migrate AND a.deleted IS FALSE AND a.barcode = b.barcode
LOOP
- FOR x_id IN SELECT id FROM asset_copy_legacy WHERE barcode = x_barcode
+ FOR x_id IN SELECT id FROM m_asset_copy_legacy WHERE barcode = x_barcode
LOOP
- UPDATE asset_copy_legacy SET barcode = migration_schema || '_' || barcode WHERE id = x_id;
+ UPDATE m_asset_copy_legacy SET barcode = migration_schema || '_' || barcode WHERE id = x_id;
GET DIAGNOSTICS row_count = ROW_COUNT;
incumbent_collision_count := incumbent_collision_count + row_count;
END LOOP;
END
$function$ LANGUAGE plpgsql;
--- alternate version: convenience function for handling patron barcode/usrname collisions in actor_usr_legacy
--- this should be ran prior to populating actor_card
+-- alternate version: convenience function for handling patron barcode/usrname collisions in m_actor_usr_legacy
+-- this should be ran prior to populating m_actor_card
CREATE OR REPLACE FUNCTION migration_tools.handle_actor_barcode_collisions2(migration_schema TEXT) RETURNS VOID AS $function$
DECLARE
incumbent_barcode_collision_count NUMERIC := 0;
incumbent_usrname_collision_count NUMERIC := 0;
BEGIN
- FOR x_barcode IN SELECT usrname FROM actor_usr_legacy WHERE x_migrate GROUP BY 1 HAVING COUNT(*) > 1
+ FOR x_barcode IN SELECT usrname FROM m_actor_usr_legacy WHERE x_migrate GROUP BY 1 HAVING COUNT(*) > 1
LOOP
- FOR x_id IN SELECT id FROM actor_usr_legacy WHERE x_migrate AND usrname = x_barcode
+ FOR x_id IN SELECT id FROM m_actor_usr_legacy WHERE x_migrate AND usrname = x_barcode
LOOP
- UPDATE actor_usr_legacy SET usrname = migration_schema || '_internal_collision_' || id || '_' || usrname WHERE id = x_id;
+ UPDATE m_actor_usr_legacy SET usrname = migration_schema || '_internal_collision_' || id || '_' || usrname WHERE id = x_id;
GET DIAGNOSTICS row_count = ROW_COUNT;
internal_collision_count := internal_collision_count + row_count;
END LOOP;
RAISE INFO '% internal usrname/barcode collisions', internal_collision_count;
FOR x_barcode IN
- SELECT a.barcode FROM actor.card a, actor_usr_legacy b WHERE x_migrate AND a.barcode = b.usrname
+ SELECT a.barcode FROM actor.card a, m_actor_usr_legacy b WHERE x_migrate AND a.barcode = b.usrname
LOOP
- FOR x_id IN SELECT DISTINCT id FROM actor_usr_legacy WHERE x_migrate AND usrname = x_barcode
+ FOR x_id IN SELECT DISTINCT id FROM m_actor_usr_legacy WHERE x_migrate AND usrname = x_barcode
LOOP
- UPDATE actor_usr_legacy SET usrname = migration_schema || '_' || usrname WHERE id = x_id;
+ UPDATE m_actor_usr_legacy SET usrname = migration_schema || '_' || usrname WHERE id = x_id;
GET DIAGNOSTICS row_count = ROW_COUNT;
incumbent_barcode_collision_count := incumbent_barcode_collision_count + row_count;
END LOOP;
RAISE INFO '% incumbent barcode collisions', incumbent_barcode_collision_count;
FOR x_barcode IN
- SELECT a.usrname FROM actor.usr a, actor_usr_legacy b WHERE x_migrate AND a.usrname = b.usrname
+ SELECT a.usrname FROM actor.usr a, m_actor_usr_legacy b WHERE x_migrate AND a.usrname = b.usrname
LOOP
- FOR x_id IN SELECT DISTINCT id FROM actor_usr_legacy WHERE x_migrate AND usrname = x_barcode
+ FOR x_id IN SELECT DISTINCT id FROM m_actor_usr_legacy WHERE x_migrate AND usrname = x_barcode
LOOP
- UPDATE actor_usr_legacy SET usrname = migration_schema || '_' || usrname WHERE id = x_id;
+ UPDATE m_actor_usr_legacy SET usrname = migration_schema || '_' || usrname WHERE id = x_id;
GET DIAGNOSTICS row_count = ROW_COUNT;
incumbent_usrname_collision_count := incumbent_usrname_collision_count + row_count;
END LOOP;