Skip to content

Commit c670a2c

Browse files
committed
wip #221
1 parent 9ea1b10 commit c670a2c

File tree

5 files changed

+82
-8
lines changed

5 files changed

+82
-8
lines changed

app/models/import_error.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
# == Schema Information
2+
#
3+
# Table name: import_errors
4+
#
5+
# id :bigint not null, primary key
6+
# error_message :text
7+
# error_type :string not null
8+
# file_name :string
9+
# metadata :json
10+
# created_at :datetime not null
11+
# updated_at :datetime not null
12+
# import_report_id :bigint not null
13+
# topic_id :integer
14+
#
15+
# Indexes
16+
#
17+
# index_import_errors_on_error_type (error_type)
18+
# index_import_errors_on_file_name (file_name)
19+
# index_import_errors_on_import_report_id (import_report_id)
20+
#
21+
# Foreign Keys
22+
#
23+
# fk_rails_... (import_report_id => import_reports.id)
24+
#
125
class ImportError < ApplicationRecord
226
belongs_to :import_report
327

app/models/import_report.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
# == Schema Information
2+
#
3+
# Table name: import_reports
4+
#
5+
# id :bigint not null, primary key
6+
# completed_at :datetime
7+
# error_details :json
8+
# import_type :string not null
9+
# started_at :datetime
10+
# status :string default("pending")
11+
# summary_stats :json
12+
# unmatched_files :json
13+
# created_at :datetime not null
14+
# updated_at :datetime not null
15+
#
16+
# Indexes
17+
#
18+
# index_import_reports_on_import_type (import_type)
19+
#
120
class ImportReport < ApplicationRecord
221
has_many :import_errors, dependent: :destroy
322

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class CreateImportErrors < ActiveRecord::Migration[7.0]
2+
def change
3+
create_table :import_errors do |t|
4+
t.references :import_report, null: false, foreign_key: true
5+
t.string :error_type, null: false
6+
t.string :file_name
7+
t.integer :topic_id
8+
t.text :error_message
9+
t.json :metadata
10+
11+
t.timestamps
12+
end
13+
14+
add_index :import_errors, :error_type
15+
add_index :import_errors, :file_name
16+
end
17+
end

db/schema.rb

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/autorequire/data_import.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,12 @@ def self.import_training_documents
202202
importable_rows = match_csv_with_azure_files(valid_csv_rows, azure_files)
203203
unmatched_files = collect_unmatched_files(csv_data, azure_files, importable_rows)
204204

205-
log_import_summary(valid_csv_rows, azure_files, importable_rows)
205+
report.update!(
206+
summary_stats: build_summary_stats(import_stats, csv_data, azure_files),
207+
unmatched_files: unmatched_files,
208+
error_details: import_stats[:error_files],
209+
status: "planned"
210+
)
206211

207212
process_document_attachments(importable_rows, import_stats)
208213

@@ -331,12 +336,6 @@ def self.build_summary_stats(import_stats, csv_data, azure_files)
331336
}
332337
end
333338

334-
def self.log_import_summary(csv_rows, azure_files, importable_rows)
335-
puts "CSV rows with topics: #{csv_rows.size}"
336-
puts "Azure files found: #{azure_files.size}"
337-
puts "Importable files: #{importable_rows.size}"
338-
end
339-
340339
def self.log_final_results(stats)
341340
puts "Topics not found: #{stats[:topics_without_csv].size}"
342341
puts "Successful attachments: #{stats[:successful_attachments].size}"

0 commit comments

Comments
 (0)