-- +goose Up
-- Migration: Create flight_prep_checks table
-- Date: 2026-04-09
-- Description: Per-inspection execution data for flight preparation checklist items

CREATE TABLE flight_prep_checks (
    id BINARY(16) PRIMARY KEY,
    flight_inspection_id BINARY(16) NOT NULL,
    flight_prep_item_id BINARY(16) NOT NULL,
    is_done TINYINT(1) NOT NULL DEFAULT 0,
    note TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    created_by BINARY(16),
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    updated_by BINARY(16),

    CONSTRAINT fk_flight_prep_checks_flight_inspection FOREIGN KEY (flight_inspection_id) REFERENCES flight_inspections(id) ON DELETE CASCADE,
    CONSTRAINT fk_flight_prep_checks_flight_prep_item FOREIGN KEY (flight_prep_item_id) REFERENCES flight_prep_items(id) ON DELETE RESTRICT,

    INDEX idx_flight_prep_checks_flight_inspection (flight_inspection_id),
    INDEX idx_flight_prep_checks_flight_inspection_sorted (flight_inspection_id, is_done),
    UNIQUE KEY uk_flight_prep_checks_inspection_item (flight_inspection_id, flight_prep_item_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- +goose Down
DROP TABLE IF EXISTS flight_prep_checks;
