| 1 | // This is your Prisma schema file, |
| 2 | // learn more about it in the docs: https://pris.ly/d/prisma-schema |
| 3 | |
| 4 | // Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? |
| 5 | // Try Prisma Accelerate: https://pris.ly/cli/accelerate-init |
| 6 | |
| 7 | generator client { |
| 8 | provider = "prisma-client-js" |
| 9 | previewFeatures = ["fullTextSearchPostgres", "omitApi" |
| 10 | } |
| 11 | |
| 12 | datasource db { |
| 13 | provider = "postgresql" |
| 14 | url = env( |
| 15 | } |
| 16 | |
| 17 | model User { |
| 18 | id String @id |
| 19 | name String |
| 20 | email String @unique |
| 21 | password String |
| 22 | |
| 23 | createdAt DateTime @default |
| 24 | updatedAt DateTime @updatedAt |
| 25 | flights Flight[] |
| 26 | bookings FlightBooking[] |
| 27 | |
| 28 | @@map("users") |
| 29 | } |
| 30 | |
| 31 | enum AirportType { |
| 32 | small_airport |
| 33 | seaplane_base |
| 34 | medium_airport |
| 35 | large_airport |
| 36 | heliport |
| 37 | closed |
| 38 | balloonport |
| 39 | } |
| 40 | |
| 41 | model Airport { |
| 42 | id String @id |
| 43 | ident String |
| 44 | type AirportType |
| 45 | elevation Decimal? |
| 46 | continent String |
| 47 | isoCountry String @map |
| 48 | isoRegion String @map |
| 49 | municipality String? |
| 50 | gpsCode String? @map |
| 51 | iataCode String? @map |
| 52 | name String |
| 53 | lat Decimal |
| 54 | long Decimal |
| 55 | |
| 56 | createdAt DateTime @default |
| 57 | updatedAt DateTime @updatedAt |
| 58 | |
| 59 | @@index([ident]) |
| 60 | @@index([municipality]) |
| 61 | @@index([gpsCode]) |
| 62 | @@index([iataCode]) |
| 63 | @@index([name]) |
| 64 | @@map("airports") |
| 65 | } |
| 66 | |
| 67 | model Airline { |
| 68 | id String @id |
| 69 | name String |
| 70 | icao String |
| 71 | iata String |
| 72 | |
| 73 | image String? |
| 74 | |
| 75 | createdAt DateTime @default |
| 76 | updatedAt DateTime @updatedAt |
| 77 | |
| 78 | @@index([name]) |
| 79 | @@index([icao]) |
| 80 | @@index([iata]) |
| 81 | @@map("airlines") |
| 82 | } |
| 83 | |
| 84 | model Aircraft { |
| 85 | id String @id |
| 86 | aircraft_id String |
| 87 | reg String |
| 88 | hexIcao String? @map |
| 89 | modelCode String? @map |
| 90 | age Decimal? |
| 91 | firstFlightDate DateTime? @map |
| 92 | deliveryDate DateTime? @map |
| 93 | typeName String? @map |
| 94 | isFreighter Boolean @map |
| 95 | image String? |
| 96 | attribution String? |
| 97 | registrations AircraftRegistration[] |
| 98 | |
| 99 | // store the whole json payload from api |
| 100 | payload Json? |
| 101 | |
| 102 | createdAt DateTime @default |
| 103 | updatedAt DateTime @updatedAt |
| 104 | |
| 105 | @@map("aircrafts") |
| 106 | } |
| 107 | |
| 108 | enum FlightType { |
| 109 | arrival |
| 110 | departure |
| 111 | } |
| 112 | |
| 113 | enum FlightStatus { |
| 114 | scheduled |
| 115 | active |
| 116 | landed |
| 117 | cancelled |
| 118 | incident |
| 119 | diverted |
| 120 | unknown |
| 121 | } |
| 122 | |
| 123 | model Flights { |
| 124 | id String @id |
| 125 | |
| 126 | date DateTime |
| 127 | airline Json |
| 128 | arrival Json |
| 129 | codeshared Json? |
| 130 | departure Json |
| 131 | flight Json |
| 132 | type FlightType |
| 133 | status FlightStatus? |
| 134 | |
| 135 | createdAt DateTime @default |
| 136 | updatedAt DateTime @updatedAt |
| 137 | |
| 138 | @@map("flights") |
| 139 | } |
| 140 | |
| 141 | enum AltitudeChange { |
| 142 | Climb |
| 143 | Descend |
| 144 | None |
| 145 | } |
| 146 | |
| 147 | enum UpdateType { |
| 148 | Projected |
| 149 | Oceanic |
| 150 | Radar |
| 151 | ADSB |
| 152 | Multilateration |
| 153 | Datalink |
| 154 | Surface_And_Near_Surface |
| 155 | Spaced_Based |
| 156 | Virtual_Event |
| 157 | } |
| 158 | |
| 159 | model FlightPositions { |
| 160 | id String @id |
| 161 | |
| 162 | altitude Int |
| 163 | altitudeChange AltitudeChange @default |
| 164 | |
| 165 | groundSpeed Int @map |
| 166 | heading Int? |
| 167 | latitude Decimal |
| 168 | longitude Decimal |
| 169 | timestamp DateTime |
| 170 | |
| 171 | updatedType UpdateType @map |
| 172 | |
| 173 | createdAt DateTime @default |
| 174 | updatedAt DateTime @updatedAt |
| 175 | |
| 176 | flight Flight? @relation |
| 177 | flightId String? @map |
| 178 | |
| 179 | @@index([timestamp]) |
| 180 | @@index([latitude, longitude] |
| 181 | @@index([altitude]) |
| 182 | @@index([altitudeChange]) |
| 183 | @@index([groundSpeed]) |
| 184 | @@index([heading]) |
| 185 | @@index([updatedType]) |
| 186 | @@map("flight_positions") |
| 187 | } |
| 188 | |
| 189 | model GreatCircleDistance { |
| 190 | id String @id |
| 191 | |
| 192 | meter Decimal |
| 193 | km Decimal |
| 194 | mile Decimal |
| 195 | nm Decimal |
| 196 | feet Decimal |
| 197 | |
| 198 | flight Flight @relation |
| 199 | flightId String @unique |
| 200 | |
| 201 | createdAt DateTime @default |
| 202 | updatedAt DateTime @updatedAt |
| 203 | |
| 204 | @@map("great_circle_distance") |
| 205 | } |
| 206 | |
| 207 | model Flight { |
| 208 | id String @id |
| 209 | |
| 210 | greatCircleDistance GreatCircleDistance? |
| 211 | flightAwareData FlightAwareData? |
| 212 | |
| 213 | flightNo String @map |
| 214 | aircraft Json |
| 215 | airline Json |
| 216 | arrival Json |
| 217 | departure Json |
| 218 | cargo Boolean @default |
| 219 | date DateTime |
| 220 | callSign String @map |
| 221 | |
| 222 | createdAt DateTime @default |
| 223 | updatedAt DateTime @updatedAt |
| 224 | FlightPositions FlightPositions[] |
| 225 | allFlightPositionsFetched Boolean @default |
| 226 | bookings FlightBooking[] |
| 227 | |
| 228 | user User @relation |
| 229 | userId String |
| 230 | |
| 231 | @@map("flight") |
| 232 | } |
| 233 | |
| 234 | enum SeatType { |
| 235 | window |
| 236 | middle |
| 237 | aisle |
| 238 | jumpseat |
| 239 | captain |
| 240 | pilot |
| 241 | copilot |
| 242 | flight_engineer |
| 243 | flight_attendant |
| 244 | observer |
| 245 | other |
| 246 | } |
| 247 | |
| 248 | enum SeatingClass { |
| 249 | economy |
| 250 | premium_economy |
| 251 | business |
| 252 | first |
| 253 | private |
| 254 | other |
| 255 | } |
| 256 | |
| 257 | enum BookingReason { |
| 258 | personal |
| 259 | business |
| 260 | crew |
| 261 | training |
| 262 | repositioning |
| 263 | other |
| 264 | } |
| 265 | |
| 266 | model FlightBooking { |
| 267 | id String @id |
| 268 | |
| 269 | /// Booking code/confirmation code (e.g., "ABC123") |
| 270 | bookingCode String? @map |
| 271 | |
| 272 | /// Seat number (e.g., "12A", "1F") |
| 273 | seatNumber String? @map |
| 274 | |
| 275 | /// Type of seat position |
| 276 | seatType SeatType? @map |
| 277 | |
| 278 | /// Class of service |
| 279 | seatingClass SeatingClass? @map |
| 280 | |
| 281 | /// Reason for the flight |
| 282 | reason BookingReason? |
| 283 | |
| 284 | /// Notes about the booking |
| 285 | notes String? |
| 286 | |
| 287 | flight Flight @relation |
| 288 | flightId String @map |
| 289 | |
| 290 | user User @relation |
| 291 | userId String @map |
| 292 | |
| 293 | createdAt DateTime @default |
| 294 | updatedAt DateTime @updatedAt |
| 295 | |
| 296 | @@index([flightId]) |
| 297 | @@index([userId]) |
| 298 | @@index([bookingCode]) |
| 299 | @@map("flight_bookings") |
| 300 | } |
| 301 | |
| 302 | model FlightAwareData { |
| 303 | id String @id |
| 304 | |
| 305 | /// FlightAware flight ID - unique identifier assigned by FlightAware |
| 306 | faFlightId String @map |
| 307 | |
| 308 | /// Flight identifier (operator code + flight number or aircraft registration) |
| 309 | ident String |
| 310 | |
| 311 | /// ICAO operator code + flight number |
| 312 | identIcao String? @map |
| 313 | |
| 314 | /// IATA operator code + flight number |
| 315 | identIata String? @map |
| 316 | |
| 317 | /// Actual departure runway at origin |
| 318 | actualRunwayOff String? @map |
| 319 | |
| 320 | /// Actual arrival runway at destination |
| 321 | actualRunwayOn String? @map |
| 322 | |
| 323 | /// ICAO code of the operator, otherwise the IATA code |
| 324 | operator String? |
| 325 | |
| 326 | /// ICAO code of the operator |
| 327 | operatorIcao String? @map |
| 328 | |
| 329 | /// IATA code of the operator |
| 330 | operatorIata String? @map |
| 331 | |
| 332 | /// Bare flight number |
| 333 | flightNumber String? @map |
| 334 | |
| 335 | /// Aircraft registration (tail number) |
| 336 | registration String? |
| 337 | |
| 338 | /// Ident for Air Traffic Control purposes |
| 339 | atcIdent String? @map |
| 340 | |
| 341 | /// Previous flight ID of the aircraft |
| 342 | inboundFaFlightId String? @map |
| 343 | |
| 344 | /// IATA codeshares |
| 345 | codesharesIata String[] @default |
| 346 | |
| 347 | /// ICAO codeshares |
| 348 | codesharesIcao String[] @default |
| 349 | |
| 350 | /// Departure delay in seconds (negative = early) |
| 351 | departureDelay Int? @map |
| 352 | |
| 353 | /// Arrival delay in seconds (negative = early) |
| 354 | arrivalDelay Int? @map |
| 355 | |
| 356 | /// Runway-to-runway filed duration in seconds |
| 357 | filedEte Int? @map |
| 358 | |
| 359 | /// Percent completion (0-100) |
| 360 | progressPercent Int? @map |
| 361 | |
| 362 | /// Flight status description |
| 363 | status String |
| 364 | |
| 365 | /// Aircraft type (ICAO or IATA code) |
| 366 | aircraftType String? @map |
| 367 | |
| 368 | /// Planned flight distance in statute miles |
| 369 | routeDistance Int? @map |
| 370 | |
| 371 | /// Filed IFR airspeed in knots |
| 372 | filedAirspeed Int? @map |
| 373 | |
| 374 | /// Filed IFR altitude in 100s of feet |
| 375 | filedAltitude Int? @map |
| 376 | |
| 377 | /// Flight route description |
| 378 | route String? |
| 379 | |
| 380 | /// Baggage claim location |
| 381 | baggageClaim String? @map |
| 382 | |
| 383 | /// Business class seats |
| 384 | seatsCabinBusiness Int? @map |
| 385 | |
| 386 | /// Coach class seats |
| 387 | seatsCabinCoach Int? @map |
| 388 | |
| 389 | /// First class seats |
| 390 | seatsCabinFirst Int? @map |
| 391 | |
| 392 | /// Departure gate |
| 393 | gateOrigin String? @map |
| 394 | |
| 395 | /// Arrival gate |
| 396 | gateDestination String? @map |
| 397 | |
| 398 | /// Departure terminal |
| 399 | terminalOrigin String? @map |
| 400 | |
| 401 | /// Arrival terminal |
| 402 | terminalDestination String? @map |
| 403 | |
| 404 | /// Scheduled gate departure |
| 405 | scheduledOut DateTime? @map |
| 406 | |
| 407 | /// Estimated gate departure |
| 408 | estimatedOut DateTime? @map |
| 409 | |
| 410 | /// Actual gate departure |
| 411 | actualOut DateTime? @map |
| 412 | |
| 413 | /// Scheduled runway departure |
| 414 | scheduledOff DateTime? @map |
| 415 | |
| 416 | /// Estimated runway departure |
| 417 | estimatedOff DateTime? @map |
| 418 | |
| 419 | /// Actual runway departure |
| 420 | actualOff DateTime? @map |
| 421 | |
| 422 | /// Scheduled runway arrival |
| 423 | scheduledOn DateTime? @map |
| 424 | |
| 425 | /// Estimated runway arrival |
| 426 | estimatedOn DateTime? @map |
| 427 | |
| 428 | /// Actual runway arrival |
| 429 | actualOn DateTime? @map |
| 430 | |
| 431 | /// Scheduled gate arrival |
| 432 | scheduledIn DateTime? @map |
| 433 | |
| 434 | /// Estimated gate arrival |
| 435 | estimatedIn DateTime? @map |
| 436 | |
| 437 | /// Actual gate arrival |
| 438 | actualIn DateTime? @map |
| 439 | |
| 440 | /// Foresight predictions available |
| 441 | foresightPredictionsAvailable Boolean @default |
| 442 | |
| 443 | /// Flight blocked from public viewing |
| 444 | blocked Boolean @default |
| 445 | |
| 446 | /// Flight diverted |
| 447 | diverted Boolean @default |
| 448 | |
| 449 | /// Flight cancelled by airline |
| 450 | cancelled Boolean @default |
| 451 | |
| 452 | /// Position-only flight (no flight plan) |
| 453 | positionOnly Boolean @default |
| 454 | |
| 455 | /// Origin airport code (ICAO/IATA/LID) |
| 456 | originCode String? @map |
| 457 | |
| 458 | /// Origin airport ICAO code |
| 459 | originCodeIcao String? @map |
| 460 | |
| 461 | /// Origin airport IATA code |
| 462 | originCodeIata String? @map |
| 463 | |
| 464 | /// Origin airport LID code |
| 465 | originCodeLid String? @map |
| 466 | |
| 467 | /// Origin airport timezone |
| 468 | originTimezone String? @map |
| 469 | |
| 470 | /// Origin airport name |
| 471 | originName String? @map |
| 472 | |
| 473 | /// Origin airport city |
| 474 | originCity String? @map |
| 475 | |
| 476 | /// Destination airport code (ICAO/IATA/LID) |
| 477 | destinationCode String? @map |
| 478 | |
| 479 | /// Destination airport ICAO code |
| 480 | destinationCodeIcao String? @map |
| 481 | |
| 482 | /// Destination airport IATA code |
| 483 | destinationCodeIata String? @map |
| 484 | |
| 485 | /// Destination airport LID code |
| 486 | destinationCodeLid String? @map |
| 487 | |
| 488 | /// Destination airport timezone |
| 489 | destinationTimezone String? @map |
| 490 | |
| 491 | /// Destination airport name |
| 492 | destinationName String? @map |
| 493 | |
| 494 | /// Destination airport city |
| 495 | destinationCity String? @map |
| 496 | |
| 497 | flight Flight @relation |
| 498 | flightId String @unique |
| 499 | |
| 500 | createdAt DateTime @default |
| 501 | updatedAt DateTime @updatedAt |
| 502 | |
| 503 | @@index([ident]) |
| 504 | @@index([faFlightId]) |
| 505 | @@index([registration]) |
| 506 | @@map("flight_aware_data") |
| 507 | } |
| 508 | |
| 509 | model AircraftRegistration { |
| 510 | id String @id |
| 511 | |
| 512 | reg String |
| 513 | active Boolean |
| 514 | hexIcao String? @map |
| 515 | airlineName String? @map |
| 516 | registrationDate DateTime? @map |
| 517 | |
| 518 | createdAt DateTime @default |
| 519 | updatedAt DateTime @updatedAt |
| 520 | |
| 521 | Aircraft Aircraft? @relation |
| 522 | aircraftId String? @map |
| 523 | |
| 524 | @@map("aircraft_registrations") |
| 525 | } |