upgrade harvest_source_clear to not delete from authz models removed in migration 078

This commit is contained in:
florianm 2015-08-19 10:25:20 +08:00
parent 83cca925c9
commit 1905caa961
1 changed files with 10 additions and 2 deletions

View File

@ -140,14 +140,22 @@ def harvest_source_clear(context,data_dict):
delete from resource_group where package_id in
(select id from package where state = 'to_delete');
'''
# CKAN pre-2.5: authz models were removed in migration 078
if toolkit.check_ckan_version(max_version='2.4'):
sql += '''
delete from user_object_role where id not in
(select user_object_role_id from package_role) and context = 'Package';
delete from package_role where package_id in
(select id from package where state = 'to_delete');
'''
sql += '''
delete from harvest_object_error where harvest_object_id in (select id from harvest_object where harvest_source_id = '{harvest_source_id}');
delete from harvest_object_extra where harvest_object_id in (select id from harvest_object where harvest_source_id = '{harvest_source_id}');
delete from harvest_object where harvest_source_id = '{harvest_source_id}';
delete from harvest_gather_error where harvest_job_id in (select id from harvest_job where source_id = '{harvest_source_id}');
delete from harvest_job where source_id = '{harvest_source_id}';
delete from package_role where package_id in (select id from package where state = 'to_delete' );
delete from user_object_role where id not in (select user_object_role_id from package_role) and context = 'Package';
delete from package_tag_revision where package_id in (select id from package where state = 'to_delete');
delete from member_revision where table_id in (select id from package where state = 'to_delete');
delete from package_extra_revision where package_id in (select id from package where state = 'to_delete');