From 61230365a8f5e67c96043faaa160cf6fa5b0d7f1 Mon Sep 17 00:00:00 2001 From: Jason Gessner Date: Mon, 17 Feb 2025 04:51:48 +0000 Subject: [PATCH] Fix issue with empty project import for RawPrinting. --- app/models/raw_printing.rb | 1 - lib/tasks/cards.rake | 14 +++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/models/raw_printing.rb b/app/models/raw_printing.rb index a9b220a..8c4fc9f 100644 --- a/app/models/raw_printing.rb +++ b/app/models/raw_printing.rb @@ -6,7 +6,6 @@ class RawPrinting < ApplicationRecord self.table_name = 'printings' - belongs_to :card belongs_to :card_set belongs_to :raw_card, inverse_of: :raw_printings, primary_key: :id, foreign_key: :card_id has_one :faction, through: :card diff --git a/lib/tasks/cards.rake b/lib/tasks/cards.rake index 1954c3c..26ec4a0 100644 --- a/lib/tasks/cards.rake +++ b/lib/tasks/cards.rake @@ -9,6 +9,7 @@ namespace :cards do text.downcase .unicode_normalize(:nfd) .gsub(/\P{ASCII}/, '') + # TODO(plural): Fix contractions to match javascript version. .gsub(/'s(\p{Space}|\z)/, 's\1') .split(/[\p{Space}\p{Punct}]+/) .reject { |s| s&.strip&.empty? } @@ -264,13 +265,12 @@ namespace :cards do next if face_subtypes.nil? face_subtypes.each do |s| - puts "Adding subtype #{s} to face #{i} of card #{new_face.card_id}" + puts " Adding subtype #{s} to face #{i} of card #{new_face.card_id}" cfcs = CardFaceCardSubtype.new( card_id: new_face.card_id, face_index: i, card_subtype_id: s ) - puts cfcs.inspect cfcs.save end i += 1 @@ -407,6 +407,7 @@ namespace :cards do def import_printings(printings) card_sets = CardSet.all.index_by(&:id) + puts "Printings argument is #{printings.size}" new_printings = [] printings.each do |printing| new_printings << RawPrinting.new( @@ -424,11 +425,14 @@ namespace :cards do num_printings = 0 new_printings.each_slice(250) do |s| + puts s.inspect num_printings += s.length puts " #{num_printings} printings" - RawPrinting.import s, on_duplicate_key_update: { conflict_target: [:id], columns: :all } + RawPrinting.import s, on_duplicate_key_update: { conflict_target: [:id], columns: :all }, raise_error: true end + puts "Printings has #{RawPrinting.count} entries" + # Use ROW_NUMBER() to identify the position of each printing in the each set. sql = <<~SQL UPDATE @@ -979,6 +983,10 @@ namespace :cards do puts 'Refreshing materialized view for printings...' Scenic.database.refresh_materialized_view(:unified_printings, concurrently: false, cascade: false) + puts "unified_cards has #{Card.all.size} records." + puts "unified_printings has #{Printing.all.size} records." + puts "unified_restrictions has #{UnifiedRestriction.all.size} records." + puts '' puts 'Done!' end end