Files
simple-aircraft-manager-rails/db/migrate/20261115020000_create_draft_batches.rb
rickyandClaude Opus 5.5 e4c27c6ff7 API: draft logbook entries for signing
- POST /aircraft/:id/draft_batches turns a visit's work items into one
  unsigned entry per logbook, signed in the app (by a user with a
  certificate, or a mechanic through a returned or emailed invitation link).
- The squawks they resolve and inspections they complete (with their result)
  are held until every entry is signed, then applied, attributed to the last
  signer; draft_batch.completed webhook. A draft never clears a squawk alone.
- Drafts are for owners (integrations act for one, drafts:write scope);
  unsigned drafts can be withdrawn; lookup by external_ref.
- The signing and entry pages show where a draft came from and what signing
  will do.
- The suggested recordkeeping procedures describe the API once it's in use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 19:11:38 -05:00

22 lines
1001 B
Ruby

# Draft logbook entries from the API (docs/api.md, "Draft entries"): one
# batch per visit, one unsigned entry per logbook; what the work resolves
# (squawks, inspections) is held until every entry is signed.
class CreateDraftBatches < ActiveRecord::Migration[8.1]
def change
create_table :draft_batches do |t|
t.references :aircraft, null: false, foreign_key: true
t.references :api_token, foreign_key: true
t.references :created_by, foreign_key: { to_table: :users }
t.string :external_ref
t.string :status, null: false, default: "awaiting_signature" # awaiting_signature | completed | withdrawn
t.string :signer_email
t.json :held, null: false, default: {} # { "squawks" => [{ "id", "log" }], "inspections" => [{ "id", "log" }] }
t.datetime :completed_at
t.timestamps
t.index :external_ref
end
add_reference :logbook_entries, :draft_batch, foreign_key: true
add_column :logbook_entries, :external_ref, :string
end
end