From e2ae409082a3e585958a9e7742fad3a125bd5e2e Mon Sep 17 00:00:00 2001 From: Michael Bauer Date: Fri, 28 Apr 2017 18:46:26 +1000 Subject: [PATCH] Bugfix: Clear Data not clearing documents from Postgres database --- script/clear_data.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/script/clear_data.rb b/script/clear_data.rb index 82bdd59..80c5ac8 100644 --- a/script/clear_data.rb +++ b/script/clear_data.rb @@ -15,8 +15,12 @@ def main(collection_name) solr.delete_by_query "collection_name_facet:#{collection_name}" solr.commit ActiveRecord::Base.establish_connection(config[:postgres_worker][:activerecord]) - collection_id = Collection.where(name: collection_name).first.id - Item.where(collection_id: collection_id).delete_all + if collection = Collection.where(name: collection_name).first + Item.where(collection_id: collection.id).delete_all + #Delete all documents that point to invalid items. + sql = "DELETE FROM documents WHERE item_id NOT IN (SELECT id FROM items);" + ActiveRecord::Base.connection.execute(sql) + end sesame = SesameClient.new(config[:sesame_worker]) sesame.clear_repository(collection_name) sesame.close