Skip to content

Commit 528d493

Browse files
committed
feat: add import report and errors models #216
1 parent 55f7f35 commit 528d493

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

app/models/import_error.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class ImportError < ApplicationRecord
2+
belongs_to :import_report
3+
4+
validates :error_type, presence: true
5+
6+
scope :by_type, ->(type) { where(error_type: type) }
7+
scope :with_files, -> { where.not(file_name: nil) }
8+
end

app/models/import_report.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class ImportReport < ApplicationRecord
2+
has_many :import_errors, dependent: :destroy
3+
4+
validates :import_type, presence: true
5+
6+
enum status: { pending: "pending", completed: "completed", failed: "failed" }
7+
8+
scope :recent, -> { order(created_at: :desc) }
9+
scope :by_type, ->(type) { where(import_type: type) }
10+
end
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
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class CreateImportReports < ActiveRecord::Migration[8.0]
2+
def change
3+
create_table :import_reports do |t|
4+
t.string :import_type, null: false
5+
t.datetime :started_at
6+
t.datetime :completed_at
7+
t.json :summary_stats
8+
t.json :unmatched_files
9+
t.json :error_details
10+
t.string :status, default: 'pending'
11+
12+
t.timestamps
13+
end
14+
15+
add_index :import_reports, :import_type
16+
end
17+
end

0 commit comments

Comments
 (0)