Initial commit: Rails port of Simple Aircraft Manager

Rails 8.1 + SQLite rewrite of marbindrakon/simple-aircraft-manager,
designed to self-host as a single container (Solid Queue/Cache/Cable,
Active Storage on disk, Hotwire + importmap, Tailwind).

- Airworthiness engine ported from health/services.py (ADs, grounding
  squawks, inspection recurrency, component replacement)
- Hours updates and flight logs cascading to in-service components,
  optional airworthiness enforcement
- Components, squawks, ADs, inspections, logbook, documents, major
  records, oil/fuel consumption stats and charts, activity log
- Admin/owner/pilot RBAC and public share links (status/maintenance)
- Docker Compose and Kamal deployment, env-driven production config
- Service and integration tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-04 17:59:08 -05:00
commit 38df19c331
264 files changed
+8365

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
ActiveRecord::Schema[7.1].define(version: 1) do
create_table "solid_cable_messages", force: :cascade do |t|
t.binary "channel", limit: 1024, null: false
t.binary "payload", limit: 536870912, null: false
t.datetime "created_at", null: false
t.integer "channel_hash", limit: 8, null: false
t.index ["channel"], name: "index_solid_cable_messages_on_channel"
t.index ["channel_hash"], name: "index_solid_cable_messages_on_channel_hash"
t.index ["created_at"], name: "index_solid_cable_messages_on_created_at"
end
end
+12
View File
@@ -0,0 +1,12 @@
ActiveRecord::Schema[7.2].define(version: 1) do
create_table "solid_cache_entries", force: :cascade do |t|
t.binary "key", limit: 1024, null: false
t.binary "value", limit: 536870912, null: false
t.datetime "created_at", null: false
t.integer "key_hash", limit: 8, null: false
t.integer "byte_size", limit: 4, null: false
t.index ["byte_size"], name: "index_solid_cache_entries_on_byte_size"
t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size"
t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true
end
end
+11
View File
@@ -0,0 +1,11 @@
class CreateUsers < ActiveRecord::Migration[8.0]
def change
create_table :users do |t|
t.string :email_address, null: false
t.string :password_digest, null: false
t.timestamps
end
add_index :users, :email_address, unique: true
end
end
@@ -0,0 +1,11 @@
class CreateSessions < ActiveRecord::Migration[8.0]
def change
create_table :sessions do |t|
t.references :user, null: false, foreign_key: true
t.string :ip_address
t.string :user_agent
t.timestamps
end
end
end
@@ -0,0 +1,57 @@
# This migration comes from active_storage (originally 20170806125915)
class CreateActiveStorageTables < ActiveRecord::Migration[7.0]
def change
# Use Active Record's configured type for primary and foreign keys
primary_key_type, foreign_key_type = primary_and_foreign_key_types
create_table :active_storage_blobs, id: primary_key_type do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.string :service_name, null: false
t.bigint :byte_size, null: false
t.string :checksum
if connection.supports_datetime_with_precision?
t.datetime :created_at, precision: 6, null: false
else
t.datetime :created_at, null: false
end
t.index [ :key ], unique: true
end
create_table :active_storage_attachments, id: primary_key_type do |t|
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
t.references :blob, null: false, type: foreign_key_type
if connection.supports_datetime_with_precision?
t.datetime :created_at, precision: 6, null: false
else
t.datetime :created_at, null: false
end
t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
create_table :active_storage_variant_records, id: primary_key_type do |t|
t.belongs_to :blob, null: false, index: false, type: foreign_key_type
t.string :variation_digest, null: false
t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end
private
def primary_and_foreign_key_types
config = Rails.configuration.generators
setting = config.options[config.orm][:primary_key_type]
primary_key_type = setting || :primary_key
foreign_key_type = setting || :bigint
[ primary_key_type, foreign_key_type ]
end
end
@@ -0,0 +1,261 @@
class CreateAircraftDomain < ActiveRecord::Migration[8.0]
def change
add_column :users, :name, :string
add_column :users, :admin, :boolean, null: false, default: false
create_table :aircraft do |t|
t.string :tail_number, null: false
t.string :make
t.string :model
t.string :serial_number
t.text :description
t.date :purchased
t.string :status, null: false, default: "AVAILABLE"
t.decimal :tach_time, precision: 8, scale: 1, null: false, default: 0
t.decimal :tach_time_offset, precision: 8, scale: 1, null: false, default: 0
t.decimal :hobbs_time, precision: 8, scale: 1, null: false, default: 0
t.decimal :hobbs_time_offset, precision: 8, scale: 1, null: false, default: 0
t.boolean :airworthiness_enforcement, null: false, default: false
t.timestamps
end
create_table :aircraft_roles do |t|
t.references :aircraft, null: false, foreign_key: true
t.references :user, null: false, foreign_key: true
t.string :role, null: false
t.timestamps
end
add_index :aircraft_roles, [ :aircraft_id, :user_id ], unique: true
create_table :aircraft_notes do |t|
t.references :aircraft, null: false, foreign_key: true
t.references :user, foreign_key: { on_delete: :nullify }
t.text :text, null: false
t.boolean :public, null: false, default: false
t.datetime :edited_at
t.timestamps
end
create_table :aircraft_events do |t|
t.references :aircraft, null: false, foreign_key: true
t.references :user, foreign_key: { on_delete: :nullify }
t.string :category, null: false
t.string :event_name, null: false
t.text :notes
t.datetime :created_at, null: false
end
add_index :aircraft_events, [ :aircraft_id, :created_at ]
create_table :share_tokens do |t|
t.references :aircraft, null: false, foreign_key: true
t.references :created_by, foreign_key: { to_table: :users, on_delete: :nullify }
t.string :token, null: false
t.string :label
t.string :privilege, null: false, default: "status"
t.datetime :expires_at
t.timestamps
end
add_index :share_tokens, :token, unique: true
create_table :component_types do |t|
t.string :name, null: false
t.boolean :consumable, null: false, default: false
t.timestamps
end
add_index :component_types, :name, unique: true
create_table :components do |t|
t.references :aircraft, foreign_key: true
t.references :parent_component, foreign_key: { to_table: :components }
t.references :component_type, null: false, foreign_key: true
t.string :manufacturer, null: false
t.string :model, null: false
t.string :serial_number
t.string :install_location
t.text :notes
t.string :status, null: false, default: "SPARE"
t.date :date_in_service, null: false
t.decimal :hours_in_service, precision: 8, scale: 1, null: false, default: 0
t.decimal :hours_since_overhaul, precision: 8, scale: 1, null: false, default: 0
t.date :overhaul_date
t.integer :tbo_hours
t.integer :tbo_days
t.integer :inspection_hours
t.integer :inspection_days
t.integer :replacement_hours
t.integer :replacement_days
t.boolean :tbo_critical, null: false, default: true
t.boolean :on_condition, null: false, default: false
t.boolean :inspection_critical, null: false, default: true
t.boolean :replacement_critical, null: false, default: false
t.timestamps
end
create_table :document_collections do |t|
t.references :aircraft, null: false, foreign_key: true
t.string :name, null: false
t.text :description
t.string :visibility, null: false, default: "private"
t.boolean :starred, null: false, default: false
t.timestamps
end
create_table :documents do |t|
t.references :aircraft, null: false, foreign_key: true
t.references :document_collection, foreign_key: true
t.string :doc_type, null: false, default: "OTHER"
t.string :name, null: false
t.text :description
# nil = inherit from collection (or private when uncollected)
t.string :visibility
t.timestamps
end
create_table :logbook_entries do |t|
t.references :aircraft, null: false, foreign_key: true
t.references :document, foreign_key: { on_delete: :nullify } # scanned page(s)
t.string :log_type, null: false, default: "AC"
t.string :entry_type, null: false, default: "MAINTENANCE"
t.date :date, null: false
t.text :text, null: false
t.text :signoff_person
t.string :signoff_location
t.decimal :aircraft_hours_at_entry, precision: 8, scale: 1
t.integer :page_number
t.timestamps
end
create_table :squawks do |t|
t.references :aircraft, null: false, foreign_key: true
t.references :component, foreign_key: { on_delete: :nullify }
t.references :reported_by, foreign_key: { to_table: :users, on_delete: :nullify }
t.integer :priority, null: false, default: 0
t.text :issue_reported
t.text :notes
t.boolean :resolved, null: false, default: false
t.datetime :resolved_at
t.timestamps
end
create_table :inspection_types do |t|
t.string :name, null: false
t.boolean :recurring, null: false, default: false
t.boolean :required, null: false, default: true
t.decimal :recurring_hours, precision: 8, scale: 1, null: false, default: 0
t.integer :recurring_days, null: false, default: 0
t.integer :recurring_months, null: false, default: 0
t.timestamps
end
create_join_table :aircraft, :inspection_types do |t|
t.index [ :aircraft_id, :inspection_type_id ], unique: true, name: "idx_aircraft_inspection_types"
end
create_join_table :components, :inspection_types do |t|
t.index [ :component_id, :inspection_type_id ], unique: true, name: "idx_component_inspection_types"
end
create_table :inspection_records do |t|
t.references :inspection_type, null: false, foreign_key: true
t.references :aircraft, foreign_key: true
t.references :component, foreign_key: true
t.references :logbook_entry, foreign_key: { on_delete: :nullify }
t.date :date, null: false
t.decimal :aircraft_hours, precision: 8, scale: 1
t.text :notes
t.timestamps
end
create_table :airworthiness_directives do |t|
t.string :name, null: false
t.string :short_description, null: false
t.text :required_action
t.string :compliance_type, null: false, default: "standard"
t.text :trigger_condition
t.boolean :recurring, null: false, default: false
t.decimal :recurring_hours, precision: 8, scale: 1, null: false, default: 0
t.integer :recurring_months, null: false, default: 0
t.integer :recurring_days, null: false, default: 0
t.string :bulletin_type, null: false, default: "ad"
t.boolean :mandatory, null: false, default: true
t.references :document, foreign_key: { on_delete: :nullify }
t.timestamps
end
create_join_table :aircraft, :airworthiness_directives do |t|
t.index [ :aircraft_id, :airworthiness_directive_id ], unique: true, name: "idx_aircraft_ads"
end
create_join_table :components, :airworthiness_directives do |t|
t.index [ :component_id, :airworthiness_directive_id ], unique: true, name: "idx_component_ads"
end
create_table :ad_compliances do |t|
t.references :airworthiness_directive, null: false, foreign_key: true
t.references :aircraft, foreign_key: true
t.references :component, foreign_key: true
t.references :logbook_entry, foreign_key: { on_delete: :nullify }
t.references :inspection_record, foreign_key: { on_delete: :nullify }
t.date :date_complied, null: false
t.text :compliance_notes, null: false
t.boolean :permanent, null: false, default: false
t.decimal :next_due_at_time, precision: 8, scale: 1, null: false, default: 0
t.decimal :aircraft_hours_at_compliance, precision: 8, scale: 1
t.timestamps
end
create_table :major_records do |t|
t.references :aircraft, null: false, foreign_key: true
t.references :component, foreign_key: { on_delete: :nullify }
t.references :form_337_document, foreign_key: { to_table: :documents, on_delete: :nullify }
t.references :stc_document, foreign_key: { to_table: :documents, on_delete: :nullify }
t.references :logbook_entry, foreign_key: { on_delete: :nullify }
t.string :record_type, null: false
t.string :title, null: false
t.text :description
t.date :date_performed, null: false
t.string :performed_by
t.string :stc_number
t.string :stc_holder
t.decimal :aircraft_hours, precision: 8, scale: 1
t.boolean :has_ica, null: false, default: false
t.text :ica_notes
t.text :notes
t.timestamps
end
create_table :flight_logs do |t|
t.references :aircraft, null: false, foreign_key: true
t.references :user, foreign_key: { on_delete: :nullify }
t.date :date, null: false
t.decimal :tach_time, precision: 6, scale: 1, null: false
t.decimal :tach_out, precision: 8, scale: 1
t.decimal :tach_in, precision: 8, scale: 1
t.decimal :hobbs_time, precision: 6, scale: 1
t.decimal :hobbs_out, precision: 8, scale: 1
t.decimal :hobbs_in, precision: 8, scale: 1
t.string :departure_location
t.string :destination_location
t.text :route
t.decimal :oil_added, precision: 6, scale: 2
t.string :oil_added_type
t.decimal :oil_level_after, precision: 6, scale: 2
t.decimal :fuel_added, precision: 8, scale: 2
t.string :fuel_added_type
t.decimal :fuel_level_after, precision: 8, scale: 2
t.text :notes
t.timestamps
end
create_table :consumable_records do |t|
t.references :aircraft, null: false, foreign_key: true
t.references :flight_log, foreign_key: { on_delete: :nullify }
t.string :record_type, null: false
t.date :date, null: false
t.decimal :quantity_added, precision: 6, scale: 2, null: false
t.decimal :level_after, precision: 6, scale: 2
t.string :consumable_type
t.decimal :flight_hours, precision: 8, scale: 1, null: false
t.text :notes
t.boolean :excluded_from_averages, null: false, default: false
t.timestamps
end
add_index :consumable_records, [ :aircraft_id, :record_type, :flight_hours ]
end
end
+160
View File
@@ -0,0 +1,160 @@
ActiveRecord::Schema[7.1].define(version: 1) do
create_table "solid_queue_blocked_executions", force: :cascade do |t|
t.bigint "job_id", null: false
t.string "queue_name", null: false
t.integer "priority", default: 0, null: false
t.string "concurrency_key", null: false
t.datetime "expires_at", null: false
t.datetime "created_at", null: false
t.index [ "concurrency_key", "priority", "job_id" ], name: "index_solid_queue_blocked_executions_for_release"
t.index [ "expires_at", "concurrency_key" ], name: "index_solid_queue_blocked_executions_for_maintenance"
t.index [ "job_id" ], name: "index_solid_queue_blocked_executions_on_job_id", unique: true
end
create_table "solid_queue_claimed_executions", force: :cascade do |t|
t.bigint "job_id", null: false
t.bigint "process_id"
t.datetime "created_at", null: false
t.index [ "job_id" ], name: "index_solid_queue_claimed_executions_on_job_id", unique: true
t.index [ "process_id", "job_id" ], name: "index_solid_queue_claimed_executions_on_process_id_and_job_id"
end
create_table "solid_queue_failed_executions", force: :cascade do |t|
t.bigint "job_id", null: false
t.text "error"
t.datetime "created_at", null: false
t.index [ "job_id" ], name: "index_solid_queue_failed_executions_on_job_id", unique: true
end
create_table "solid_queue_jobs", force: :cascade do |t|
t.string "queue_name", null: false
t.string "class_name", null: false
t.text "arguments"
t.integer "priority", default: 0, null: false
t.string "active_job_id"
t.datetime "scheduled_at"
t.datetime "finished_at"
t.string "concurrency_key"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.bigint "batch_id"
t.index [ "active_job_id" ], name: "index_solid_queue_jobs_on_active_job_id"
t.index [ "batch_id" ], name: "index_solid_queue_jobs_on_batch_id"
t.index [ "class_name" ], name: "index_solid_queue_jobs_on_class_name"
t.index [ "finished_at" ], name: "index_solid_queue_jobs_on_finished_at"
t.index [ "queue_name", "finished_at" ], name: "index_solid_queue_jobs_for_filtering"
t.index [ "scheduled_at", "finished_at" ], name: "index_solid_queue_jobs_for_alerting"
end
create_table "solid_queue_pauses", force: :cascade do |t|
t.string "queue_name", null: false
t.datetime "created_at", null: false
t.index [ "queue_name" ], name: "index_solid_queue_pauses_on_queue_name", unique: true
end
create_table "solid_queue_processes", force: :cascade do |t|
t.string "kind", null: false
t.datetime "last_heartbeat_at", null: false
t.bigint "supervisor_id"
t.integer "pid", null: false
t.string "hostname"
t.text "metadata"
t.datetime "created_at", null: false
t.string "name", null: false
t.index [ "last_heartbeat_at" ], name: "index_solid_queue_processes_on_last_heartbeat_at"
t.index [ "name", "supervisor_id" ], name: "index_solid_queue_processes_on_name_and_supervisor_id", unique: true
t.index [ "supervisor_id" ], name: "index_solid_queue_processes_on_supervisor_id"
end
create_table "solid_queue_ready_executions", force: :cascade do |t|
t.bigint "job_id", null: false
t.string "queue_name", null: false
t.integer "priority", default: 0, null: false
t.datetime "created_at", null: false
t.index [ "job_id" ], name: "index_solid_queue_ready_executions_on_job_id", unique: true
t.index [ "priority", "job_id" ], name: "index_solid_queue_poll_all"
t.index [ "queue_name", "priority", "job_id" ], name: "index_solid_queue_poll_by_queue"
end
create_table "solid_queue_recurring_executions", force: :cascade do |t|
t.bigint "job_id", null: false
t.string "task_key", null: false
t.datetime "run_at", null: false
t.datetime "created_at", null: false
t.index [ "job_id" ], name: "index_solid_queue_recurring_executions_on_job_id", unique: true
t.index [ "task_key", "run_at" ], name: "index_solid_queue_recurring_executions_on_task_key_and_run_at", unique: true
end
create_table "solid_queue_recurring_tasks", force: :cascade do |t|
t.string "key", null: false
t.string "schedule", null: false
t.string "command", limit: 2048
t.string "class_name"
t.text "arguments"
t.string "queue_name"
t.integer "priority", default: 0
t.boolean "static", default: true, null: false
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index [ "key" ], name: "index_solid_queue_recurring_tasks_on_key", unique: true
t.index [ "static" ], name: "index_solid_queue_recurring_tasks_on_static"
end
create_table "solid_queue_scheduled_executions", force: :cascade do |t|
t.bigint "job_id", null: false
t.string "queue_name", null: false
t.integer "priority", default: 0, null: false
t.datetime "scheduled_at", null: false
t.datetime "created_at", null: false
t.index [ "job_id" ], name: "index_solid_queue_scheduled_executions_on_job_id", unique: true
t.index [ "scheduled_at", "priority", "job_id" ], name: "index_solid_queue_dispatch_all"
end
create_table "solid_queue_semaphores", force: :cascade do |t|
t.string "key", null: false
t.integer "value", default: 1, null: false
t.datetime "expires_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index [ "expires_at" ], name: "index_solid_queue_semaphores_on_expires_at"
t.index [ "key", "value" ], name: "index_solid_queue_semaphores_on_key_and_value"
t.index [ "key" ], name: "index_solid_queue_semaphores_on_key", unique: true
end
create_table "solid_queue_batches", force: :cascade do |t|
t.string "active_job_batch_id"
t.string "description"
t.text "on_finish"
t.text "on_success"
t.text "on_failure"
t.text "metadata"
t.integer "total_jobs", default: 0, null: false
t.integer "completed_jobs", default: 0, null: false
t.integer "failed_jobs", default: 0, null: false
t.datetime "enqueued_at"
t.datetime "finished_at"
t.datetime "failed_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index [ "active_job_batch_id" ], name: "index_solid_queue_batches_on_active_job_batch_id", unique: true
t.index [ "finished_at" ], name: "index_solid_queue_batches_on_finished_at"
end
create_table "solid_queue_batch_executions", force: :cascade do |t|
t.bigint "job_id", null: false
t.bigint "batch_id", null: false
t.datetime "created_at", null: false
t.index [ "job_id" ], name: "index_solid_queue_batch_executions_on_job_id", unique: true
t.index [ "batch_id" ], name: "index_solid_queue_batch_executions_on_batch_id"
end
add_foreign_key "solid_queue_batch_executions", "solid_queue_batches", column: "batch_id", on_delete: :cascade
add_foreign_key "solid_queue_batch_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "solid_queue_claimed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "solid_queue_failed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "solid_queue_ready_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "solid_queue_recurring_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
end
Generated
+423
View File
@@ -0,0 +1,423 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2026_11_04_222400) do
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.bigint "record_id", null: false
t.bigint "blob_id", null: false
t.datetime "created_at", null: false
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end
create_table "active_storage_blobs", force: :cascade do |t|
t.string "key", null: false
t.string "filename", null: false
t.string "content_type"
t.text "metadata"
t.string "service_name", null: false
t.bigint "byte_size", null: false
t.string "checksum"
t.datetime "created_at", null: false
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end
create_table "active_storage_variant_records", force: :cascade do |t|
t.bigint "blob_id", null: false
t.string "variation_digest", null: false
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end
create_table "ad_compliances", force: :cascade do |t|
t.integer "airworthiness_directive_id", null: false
t.integer "aircraft_id"
t.integer "component_id"
t.integer "logbook_entry_id"
t.integer "inspection_record_id"
t.date "date_complied", null: false
t.text "compliance_notes", null: false
t.boolean "permanent", default: false, null: false
t.decimal "next_due_at_time", precision: 8, scale: 1, default: "0.0", null: false
t.decimal "aircraft_hours_at_compliance", precision: 8, scale: 1
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["aircraft_id"], name: "index_ad_compliances_on_aircraft_id"
t.index ["airworthiness_directive_id"], name: "index_ad_compliances_on_airworthiness_directive_id"
t.index ["component_id"], name: "index_ad_compliances_on_component_id"
t.index ["inspection_record_id"], name: "index_ad_compliances_on_inspection_record_id"
t.index ["logbook_entry_id"], name: "index_ad_compliances_on_logbook_entry_id"
end
create_table "aircraft", force: :cascade do |t|
t.string "tail_number", null: false
t.string "make"
t.string "model"
t.string "serial_number"
t.text "description"
t.date "purchased"
t.string "status", default: "AVAILABLE", null: false
t.decimal "tach_time", precision: 8, scale: 1, default: "0.0", null: false
t.decimal "tach_time_offset", precision: 8, scale: 1, default: "0.0", null: false
t.decimal "hobbs_time", precision: 8, scale: 1, default: "0.0", null: false
t.decimal "hobbs_time_offset", precision: 8, scale: 1, default: "0.0", null: false
t.boolean "airworthiness_enforcement", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "aircraft_airworthiness_directives", id: false, force: :cascade do |t|
t.integer "aircraft_id", null: false
t.integer "airworthiness_directive_id", null: false
t.index ["aircraft_id", "airworthiness_directive_id"], name: "idx_aircraft_ads", unique: true
end
create_table "aircraft_events", force: :cascade do |t|
t.integer "aircraft_id", null: false
t.integer "user_id"
t.string "category", null: false
t.string "event_name", null: false
t.text "notes"
t.datetime "created_at", null: false
t.index ["aircraft_id", "created_at"], name: "index_aircraft_events_on_aircraft_id_and_created_at"
t.index ["aircraft_id"], name: "index_aircraft_events_on_aircraft_id"
t.index ["user_id"], name: "index_aircraft_events_on_user_id"
end
create_table "aircraft_inspection_types", id: false, force: :cascade do |t|
t.integer "aircraft_id", null: false
t.integer "inspection_type_id", null: false
t.index ["aircraft_id", "inspection_type_id"], name: "idx_aircraft_inspection_types", unique: true
end
create_table "aircraft_notes", force: :cascade do |t|
t.integer "aircraft_id", null: false
t.integer "user_id"
t.text "text", null: false
t.boolean "public", default: false, null: false
t.datetime "edited_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["aircraft_id"], name: "index_aircraft_notes_on_aircraft_id"
t.index ["user_id"], name: "index_aircraft_notes_on_user_id"
end
create_table "aircraft_roles", force: :cascade do |t|
t.integer "aircraft_id", null: false
t.integer "user_id", null: false
t.string "role", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["aircraft_id", "user_id"], name: "index_aircraft_roles_on_aircraft_id_and_user_id", unique: true
t.index ["aircraft_id"], name: "index_aircraft_roles_on_aircraft_id"
t.index ["user_id"], name: "index_aircraft_roles_on_user_id"
end
create_table "airworthiness_directives", force: :cascade do |t|
t.string "name", null: false
t.string "short_description", null: false
t.text "required_action"
t.string "compliance_type", default: "standard", null: false
t.text "trigger_condition"
t.boolean "recurring", default: false, null: false
t.decimal "recurring_hours", precision: 8, scale: 1, default: "0.0", null: false
t.integer "recurring_months", default: 0, null: false
t.integer "recurring_days", default: 0, null: false
t.string "bulletin_type", default: "ad", null: false
t.boolean "mandatory", default: true, null: false
t.integer "document_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["document_id"], name: "index_airworthiness_directives_on_document_id"
end
create_table "airworthiness_directives_components", id: false, force: :cascade do |t|
t.integer "component_id", null: false
t.integer "airworthiness_directive_id", null: false
t.index ["component_id", "airworthiness_directive_id"], name: "idx_component_ads", unique: true
end
create_table "component_types", force: :cascade do |t|
t.string "name", null: false
t.boolean "consumable", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["name"], name: "index_component_types_on_name", unique: true
end
create_table "components", force: :cascade do |t|
t.integer "aircraft_id"
t.integer "parent_component_id"
t.integer "component_type_id", null: false
t.string "manufacturer", null: false
t.string "model", null: false
t.string "serial_number"
t.string "install_location"
t.text "notes"
t.string "status", default: "SPARE", null: false
t.date "date_in_service", null: false
t.decimal "hours_in_service", precision: 8, scale: 1, default: "0.0", null: false
t.decimal "hours_since_overhaul", precision: 8, scale: 1, default: "0.0", null: false
t.date "overhaul_date"
t.integer "tbo_hours"
t.integer "tbo_days"
t.integer "inspection_hours"
t.integer "inspection_days"
t.integer "replacement_hours"
t.integer "replacement_days"
t.boolean "tbo_critical", default: true, null: false
t.boolean "on_condition", default: false, null: false
t.boolean "inspection_critical", default: true, null: false
t.boolean "replacement_critical", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["aircraft_id"], name: "index_components_on_aircraft_id"
t.index ["component_type_id"], name: "index_components_on_component_type_id"
t.index ["parent_component_id"], name: "index_components_on_parent_component_id"
end
create_table "components_inspection_types", id: false, force: :cascade do |t|
t.integer "component_id", null: false
t.integer "inspection_type_id", null: false
t.index ["component_id", "inspection_type_id"], name: "idx_component_inspection_types", unique: true
end
create_table "consumable_records", force: :cascade do |t|
t.integer "aircraft_id", null: false
t.integer "flight_log_id"
t.string "record_type", null: false
t.date "date", null: false
t.decimal "quantity_added", precision: 6, scale: 2, null: false
t.decimal "level_after", precision: 6, scale: 2
t.string "consumable_type"
t.decimal "flight_hours", precision: 8, scale: 1, null: false
t.text "notes"
t.boolean "excluded_from_averages", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["aircraft_id", "record_type", "flight_hours"], name: "idx_on_aircraft_id_record_type_flight_hours_2c5ed6828c"
t.index ["aircraft_id"], name: "index_consumable_records_on_aircraft_id"
t.index ["flight_log_id"], name: "index_consumable_records_on_flight_log_id"
end
create_table "document_collections", force: :cascade do |t|
t.integer "aircraft_id", null: false
t.string "name", null: false
t.text "description"
t.string "visibility", default: "private", null: false
t.boolean "starred", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["aircraft_id"], name: "index_document_collections_on_aircraft_id"
end
create_table "documents", force: :cascade do |t|
t.integer "aircraft_id", null: false
t.integer "document_collection_id"
t.string "doc_type", default: "OTHER", null: false
t.string "name", null: false
t.text "description"
t.string "visibility"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["aircraft_id"], name: "index_documents_on_aircraft_id"
t.index ["document_collection_id"], name: "index_documents_on_document_collection_id"
end
create_table "flight_logs", force: :cascade do |t|
t.integer "aircraft_id", null: false
t.integer "user_id"
t.date "date", null: false
t.decimal "tach_time", precision: 6, scale: 1, null: false
t.decimal "tach_out", precision: 8, scale: 1
t.decimal "tach_in", precision: 8, scale: 1
t.decimal "hobbs_time", precision: 6, scale: 1
t.decimal "hobbs_out", precision: 8, scale: 1
t.decimal "hobbs_in", precision: 8, scale: 1
t.string "departure_location"
t.string "destination_location"
t.text "route"
t.decimal "oil_added", precision: 6, scale: 2
t.string "oil_added_type"
t.decimal "oil_level_after", precision: 6, scale: 2
t.decimal "fuel_added", precision: 8, scale: 2
t.string "fuel_added_type"
t.decimal "fuel_level_after", precision: 8, scale: 2
t.text "notes"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["aircraft_id"], name: "index_flight_logs_on_aircraft_id"
t.index ["user_id"], name: "index_flight_logs_on_user_id"
end
create_table "inspection_records", force: :cascade do |t|
t.integer "inspection_type_id", null: false
t.integer "aircraft_id"
t.integer "component_id"
t.integer "logbook_entry_id"
t.date "date", null: false
t.decimal "aircraft_hours", precision: 8, scale: 1
t.text "notes"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["aircraft_id"], name: "index_inspection_records_on_aircraft_id"
t.index ["component_id"], name: "index_inspection_records_on_component_id"
t.index ["inspection_type_id"], name: "index_inspection_records_on_inspection_type_id"
t.index ["logbook_entry_id"], name: "index_inspection_records_on_logbook_entry_id"
end
create_table "inspection_types", force: :cascade do |t|
t.string "name", null: false
t.boolean "recurring", default: false, null: false
t.boolean "required", default: true, null: false
t.decimal "recurring_hours", precision: 8, scale: 1, default: "0.0", null: false
t.integer "recurring_days", default: 0, null: false
t.integer "recurring_months", default: 0, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "logbook_entries", force: :cascade do |t|
t.integer "aircraft_id", null: false
t.integer "document_id"
t.string "log_type", default: "AC", null: false
t.string "entry_type", default: "MAINTENANCE", null: false
t.date "date", null: false
t.text "text", null: false
t.text "signoff_person"
t.string "signoff_location"
t.decimal "aircraft_hours_at_entry", precision: 8, scale: 1
t.integer "page_number"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["aircraft_id"], name: "index_logbook_entries_on_aircraft_id"
t.index ["document_id"], name: "index_logbook_entries_on_document_id"
end
create_table "major_records", force: :cascade do |t|
t.integer "aircraft_id", null: false
t.integer "component_id"
t.integer "form_337_document_id"
t.integer "stc_document_id"
t.integer "logbook_entry_id"
t.string "record_type", null: false
t.string "title", null: false
t.text "description"
t.date "date_performed", null: false
t.string "performed_by"
t.string "stc_number"
t.string "stc_holder"
t.decimal "aircraft_hours", precision: 8, scale: 1
t.boolean "has_ica", default: false, null: false
t.text "ica_notes"
t.text "notes"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["aircraft_id"], name: "index_major_records_on_aircraft_id"
t.index ["component_id"], name: "index_major_records_on_component_id"
t.index ["form_337_document_id"], name: "index_major_records_on_form_337_document_id"
t.index ["logbook_entry_id"], name: "index_major_records_on_logbook_entry_id"
t.index ["stc_document_id"], name: "index_major_records_on_stc_document_id"
end
create_table "sessions", force: :cascade do |t|
t.integer "user_id", null: false
t.string "ip_address"
t.string "user_agent"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_sessions_on_user_id"
end
create_table "share_tokens", force: :cascade do |t|
t.integer "aircraft_id", null: false
t.integer "created_by_id"
t.string "token", null: false
t.string "label"
t.string "privilege", default: "status", null: false
t.datetime "expires_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["aircraft_id"], name: "index_share_tokens_on_aircraft_id"
t.index ["created_by_id"], name: "index_share_tokens_on_created_by_id"
t.index ["token"], name: "index_share_tokens_on_token", unique: true
end
create_table "squawks", force: :cascade do |t|
t.integer "aircraft_id", null: false
t.integer "component_id"
t.integer "reported_by_id"
t.integer "priority", default: 0, null: false
t.text "issue_reported"
t.text "notes"
t.boolean "resolved", default: false, null: false
t.datetime "resolved_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["aircraft_id"], name: "index_squawks_on_aircraft_id"
t.index ["component_id"], name: "index_squawks_on_component_id"
t.index ["reported_by_id"], name: "index_squawks_on_reported_by_id"
end
create_table "users", force: :cascade do |t|
t.string "email_address", null: false
t.string "password_digest", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
t.boolean "admin", default: false, null: false
t.index ["email_address"], name: "index_users_on_email_address", unique: true
end
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "ad_compliances", "aircraft"
add_foreign_key "ad_compliances", "airworthiness_directives"
add_foreign_key "ad_compliances", "components"
add_foreign_key "ad_compliances", "inspection_records", on_delete: :nullify
add_foreign_key "ad_compliances", "logbook_entries", on_delete: :nullify
add_foreign_key "aircraft_events", "aircraft"
add_foreign_key "aircraft_events", "users", on_delete: :nullify
add_foreign_key "aircraft_notes", "aircraft"
add_foreign_key "aircraft_notes", "users", on_delete: :nullify
add_foreign_key "aircraft_roles", "aircraft"
add_foreign_key "aircraft_roles", "users"
add_foreign_key "airworthiness_directives", "documents", on_delete: :nullify
add_foreign_key "components", "aircraft"
add_foreign_key "components", "component_types"
add_foreign_key "components", "components", column: "parent_component_id"
add_foreign_key "consumable_records", "aircraft"
add_foreign_key "consumable_records", "flight_logs", on_delete: :nullify
add_foreign_key "document_collections", "aircraft"
add_foreign_key "documents", "aircraft"
add_foreign_key "documents", "document_collections"
add_foreign_key "flight_logs", "aircraft"
add_foreign_key "flight_logs", "users", on_delete: :nullify
add_foreign_key "inspection_records", "aircraft"
add_foreign_key "inspection_records", "components"
add_foreign_key "inspection_records", "inspection_types"
add_foreign_key "inspection_records", "logbook_entries", on_delete: :nullify
add_foreign_key "logbook_entries", "aircraft"
add_foreign_key "logbook_entries", "documents", on_delete: :nullify
add_foreign_key "major_records", "aircraft"
add_foreign_key "major_records", "components", on_delete: :nullify
add_foreign_key "major_records", "documents", column: "form_337_document_id", on_delete: :nullify
add_foreign_key "major_records", "documents", column: "stc_document_id", on_delete: :nullify
add_foreign_key "major_records", "logbook_entries", on_delete: :nullify
add_foreign_key "sessions", "users"
add_foreign_key "share_tokens", "aircraft"
add_foreign_key "share_tokens", "users", column: "created_by_id", on_delete: :nullify
add_foreign_key "squawks", "aircraft"
add_foreign_key "squawks", "components", on_delete: :nullify
add_foreign_key "squawks", "users", column: "reported_by_id", on_delete: :nullify
end
+91
View File
@@ -0,0 +1,91 @@
# Standard component types (idempotent).
[
[ "Engine", false ], [ "Propeller", false ], [ "Magneto", false ], [ "Vacuum Pump", false ],
[ "Alternator", false ], [ "Starter", false ], [ "ELT", false ], [ "ELT Battery", true ],
[ "Oil", true ], [ "Oil Filter", true ], [ "Spark Plugs", true ], [ "Air Filter", true ],
[ "Battery", true ], [ "Transponder", false ], [ "Tires", true ], [ "Brakes", true ]
].each do |name, consumable|
ComponentType.find_or_create_by!(name: name) { _1.consumable = consumable }
end
# Demo data: `DEMO=1 bin/rails db:seed`
if ENV["DEMO"].present?
admin = User.find_or_create_by!(email_address: "admin@example.com") do |u|
u.name = "Demo Admin"
u.password = "password123"
u.admin = true
end
pilot = User.find_or_create_by!(email_address: "pilot@example.com") do |u|
u.name = "Demo Pilot"
u.password = "password123"
end
Current.session = admin.sessions.first_or_create!(user_agent: "seed", ip_address: "127.0.0.1")
ac = Aircraft.find_or_create_by!(tail_number: "N12345") do |a|
a.make = "Cessna"
a.model = "172N"
a.serial_number = "17270001"
a.tach_time = 4210.3
a.hobbs_time = 5102.8
a.purchased = Date.new(2019, 6, 1)
end
ac.roles.find_or_create_by!(user: admin) { _1.role = "owner" }
ac.roles.find_or_create_by!(user: pilot) { _1.role = "pilot" }
type = ->(n) { ComponentType.find_by!(name: n) }
if ac.components.none?
engine = ac.components.create!(component_type: type.("Engine"), manufacturer: "Lycoming", model: "O-320-H2AD",
serial_number: "L-1234-76", status: "IN-USE", date_in_service: Date.new(2012, 3, 1),
hours_in_service: 1650, hours_since_overhaul: 1650, tbo_hours: 2000, overhaul_date: Date.new(2012, 3, 1))
ac.components.create!(component_type: type.("Propeller"), manufacturer: "McCauley", model: "1C160/DTM7553",
status: "IN-USE", date_in_service: Date.new(2015, 1, 1), hours_in_service: 900, hours_since_overhaul: 900,
tbo_hours: 2000, tbo_critical: true)
ac.components.create!(component_type: type.("Oil"), parent_component: engine, manufacturer: "Aeroshell",
model: "W100", status: "IN-USE", date_in_service: 40.days.ago, overhaul_date: 40.days.ago,
hours_since_overhaul: 44, replacement_hours: 50, replacement_days: 120, replacement_critical: true,
tbo_critical: false)
ac.components.create!(component_type: type.("ELT Battery"), manufacturer: "ACK", model: "E-04",
install_location: "Tailcone", status: "IN-USE", date_in_service: 2.years.ago, overhaul_date: 2.years.ago,
replacement_days: 730, replacement_critical: true, tbo_critical: false)
end
annual = InspectionType.find_or_create_by!(name: "Annual Inspection") { _1.recurring = true; _1.recurring_months = 12 }
xpdr = InspectionType.find_or_create_by!(name: "Transponder (91.413)") { _1.recurring = true; _1.recurring_months = 24 }
[ annual, xpdr ].each { |t| t.aircraft << ac unless t.aircraft.include?(ac) }
ac.inspection_records.find_or_create_by!(inspection_type: annual) { _1.date = 11.months.ago.to_date; _1.aircraft_hours = 4150 }
ac.inspection_records.find_or_create_by!(inspection_type: xpdr) { _1.date = 10.months.ago.to_date; _1.aircraft_hours = 4160 }
ad = AirworthinessDirective.find_or_create_by!(name: "2011-10-09") do |a|
a.short_description = "Seat rail inspection"
a.recurring = true
a.recurring_hours = 100
end
ad.aircraft << ac unless ad.aircraft.include?(ac)
ad.ad_compliances.find_or_create_by!(aircraft: ac) do |c|
c.date_complied = 11.months.ago.to_date
c.compliance_notes = "Inspected seat rails and stops IAW AD. No defects."
c.aircraft_hours_at_compliance = 4150
c.next_due_at_time = 4250
end
ac.squawks.find_or_create_by!(issue_reported: "Left landing light inop") { _1.priority = 2; _1.reported_by = pilot }
if ac.consumable_records.none?
hrs = 4150.0
[ 1, 1, 0.5, 1, 1, 0.5, 1 ].each_with_index do |qt, i|
hrs += [ 9, 11, 6, 10, 12, 5, 10 ][i]
ac.consumable_records.create!(record_type: "oil", date: (60 - i * 8).days.ago, quantity_added: qt, flight_hours: hrs)
ac.consumable_records.create!(record_type: "fuel", date: (60 - i * 8).days.ago,
quantity_added: (8.5 * [ 9, 11, 6, 10, 12, 5, 10 ][i]).round(1), flight_hours: hrs)
end
end
ac.logbook_entries.find_or_create_by!(date: 11.months.ago.to_date, text: "Annual inspection completed IAW 14 CFR 43 App. D. Aircraft found airworthy.") do |e|
e.entry_type = "INSPECTION"
e.aircraft_hours_at_entry = 4150
e.signoff_person = "J. Mechanic A&P/IA 1234567"
end
puts "Demo data loaded. Sign in as admin@example.com / password123 (or pilot@example.com)."
end