diff --git a/scripts/database/delete_unfixable_orcids.sql b/scripts/database/delete_unfixable_orcids.sql new file mode 100644 index 0000000000..d8b841c0d7 --- /dev/null +++ b/scripts/database/delete_unfixable_orcids.sql @@ -0,0 +1,52 @@ +-- !!!!!!! run fix_fixable_orcids.sql before this script, +-- !!!!!!! otherwse fixable ORCIDs will be lost +DO $$ +DECLARE + ids numeric[]; +BEGIN + -- find indetifiers of all dataset fields with supposed ORCID values + -- that don't match ORCIS format + SELECT ARRAY(select id + from datasetfield + where + datasetfieldtype_id in (select id + from datasetfieldtype + where + name = 'authorIdentifier') + and + datasetfieldparent_id in + (select datasetfieldparent_id + from datasetfield + where + id in (select datasetfield_id + from datasetfield_controlledvocabularyvalue + where + controlledvocabularyvalues_id in (select controlledvocabularyvalue.id + from controlledvocabularyvalue join datasetfieldtype ON controlledvocabularyvalue.datasetfieldtype_id = datasetfieldtype.id + where controlledvocabularyvalue.strvalue = 'ORCID' and datasetfieldtype.name = 'authorIdentifierScheme'))) + and fieldvalue !~ '^(\d{4}-){3}\d{3}[\dX]$' + and fieldvalue is not null) + INTO ids; + + -- clear all unfixable orcid values + update datasetfield + set + fieldvalue = null + where + id = any(ids); + + -- clear indetified schema selections for deleted ORCIDs + delete + from datasetfield_controlledvocabularyvalue + where datasetfield_id in (select id from datasetfield + where + datasetfieldparent_id in (select datasetfieldparent_id + from datasetfield + where + id = any(ids)) + and + datasetfieldtype_id in (select id + from datasetfieldtype + where + name = 'authorIdentifierScheme')); +END $$;; \ No newline at end of file diff --git a/scripts/database/fix_fixable_orcids.sql b/scripts/database/fix_fixable_orcids.sql new file mode 100644 index 0000000000..fe58a88212 --- /dev/null +++ b/scripts/database/fix_fixable_orcids.sql @@ -0,0 +1,41 @@ +-- fixes ORCID values +update datasetfield set fieldvalue = LTRIM(fieldvalue, 'ORCID: ') + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'ORCID: %'; +update datasetfield set fieldvalue = LTRIM(fieldvalue, 'ORCID ') + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'ORCID 0%'; + +update datasetfield set fieldvalue = LTRIM(fieldvalue, 'http://orcid.org/') + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'http://orcid.org/%'; +update datasetfield set fieldvalue = LTRIM(fieldvalue, 'https://orcid.org/') + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'https://orcid.org/%'; +update datasetfield set fieldvalue = LTRIM(fieldvalue, 'https://orcid.org/ ') + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'https://orcid.org/ %'; +update datasetfield set fieldvalue = LTRIM(fieldvalue, 'hhttps://orcid.org/') + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'hhttps://orcid.org/%'; +update datasetfield set fieldvalue = LTRIM(fieldvalue, 'Warsaw, Poland https://orcid.org/') + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'Warsaw, Poland https://orcid.org/%'; +update datasetfield set fieldvalue = LTRIM(fieldvalue, 'ORCID logo https://orcid.org/') + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'ORCID logo https://orcid.org/%'; +update datasetfield set fieldvalue = LTRIM(fieldvalue, 'orcid logo https://orcid.org/') + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'orcid logo https://orcid.org/%'; +update datasetfield set fieldvalue = LTRIM(fieldvalue, 'orcid.org/') + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like 'orcid.org/%'; + +update datasetfield set fieldvalue = RTRIM(fieldvalue, 'Zbiór') + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like '%Zbiór'; + +update datasetfield set fieldvalue = ('0' || fieldvalue) + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like '000-%'; + +update datasetfield set fieldvalue = LTRIM(fieldvalue, '/') + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like '/0000-%'; + +update datasetfield set fieldvalue = RTRIM(fieldvalue, '.') + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like '%.'; + +update datasetfield set fieldvalue = RTRIM(fieldvalue, ',') + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier') and fieldvalue like '%,'; + + +update datasetfield set fieldvalue = TRIM(fieldvalue) + where datasetfieldtype_id in (select id from datasetfieldtype where name = 'authorIdentifier'); \ No newline at end of file