-- +goose Up
CREATE TABLE IF NOT EXISTS fm_reports (
  id BINARY(16) NOT NULL,
  takeover_id BINARY(16) NOT NULL,
  flight_id BINARY(16) NOT NULL,
  flight_inspection_id BINARY(16) NOT NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  created_by BINARY(16) NULL,
  updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  updated_by BINARY(16) NULL,
  deleted_at DATETIME NULL,
  deleted_by BINARY(16) NULL,
  PRIMARY KEY (id),
  UNIQUE KEY uidx_fm_reports_takeover_id (takeover_id),
  UNIQUE KEY uidx_fm_reports_flight_id (flight_id),
  UNIQUE KEY uidx_fm_reports_flight_inspection_id (flight_inspection_id),
  CONSTRAINT fk_fm_reports_takeover FOREIGN KEY (takeover_id) REFERENCES takeover_acs (id) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT fk_fm_reports_flight FOREIGN KEY (flight_id) REFERENCES flights (id) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT fk_fm_reports_flight_inspection FOREIGN KEY (flight_inspection_id) REFERENCES flight_inspections (id) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- +goose Down
DROP TABLE IF EXISTS fm_reports;
