Files
simple-aircraft-manager-rails/app/models/inspection_record.rb
T
rickyandClaude Opus 5.5 68a1719db2 Records integrity: history, nightly backup and check, records package
AC 120-78B chapter 3:
- Every change to logbook entries, sub-components, signatures, inspection
  records, AD compliance, major records, W&B, components, squawks and
  documents is kept as a RecordVersion (who, IP, when, field changes),
  hash-chained per aircraft; versions can't be edited or deleted. Shown on
  each logbook entry and in Activity -> Record history
- Nightly job: SQLite online-backup copy to storage/backups, verified
  (integrity_check + record counts), pruned to the configured number; then
  an integrity check of the history chains and every signature's seal and
  fingerprint. Results on Admin -> About ("Back up and check now"); admins
  are emailed on failure
- Software versions recorded (first/last seen) on Admin -> About
- Records package (Access & Sharing): logbook entries PDF with signatures,
  signatures.csv, record-history.csv, self-contained status report HTML,
  the .sam.zip, and a README, for the FAA/NTSB or a buyer
- Legacy (paper) records: documents can be marked as legacy records;
  aircraft have an "electronic records since" date (status report, package)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 13:21:26 -05:00

24 lines
846 B
Ruby

class InspectionRecord < ApplicationRecord
include Versioned
belongs_to :inspection_type
belongs_to :aircraft, optional: true
belongs_to :component, optional: true
belongs_to :logbook_entry, optional: true
has_many :ad_compliances, dependent: :nullify
validates :date, presence: true
validate { errors.add(:base, "Must belong to an aircraft or component") unless aircraft_id || component_id }
scope :recent_first, -> { order(date: :desc, created_at: :desc) }
# Records belonging to the aircraft, or to any of its components.
def self.for_aircraft(aircraft)
where(aircraft_id: aircraft.id).or(where(component_id: aircraft.components.select(:id)))
end
# Hours at inspection, falling back to the linked logbook entry.
def hours_at_inspection
aircraft_hours || logbook_entry&.aircraft_hours_at_entry
end
end