| 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 | |
| 27 | @@map("users") |
| 28 | } |
| 29 | |
| 30 | enum AirportType { |
| 31 | small_airport |
| 32 | seaplane_base |
| 33 | medium_airport |
| 34 | large_airport |
| 35 | heliport |
| 36 | closed |
| 37 | balloonport |
| 38 | } |
| 39 | |
| 40 | model Airport { |
| 41 | id String @id |
| 42 | ident String |
| 43 | type AirportType |
| 44 | elevation Decimal? |
| 45 | continent String |
| 46 | isoCountry String @map |
| 47 | isoRegion String @map |
| 48 | municipality String? |
| 49 | gpsCode String? @map |
| 50 | iataCode String? @map |
| 51 | name String |
| 52 | lat Decimal |
| 53 | long Decimal |
| 54 | |
| 55 | createdAt DateTime @default |
| 56 | updatedAt DateTime @updatedAt |
| 57 | |
| 58 | @@index([ident]) |
| 59 | @@index([municipality]) |
| 60 | @@index([gpsCode]) |
| 61 | @@index([iataCode]) |
| 62 | @@index([name]) |
| 63 | @@map("airports") |
| 64 | } |
| 65 | |
| 66 | model Airline { |
| 67 | id String @id |
| 68 | name String |
| 69 | icao String |
| 70 | iata String |
| 71 | |
| 72 | image String? |
| 73 | |
| 74 | createdAt DateTime @default |
| 75 | updatedAt DateTime @updatedAt |
| 76 | |
| 77 | @@index([name]) |
| 78 | @@index([icao]) |
| 79 | @@index([iata]) |
| 80 | @@map("airlines") |
| 81 | } |
| 82 | |
| 83 | model Aircraft { |
| 84 | id String @id |
| 85 | aircraft_id String |
| 86 | reg String |
| 87 | hexIcao String? @map |
| 88 | modelCode String? @map |
| 89 | age Decimal? |
| 90 | firstFlightDate DateTime? @map |
| 91 | deliveryDate DateTime? @map |
| 92 | typeName String? @map |
| 93 | isFreighter Boolean @map |
| 94 | image String? |
| 95 | attribution String? |
| 96 | registrations AircraftRegistration[] |
| 97 | |
| 98 | // store the whole json payload from api |
| 99 | payload Json? |
| 100 | |
| 101 | createdAt DateTime @default |
| 102 | updatedAt DateTime @updatedAt |
| 103 | |
| 104 | @@map("aircrafts") |
| 105 | } |
| 106 | |
| 107 | enum FlightType { |
| 108 | arrival |
| 109 | departure |
| 110 | } |
| 111 | |
| 112 | enum FlightStatus { |
| 113 | scheduled |
| 114 | active |
| 115 | landed |
| 116 | cancelled |
| 117 | incident |
| 118 | diverted |
| 119 | unknown |
| 120 | } |
| 121 | |
| 122 | model Flights { |
| 123 | id String @id |
| 124 | |
| 125 | date DateTime |
| 126 | airline Json |
| 127 | arrival Json |
| 128 | codeshared Json? |
| 129 | departure Json |
| 130 | flight Json |
| 131 | type FlightType |
| 132 | status FlightStatus? |
| 133 | |
| 134 | createdAt DateTime @default |
| 135 | updatedAt DateTime @updatedAt |
| 136 | |
| 137 | @@map("flights") |
| 138 | } |
| 139 | |
| 140 | enum AltitudeChange { |
| 141 | Climb |
| 142 | Descend |
| 143 | None |
| 144 | } |
| 145 | |
| 146 | enum UpdateType { |
| 147 | Projected |
| 148 | Oceanic |
| 149 | Radar |
| 150 | ADSB |
| 151 | Multilateration |
| 152 | Datalink |
| 153 | Surface_And_Near_Surface |
| 154 | Spaced_Based |
| 155 | Virtual_Event |
| 156 | } |
| 157 | |
| 158 | model FlightPositions { |
| 159 | id String @id |
| 160 | |
| 161 | altitude Int |
| 162 | altitudeChange AltitudeChange @default |
| 163 | |
| 164 | groundSpeed Int @map |
| 165 | heading Int? |
| 166 | latitude Decimal |
| 167 | longitude Decimal |
| 168 | timestamp DateTime |
| 169 | |
| 170 | updatedType UpdateType @map |
| 171 | |
| 172 | createdAt DateTime @default |
| 173 | updatedAt DateTime @updatedAt |
| 174 | |
| 175 | flight Flight? @relation |
| 176 | flightId String? @map |
| 177 | |
| 178 | @@index([timestamp]) |
| 179 | @@index([latitude, longitude] |
| 180 | @@index([altitude]) |
| 181 | @@index([altitudeChange]) |
| 182 | @@index([groundSpeed]) |
| 183 | @@index([heading]) |
| 184 | @@index([updatedType]) |
| 185 | @@map("flight_positions") |
| 186 | } |
| 187 | |
| 188 | model GreatCircleDistance { |
| 189 | id String @id |
| 190 | |
| 191 | meter Decimal |
| 192 | km Decimal |
| 193 | mile Decimal |
| 194 | nm Decimal |
| 195 | feet Decimal |
| 196 | |
| 197 | flight Flight @relation |
| 198 | flightId String @unique |
| 199 | |
| 200 | createdAt DateTime @default |
| 201 | updatedAt DateTime @updatedAt |
| 202 | |
| 203 | @@map("great_circle_distance") |
| 204 | } |
| 205 | |
| 206 | model Flight { |
| 207 | id String @id |
| 208 | |
| 209 | greatCircleDistance GreatCircleDistance? |
| 210 | flightAwareData FlightAwareData? |
| 211 | |
| 212 | flightNo String @map |
| 213 | aircraft Json |
| 214 | airline Json |
| 215 | arrival Json |
| 216 | departure Json |
| 217 | cargo Boolean @default |
| 218 | date DateTime |
| 219 | callSign String @map |
| 220 | |
| 221 | createdAt DateTime @default |
| 222 | updatedAt DateTime @updatedAt |
| 223 | FlightPositions FlightPositions[] |
| 224 | |
| 225 | user User @relation |
| 226 | userId String |
| 227 | |
| 228 | @@map("flight") |
| 229 | } |
| 230 | |
| 231 | model FlightAwareData { |
| 232 | id String @id |
| 233 | |
| 234 | /// FlightAware flight ID - unique identifier assigned by FlightAware |
| 235 | faFlightId String @map |
| 236 | |
| 237 | /// Flight identifier (operator code + flight number or aircraft registration) |
| 238 | ident String |
| 239 | |
| 240 | /// ICAO operator code + flight number |
| 241 | identIcao String? @map |
| 242 | |
| 243 | /// IATA operator code + flight number |
| 244 | identIata String? @map |
| 245 | |
| 246 | /// Actual departure runway at origin |
| 247 | actualRunwayOff String? @map |
| 248 | |
| 249 | /// Actual arrival runway at destination |
| 250 | actualRunwayOn String? @map |
| 251 | |
| 252 | /// ICAO code of the operator, otherwise the IATA code |
| 253 | operator String? |
| 254 | |
| 255 | /// ICAO code of the operator |
| 256 | operatorIcao String? @map |
| 257 | |
| 258 | /// IATA code of the operator |
| 259 | operatorIata String? @map |
| 260 | |
| 261 | /// Bare flight number |
| 262 | flightNumber String? @map |
| 263 | |
| 264 | /// Aircraft registration (tail number) |
| 265 | registration String? |
| 266 | |
| 267 | /// Ident for Air Traffic Control purposes |
| 268 | atcIdent String? @map |
| 269 | |
| 270 | /// Previous flight ID of the aircraft |
| 271 | inboundFaFlightId String? @map |
| 272 | |
| 273 | /// IATA codeshares |
| 274 | codesharesIata String[] @map |
| 275 | |
| 276 | /// Departure delay in seconds (negative = early) |
| 277 | departureDelay Int? @map |
| 278 | |
| 279 | /// Arrival delay in seconds (negative = early) |
| 280 | arrivalDelay Int? @map |
| 281 | |
| 282 | /// Runway-to-runway filed duration in seconds |
| 283 | filedEte Int? @map |
| 284 | |
| 285 | /// Percent completion (0-100) |
| 286 | progressPercent Int? @map |
| 287 | |
| 288 | /// Flight status description |
| 289 | status String |
| 290 | |
| 291 | /// Aircraft type (ICAO or IATA code) |
| 292 | aircraftType String? @map |
| 293 | |
| 294 | /// Planned flight distance in statute miles |
| 295 | routeDistance Int? @map |
| 296 | |
| 297 | /// Filed IFR airspeed in knots |
| 298 | filedAirspeed Int? @map |
| 299 | |
| 300 | /// Filed IFR altitude in 100s of feet |
| 301 | filedAltitude Int? @map |
| 302 | |
| 303 | /// Flight route description |
| 304 | route String? |
| 305 | |
| 306 | /// Baggage claim location |
| 307 | baggageClaim String? @map |
| 308 | |
| 309 | /// Business class seats |
| 310 | seatsCabinBusiness Int? @map |
| 311 | |
| 312 | /// Coach class seats |
| 313 | seatsCabinCoach Int? @map |
| 314 | |
| 315 | /// First class seats |
| 316 | seatsCabinFirst Int? @map |
| 317 | |
| 318 | /// Departure gate |
| 319 | gateOrigin String? @map |
| 320 | |
| 321 | /// Arrival gate |
| 322 | gateDestination String? @map |
| 323 | |
| 324 | /// Departure terminal |
| 325 | terminalOrigin String? @map |
| 326 | |
| 327 | /// Arrival terminal |
| 328 | terminalDestination String? @map |
| 329 | |
| 330 | /// Scheduled gate departure |
| 331 | scheduledOut DateTime? @map |
| 332 | |
| 333 | /// Estimated gate departure |
| 334 | estimatedOut DateTime? @map |
| 335 | |
| 336 | /// Actual gate departure |
| 337 | actualOut DateTime? @map |
| 338 | |
| 339 | /// Scheduled runway departure |
| 340 | scheduledOff DateTime? @map |
| 341 | |
| 342 | /// Estimated runway departure |
| 343 | estimatedOff DateTime? @map |
| 344 | |
| 345 | /// Actual runway departure |
| 346 | actualOff DateTime? @map |
| 347 | |
| 348 | /// Scheduled runway arrival |
| 349 | scheduledOn DateTime? @map |
| 350 | |
| 351 | /// Estimated runway arrival |
| 352 | estimatedOn DateTime? @map |
| 353 | |
| 354 | /// Actual runway arrival |
| 355 | actualOn DateTime? @map |
| 356 | |
| 357 | /// Scheduled gate arrival |
| 358 | scheduledIn DateTime? @map |
| 359 | |
| 360 | /// Estimated gate arrival |
| 361 | estimatedIn DateTime? @map |
| 362 | |
| 363 | /// Actual gate arrival |
| 364 | actualIn DateTime? @map |
| 365 | |
| 366 | /// Foresight predictions available |
| 367 | foresightPredictionsAvailable Boolean @default |
| 368 | |
| 369 | /// Flight blocked from public viewing |
| 370 | blocked Boolean @default |
| 371 | |
| 372 | /// Flight diverted |
| 373 | diverted Boolean @default |
| 374 | |
| 375 | /// Flight cancelled by airline |
| 376 | cancelled Boolean @default |
| 377 | |
| 378 | /// Position-only flight (no flight plan) |
| 379 | positionOnly Boolean @default |
| 380 | |
| 381 | /// Origin airport code (ICAO/IATA/LID) |
| 382 | originCode String? @map |
| 383 | |
| 384 | /// Origin airport ICAO code |
| 385 | originCodeIcao String? @map |
| 386 | |
| 387 | /// Origin airport IATA code |
| 388 | originCodeIata String? @map |
| 389 | |
| 390 | /// Origin airport LID code |
| 391 | originCodeLid String? @map |
| 392 | |
| 393 | /// Origin airport timezone |
| 394 | originTimezone String? @map |
| 395 | |
| 396 | /// Origin airport name |
| 397 | originName String? @map |
| 398 | |
| 399 | /// Origin airport city |
| 400 | originCity String? @map |
| 401 | |
| 402 | /// Destination airport code (ICAO/IATA/LID) |
| 403 | destinationCode String? @map |
| 404 | |
| 405 | /// Destination airport ICAO code |
| 406 | destinationCodeIcao String? @map |
| 407 | |
| 408 | /// Destination airport IATA code |
| 409 | destinationCodeIata String? @map |
| 410 | |
| 411 | /// Destination airport LID code |
| 412 | destinationCodeLid String? @map |
| 413 | |
| 414 | /// Destination airport timezone |
| 415 | destinationTimezone String? @map |
| 416 | |
| 417 | /// Destination airport name |
| 418 | destinationName String? @map |
| 419 | |
| 420 | /// Destination airport city |
| 421 | destinationCity String? @map |
| 422 | |
| 423 | flight Flight @relation |
| 424 | flightId String @unique |
| 425 | |
| 426 | createdAt DateTime @default |
| 427 | updatedAt DateTime @updatedAt |
| 428 | |
| 429 | @@index([ident]) |
| 430 | @@index([faFlightId]) |
| 431 | @@index([registration]) |
| 432 | @@map("flight_aware_data") |
| 433 | } |
| 434 | |
| 435 | model AircraftRegistration { |
| 436 | id String @id |
| 437 | |
| 438 | reg String |
| 439 | active Boolean |
| 440 | hexIcao String? @map |
| 441 | airlineName String? @map |
| 442 | registrationDate DateTime? @map |
| 443 | |
| 444 | createdAt DateTime @default |
| 445 | updatedAt DateTime @updatedAt |
| 446 | |
| 447 | Aircraft Aircraft? @relation |
| 448 | aircraftId String? @map |
| 449 | |
| 450 | @@map("aircraft_registrations") |
| 451 | } |