Mercurial > hg > LGDataverses
diff scripts/migration/migrate_links.sql @ 10:a50cf11e5178
Rewrite LGDataverse completely upgrading to dataverse4.0
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Tue, 08 Sep 2015 17:00:21 +0200 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/migration/migrate_links.sql Tue Sep 08 17:00:21 2015 +0200 @@ -0,0 +1,44 @@ + +-- links to datasets +insert into datasetlinkingdataverse (linkingdataverse_id, dataset_id, linkcreatetime) +select c.owner_id, ds.id, now() +from _dvn3_coll_studies link, _dvn3_vdccollection c, _dvn3_study s, dataset ds +where link.vdc_collection_id=c.id +and link.study_id=s.id +and s.owner_id != c.owner_id --don't include if already part of this dataverse +and ds.authority = s.authority +and ds.protocol = s.protocol +and ds.identifier = s.studyid; + + +-- links to root collections (now linked to dataverses) +insert into dataverselinkingdataverse (linkingdataverse_id, dataverse_id, linkcreatetime) +select vdc_id, owner_id, now() +from _dvn3_vdc_linked_collections link, _dvn3_vdccollection c +where link.linked_collection_id=c.id +and c.parentcollection_id is null; + +-- links to other, static collections (now linked to just the studies from them) +insert into datasetlinkingdataverse (linkingdataverse_id, dataset_id, linkcreatetime) +select vdc_id, ds.id, now() +from _dvn3_vdc_linked_collections link, _dvn3_coll_studies contents, _dvn3_vdccollection c, _dvn3_study s, dataset ds +where link.linked_collection_id=c.id +and c.parentcollection_id is not null +and c.type='static' +and c.id = contents.vdc_collection_id +and contents.study_id=s.id +and s.owner_id != vdc_id -- don't include if already part of this dataverse +and ds.authority = s.authority +and ds.protocol = s.protocol +and ds.identifier = s.studyid; + + + +----------------------- +-- reset sequences +----------------------- + +SELECT setval('datasetlinkingdataverse_id_seq', (SELECT MAX(id) FROM datasetlinkingdataverse)); +SELECT setval('dataverselinkingdataverse_id_seq', (SELECT MAX(id) FROM dataverselinkingdataverse)); + +
