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