From 65fc144a4654330ef2abd9c28a14774b8b0a44a5 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Wed, 29 May 2024 10:32:21 +0200 Subject: [PATCH] Task to check missing foreing ids in spree_line_items --- ...sing_required_ids_in_spree_line_items.rake | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/tasks/data/check_missing_required_ids_in_spree_line_items.rake diff --git a/lib/tasks/data/check_missing_required_ids_in_spree_line_items.rake b/lib/tasks/data/check_missing_required_ids_in_spree_line_items.rake new file mode 100644 index 0000000000..cb4b788b94 --- /dev/null +++ b/lib/tasks/data/check_missing_required_ids_in_spree_line_items.rake @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +namespace :ofn do + namespace :data do + desc 'Checking missing required ids in Spree::LineItem' + task check_missing_required_missing_ids_in_spree_line_items: :environment do + puts 'Checking for null order_id' + ids = Spree::LineItem.where(order_id: nil).pluck(:id) + + if ids.empty? + puts 'No NULL order_id found in spree_line_items' + else + puts 'NULL order_ids s have been found in spree_line_items:' + print ids + end + + puts 'Checking for null variant_id' + ids = Spree::LineItem.where(variant_id: nil).pluck(:id) + + if ids.empty? + puts 'No NULL variant_id found in spree_line_items' + else + puts 'NULL variant_id s have been found in spree_line_items:' + print ids + end + end + end +end