-- Add up migration script here

CREATE TABLE "owner_history" (
    "id" BIGSERIAL NOT NULL,
    "aircraft_id" BIGSERIAL NOT NULL,
    "pilot_id" uuid NOT NULL,
    "since" timestamp DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "owner_history_pkey" PRIMARY KEY ("id")
);

-- Pilot currently occupying/flying aircraft
CREATE TABLE "pilot_current_aircraft" (
    "pilot_id" uuid NOT NULL,
    "aircraft_id" uuid NOT NULL,
    CONSTRAINT "pilot_aircraft_pkey" PRIMARY KEY ("pilot_id", "aircraft_id"),
) WITH (oids = false);

CREATE TABLE "flight_log" (
    "id" BIGSERIAL NOT NULL,
    "pilot_id" uuid NOT NULL,
    "aircraft_id" uuid NOT NULL,
    "takeoff_time" timestamp DEFAULT CURRENT_TIMESTAMP,
    "takeoff_latitude_deg" NUMERIC NOT NULL,
    "takeoff_longitude_deg" NUMERIC NOT NULL,
    "takeoff_elevation_ft" NUMERIC NOT NULL DEFAULT 0,
    "landing" timestamp,
    "landing_latitude_deg" NUMERIC NOT NULL,
    "landing_longitude_deg" NUMERIC NOT NULL,
    "landing_elevation_ft" NUMERIC NOT NULL DEFAULT 0,
    CONSTRAINT "flight_log_pkey" PRIMARY KEY ("id")
);
