-- remove custom metadata block (in this case, metadatablock id 7)
-- wiping and re-provisioning the VM turned out to be easier

delete from datasetfieldvalue where datasetfieldvalue.id in 
(
	select datasetfieldvalue.id from datasetfieldvalue join datasetfield on datasetfieldvalue.datasetfield_id=datasetfield.id
	join datasetfieldtype on datasetfield.datasetfieldtype_id=datasetfieldtype.id 
	where datasetfieldtype.metadatablock_id=7
);

delete from datasetfield_controlledvocabularyvalue where datasetfield_id in 
( 
	select datasetfield.id from datasetfield join datasetfieldtype on datasetfield.datasetfieldtype_id=datasetfieldtype.id 
	where datasetfieldtype.metadatablock_id=7
);

delete from datasetfield where datasetfield.id in 
(
	select datasetfield.id from datasetfield join datasetfieldtype on datasetfield.datasetfieldtype_id=datasetfieldtype.id
	where datasetfieldtype.metadatablock_id=7
);

delete from controlledvocabularyvalue where datasetfieldtype_id in 
(
	select datasetfieldtype.id from datasetfieldtype where metadatablock_id=7
);
delete from dataversefacet where datasetfieldtype_id in 
(
	select datasetfieldtype.id from datasetfieldtype where metadatablock_id=7
);

delete from datasetfieldtype where metadatablock_id=7;
delete from dataverse_metadatablock where metadatablocks_id=7;
delete from metadatablock where metadatablock.id=7;

