chore: move to postgres and another flight fetching approach

This commit is contained in:
2025-08-07 21:45:43 +00:00
parent a23660376f
commit b389415447
16 changed files with 163 additions and 440 deletions

View File

@@ -1,55 +0,0 @@
-- CreateTable
CREATE TABLE "Flight" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"faFlightId" TEXT NOT NULL,
"ident" TEXT NOT NULL,
"identIcao" TEXT NOT NULL,
"identIata" TEXT,
"registration" TEXT,
"aircraftType" TEXT,
"originCode" TEXT NOT NULL,
"originIata" TEXT NOT NULL,
"originName" TEXT NOT NULL,
"originCity" TEXT NOT NULL,
"destinationCode" TEXT NOT NULL,
"destinationIata" TEXT NOT NULL,
"destinationName" TEXT NOT NULL,
"destinationCity" TEXT NOT NULL,
"scheduledOut" DATETIME NOT NULL,
"scheduledOff" DATETIME NOT NULL,
"scheduledOn" DATETIME NOT NULL,
"scheduledIn" DATETIME NOT NULL,
"estimatedOut" DATETIME,
"estimatedOff" DATETIME,
"estimatedOn" DATETIME,
"estimatedIn" DATETIME,
"actualOut" DATETIME,
"actualOff" DATETIME,
"actualOn" DATETIME,
"actualIn" DATETIME,
"status" TEXT NOT NULL,
"departureDelay" INTEGER,
"arrivalDelay" INTEGER,
"cancelled" BOOLEAN NOT NULL DEFAULT false,
"diverted" BOOLEAN NOT NULL DEFAULT false,
"progressPercent" INTEGER,
"gateOrigin" TEXT,
"gateDestination" TEXT,
"terminalOrigin" TEXT,
"terminalDestination" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
-- CreateIndex
CREATE UNIQUE INDEX "Flight_faFlightId_key" ON "Flight"("faFlightId");
-- CreateIndex
CREATE INDEX "Flight_userId_idx" ON "Flight"("userId");
-- CreateIndex
CREATE INDEX "Flight_faFlightId_idx" ON "Flight"("faFlightId");
-- CreateIndex
CREATE INDEX "Flight_scheduledOff_idx" ON "Flight"("scheduledOff");

View File

@@ -1,63 +0,0 @@
/*
Warnings:
- You are about to drop the column `destinationCode` on the `Flight` table. All the data in the column will be lost.
- You are about to drop the column `originCode` on the `Flight` table. All the data in the column will be lost.
- Added the required column `destinationIcao` to the `Flight` table without a default value. This is not possible if the table is not empty.
- Added the required column `originIcao` to the `Flight` table without a default value. This is not possible if the table is not empty.
*/
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Flight" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"faFlightId" TEXT NOT NULL,
"ident" TEXT NOT NULL,
"identIcao" TEXT NOT NULL,
"identIata" TEXT,
"registration" TEXT,
"aircraftType" TEXT,
"originIcao" TEXT NOT NULL,
"originIata" TEXT NOT NULL,
"originName" TEXT NOT NULL,
"originCity" TEXT NOT NULL,
"destinationIcao" TEXT NOT NULL,
"destinationIata" TEXT NOT NULL,
"destinationName" TEXT NOT NULL,
"destinationCity" TEXT NOT NULL,
"scheduledOut" DATETIME NOT NULL,
"scheduledOff" DATETIME NOT NULL,
"scheduledOn" DATETIME NOT NULL,
"scheduledIn" DATETIME NOT NULL,
"estimatedOut" DATETIME,
"estimatedOff" DATETIME,
"estimatedOn" DATETIME,
"estimatedIn" DATETIME,
"actualOut" DATETIME,
"actualOff" DATETIME,
"actualOn" DATETIME,
"actualIn" DATETIME,
"status" TEXT NOT NULL,
"departureDelay" INTEGER,
"arrivalDelay" INTEGER,
"cancelled" BOOLEAN NOT NULL DEFAULT false,
"diverted" BOOLEAN NOT NULL DEFAULT false,
"progressPercent" INTEGER,
"gateOrigin" TEXT,
"gateDestination" TEXT,
"terminalOrigin" TEXT,
"terminalDestination" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
INSERT INTO "new_Flight" ("actualIn", "actualOff", "actualOn", "actualOut", "aircraftType", "arrivalDelay", "cancelled", "createdAt", "departureDelay", "destinationCity", "destinationIata", "destinationName", "diverted", "estimatedIn", "estimatedOff", "estimatedOn", "estimatedOut", "faFlightId", "gateDestination", "gateOrigin", "id", "ident", "identIata", "identIcao", "originCity", "originIata", "originName", "progressPercent", "registration", "scheduledIn", "scheduledOff", "scheduledOn", "scheduledOut", "status", "terminalDestination", "terminalOrigin", "updatedAt", "userId") SELECT "actualIn", "actualOff", "actualOn", "actualOut", "aircraftType", "arrivalDelay", "cancelled", "createdAt", "departureDelay", "destinationCity", "destinationIata", "destinationName", "diverted", "estimatedIn", "estimatedOff", "estimatedOn", "estimatedOut", "faFlightId", "gateDestination", "gateOrigin", "id", "ident", "identIata", "identIcao", "originCity", "originIata", "originName", "progressPercent", "registration", "scheduledIn", "scheduledOff", "scheduledOn", "scheduledOut", "status", "terminalDestination", "terminalOrigin", "updatedAt", "userId" FROM "Flight";
DROP TABLE "Flight";
ALTER TABLE "new_Flight" RENAME TO "Flight";
CREATE UNIQUE INDEX "Flight_faFlightId_key" ON "Flight"("faFlightId");
CREATE INDEX "Flight_userId_idx" ON "Flight"("userId");
CREATE INDEX "Flight_faFlightId_idx" ON "Flight"("faFlightId");
CREATE INDEX "Flight_scheduledOff_idx" ON "Flight"("scheduledOff");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

View File

@@ -1,61 +0,0 @@
/*
Warnings:
- Added the required column `channelId` to the `Flight` table without a default value. This is not possible if the table is not empty.
*/
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Flight" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"channelId" TEXT NOT NULL,
"faFlightId" TEXT NOT NULL,
"ident" TEXT NOT NULL,
"identIcao" TEXT NOT NULL,
"identIata" TEXT,
"registration" TEXT,
"aircraftType" TEXT,
"originIcao" TEXT NOT NULL,
"originIata" TEXT NOT NULL,
"originName" TEXT NOT NULL,
"originCity" TEXT NOT NULL,
"destinationIcao" TEXT NOT NULL,
"destinationIata" TEXT NOT NULL,
"destinationName" TEXT NOT NULL,
"destinationCity" TEXT NOT NULL,
"scheduledOut" DATETIME NOT NULL,
"scheduledOff" DATETIME NOT NULL,
"scheduledOn" DATETIME NOT NULL,
"scheduledIn" DATETIME NOT NULL,
"estimatedOut" DATETIME,
"estimatedOff" DATETIME,
"estimatedOn" DATETIME,
"estimatedIn" DATETIME,
"actualOut" DATETIME,
"actualOff" DATETIME,
"actualOn" DATETIME,
"actualIn" DATETIME,
"status" TEXT NOT NULL,
"departureDelay" INTEGER,
"arrivalDelay" INTEGER,
"cancelled" BOOLEAN NOT NULL DEFAULT false,
"diverted" BOOLEAN NOT NULL DEFAULT false,
"progressPercent" INTEGER,
"gateOrigin" TEXT,
"gateDestination" TEXT,
"terminalOrigin" TEXT,
"terminalDestination" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
INSERT INTO "new_Flight" ("actualIn", "actualOff", "actualOn", "actualOut", "aircraftType", "arrivalDelay", "cancelled", "createdAt", "departureDelay", "destinationCity", "destinationIata", "destinationIcao", "destinationName", "diverted", "estimatedIn", "estimatedOff", "estimatedOn", "estimatedOut", "faFlightId", "gateDestination", "gateOrigin", "id", "ident", "identIata", "identIcao", "originCity", "originIata", "originIcao", "originName", "progressPercent", "registration", "scheduledIn", "scheduledOff", "scheduledOn", "scheduledOut", "status", "terminalDestination", "terminalOrigin", "updatedAt", "userId") SELECT "actualIn", "actualOff", "actualOn", "actualOut", "aircraftType", "arrivalDelay", "cancelled", "createdAt", "departureDelay", "destinationCity", "destinationIata", "destinationIcao", "destinationName", "diverted", "estimatedIn", "estimatedOff", "estimatedOn", "estimatedOut", "faFlightId", "gateDestination", "gateOrigin", "id", "ident", "identIata", "identIcao", "originCity", "originIata", "originIcao", "originName", "progressPercent", "registration", "scheduledIn", "scheduledOff", "scheduledOn", "scheduledOut", "status", "terminalDestination", "terminalOrigin", "updatedAt", "userId" FROM "Flight";
DROP TABLE "Flight";
ALTER TABLE "new_Flight" RENAME TO "Flight";
CREATE UNIQUE INDEX "Flight_faFlightId_key" ON "Flight"("faFlightId");
CREATE INDEX "Flight_userId_idx" ON "Flight"("userId");
CREATE INDEX "Flight_faFlightId_idx" ON "Flight"("faFlightId");
CREATE INDEX "Flight_scheduledOff_idx" ON "Flight"("scheduledOff");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

View File

@@ -1,55 +0,0 @@
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Flight" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"channelId" TEXT NOT NULL,
"faFlightId" TEXT NOT NULL,
"ident" TEXT NOT NULL,
"identIcao" TEXT NOT NULL,
"identIata" TEXT,
"registration" TEXT,
"aircraftType" TEXT,
"originIcao" TEXT NOT NULL,
"originIata" TEXT NOT NULL,
"originName" TEXT NOT NULL,
"originCity" TEXT NOT NULL,
"destinationIcao" TEXT NOT NULL,
"destinationIata" TEXT NOT NULL,
"destinationName" TEXT NOT NULL,
"destinationCity" TEXT NOT NULL,
"scheduledOut" DATETIME,
"scheduledOff" DATETIME NOT NULL,
"scheduledOn" DATETIME NOT NULL,
"scheduledIn" DATETIME NOT NULL,
"estimatedOut" DATETIME,
"estimatedOff" DATETIME,
"estimatedOn" DATETIME,
"estimatedIn" DATETIME,
"actualOut" DATETIME,
"actualOff" DATETIME,
"actualOn" DATETIME,
"actualIn" DATETIME,
"status" TEXT NOT NULL,
"departureDelay" INTEGER,
"arrivalDelay" INTEGER,
"cancelled" BOOLEAN NOT NULL DEFAULT false,
"diverted" BOOLEAN NOT NULL DEFAULT false,
"progressPercent" INTEGER,
"gateOrigin" TEXT,
"gateDestination" TEXT,
"terminalOrigin" TEXT,
"terminalDestination" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
INSERT INTO "new_Flight" ("actualIn", "actualOff", "actualOn", "actualOut", "aircraftType", "arrivalDelay", "cancelled", "channelId", "createdAt", "departureDelay", "destinationCity", "destinationIata", "destinationIcao", "destinationName", "diverted", "estimatedIn", "estimatedOff", "estimatedOn", "estimatedOut", "faFlightId", "gateDestination", "gateOrigin", "id", "ident", "identIata", "identIcao", "originCity", "originIata", "originIcao", "originName", "progressPercent", "registration", "scheduledIn", "scheduledOff", "scheduledOn", "scheduledOut", "status", "terminalDestination", "terminalOrigin", "updatedAt", "userId") SELECT "actualIn", "actualOff", "actualOn", "actualOut", "aircraftType", "arrivalDelay", "cancelled", "channelId", "createdAt", "departureDelay", "destinationCity", "destinationIata", "destinationIcao", "destinationName", "diverted", "estimatedIn", "estimatedOff", "estimatedOn", "estimatedOut", "faFlightId", "gateDestination", "gateOrigin", "id", "ident", "identIata", "identIcao", "originCity", "originIata", "originIcao", "originName", "progressPercent", "registration", "scheduledIn", "scheduledOff", "scheduledOn", "scheduledOut", "status", "terminalDestination", "terminalOrigin", "updatedAt", "userId" FROM "Flight";
DROP TABLE "Flight";
ALTER TABLE "new_Flight" RENAME TO "Flight";
CREATE UNIQUE INDEX "Flight_faFlightId_key" ON "Flight"("faFlightId");
CREATE INDEX "Flight_userId_idx" ON "Flight"("userId");
CREATE INDEX "Flight_faFlightId_idx" ON "Flight"("faFlightId");
CREATE INDEX "Flight_scheduledOff_idx" ON "Flight"("scheduledOff");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

View File

@@ -1,55 +0,0 @@
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Flight" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"channelId" TEXT NOT NULL,
"faFlightId" TEXT NOT NULL,
"ident" TEXT NOT NULL,
"identIcao" TEXT NOT NULL,
"identIata" TEXT,
"registration" TEXT,
"aircraftType" TEXT,
"originIcao" TEXT NOT NULL,
"originIata" TEXT NOT NULL,
"originName" TEXT NOT NULL,
"originCity" TEXT NOT NULL,
"destinationIcao" TEXT NOT NULL,
"destinationIata" TEXT NOT NULL,
"destinationName" TEXT NOT NULL,
"destinationCity" TEXT NOT NULL,
"scheduledOut" DATETIME,
"scheduledOff" DATETIME NOT NULL,
"scheduledOn" DATETIME NOT NULL,
"scheduledIn" DATETIME,
"estimatedOut" DATETIME,
"estimatedOff" DATETIME,
"estimatedOn" DATETIME,
"estimatedIn" DATETIME,
"actualOut" DATETIME,
"actualOff" DATETIME,
"actualOn" DATETIME,
"actualIn" DATETIME,
"status" TEXT NOT NULL,
"departureDelay" INTEGER,
"arrivalDelay" INTEGER,
"cancelled" BOOLEAN NOT NULL DEFAULT false,
"diverted" BOOLEAN NOT NULL DEFAULT false,
"progressPercent" INTEGER,
"gateOrigin" TEXT,
"gateDestination" TEXT,
"terminalOrigin" TEXT,
"terminalDestination" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
INSERT INTO "new_Flight" ("actualIn", "actualOff", "actualOn", "actualOut", "aircraftType", "arrivalDelay", "cancelled", "channelId", "createdAt", "departureDelay", "destinationCity", "destinationIata", "destinationIcao", "destinationName", "diverted", "estimatedIn", "estimatedOff", "estimatedOn", "estimatedOut", "faFlightId", "gateDestination", "gateOrigin", "id", "ident", "identIata", "identIcao", "originCity", "originIata", "originIcao", "originName", "progressPercent", "registration", "scheduledIn", "scheduledOff", "scheduledOn", "scheduledOut", "status", "terminalDestination", "terminalOrigin", "updatedAt", "userId") SELECT "actualIn", "actualOff", "actualOn", "actualOut", "aircraftType", "arrivalDelay", "cancelled", "channelId", "createdAt", "departureDelay", "destinationCity", "destinationIata", "destinationIcao", "destinationName", "diverted", "estimatedIn", "estimatedOff", "estimatedOn", "estimatedOut", "faFlightId", "gateDestination", "gateOrigin", "id", "ident", "identIata", "identIcao", "originCity", "originIata", "originIcao", "originName", "progressPercent", "registration", "scheduledIn", "scheduledOff", "scheduledOn", "scheduledOut", "status", "terminalDestination", "terminalOrigin", "updatedAt", "userId" FROM "Flight";
DROP TABLE "Flight";
ALTER TABLE "new_Flight" RENAME TO "Flight";
CREATE UNIQUE INDEX "Flight_faFlightId_key" ON "Flight"("faFlightId");
CREATE INDEX "Flight_userId_idx" ON "Flight"("userId");
CREATE INDEX "Flight_faFlightId_idx" ON "Flight"("faFlightId");
CREATE INDEX "Flight_scheduledOff_idx" ON "Flight"("scheduledOff");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

View File

@@ -1,6 +0,0 @@
-- CreateTable
CREATE TABLE "ASAccount" (
"email" TEXT NOT NULL PRIMARY KEY,
"password" TEXT NOT NULL,
"key" TEXT NOT NULL
);

View File

@@ -1,20 +0,0 @@
/*
Warnings:
- You are about to drop the `ASAccount` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropTable
PRAGMA foreign_keys=off;
DROP TABLE "ASAccount";
PRAGMA foreign_keys=on;
-- CreateTable
CREATE TABLE "AsAccount" (
"email" TEXT NOT NULL PRIMARY KEY,
"password" TEXT NOT NULL,
"key" TEXT NOT NULL,
"usage" INTEGER NOT NULL DEFAULT 0,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);

View File

@@ -1,8 +0,0 @@
/*
Warnings:
- A unique constraint covering the columns `[email]` on the table `AsAccount` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "AsAccount_email_key" ON "AsAccount"("email");

View File

@@ -1,2 +0,0 @@
-- AlterTable
ALTER TABLE "AsAccount" ADD COLUMN "lastResetDate" DATETIME;

View File

@@ -1,63 +0,0 @@
/*
Warnings:
- Added the required column `mortalsId` to the `Flight` table without a default value. This is not possible if the table is not empty.
*/
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Flight" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"channelId" TEXT NOT NULL,
"faFlightId" TEXT NOT NULL,
"mortalsId" INTEGER NOT NULL,
"ident" TEXT NOT NULL,
"identIcao" TEXT NOT NULL,
"identIata" TEXT,
"registration" TEXT,
"aircraftType" TEXT,
"originIcao" TEXT NOT NULL,
"originIata" TEXT NOT NULL,
"originName" TEXT NOT NULL,
"originCity" TEXT NOT NULL,
"destinationIcao" TEXT NOT NULL,
"destinationIata" TEXT NOT NULL,
"destinationName" TEXT NOT NULL,
"destinationCity" TEXT NOT NULL,
"scheduledOut" DATETIME,
"scheduledOff" DATETIME NOT NULL,
"scheduledOn" DATETIME NOT NULL,
"scheduledIn" DATETIME,
"estimatedOut" DATETIME,
"estimatedOff" DATETIME,
"estimatedOn" DATETIME,
"estimatedIn" DATETIME,
"actualOut" DATETIME,
"actualOff" DATETIME,
"actualOn" DATETIME,
"actualIn" DATETIME,
"status" TEXT NOT NULL,
"departureDelay" INTEGER,
"arrivalDelay" INTEGER,
"cancelled" BOOLEAN NOT NULL DEFAULT false,
"diverted" BOOLEAN NOT NULL DEFAULT false,
"progressPercent" INTEGER,
"gateOrigin" TEXT,
"gateDestination" TEXT,
"terminalOrigin" TEXT,
"terminalDestination" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
INSERT INTO "new_Flight" ("actualIn", "actualOff", "actualOn", "actualOut", "aircraftType", "arrivalDelay", "cancelled", "channelId", "createdAt", "departureDelay", "destinationCity", "destinationIata", "destinationIcao", "destinationName", "diverted", "estimatedIn", "estimatedOff", "estimatedOn", "estimatedOut", "faFlightId", "gateDestination", "gateOrigin", "id", "ident", "identIata", "identIcao", "originCity", "originIata", "originIcao", "originName", "progressPercent", "registration", "scheduledIn", "scheduledOff", "scheduledOn", "scheduledOut", "status", "terminalDestination", "terminalOrigin", "updatedAt", "userId") SELECT "actualIn", "actualOff", "actualOn", "actualOut", "aircraftType", "arrivalDelay", "cancelled", "channelId", "createdAt", "departureDelay", "destinationCity", "destinationIata", "destinationIcao", "destinationName", "diverted", "estimatedIn", "estimatedOff", "estimatedOn", "estimatedOut", "faFlightId", "gateDestination", "gateOrigin", "id", "ident", "identIata", "identIcao", "originCity", "originIata", "originIcao", "originName", "progressPercent", "registration", "scheduledIn", "scheduledOff", "scheduledOn", "scheduledOut", "status", "terminalDestination", "terminalOrigin", "updatedAt", "userId" FROM "Flight";
DROP TABLE "Flight";
ALTER TABLE "new_Flight" RENAME TO "Flight";
CREATE UNIQUE INDEX "Flight_faFlightId_key" ON "Flight"("faFlightId");
CREATE UNIQUE INDEX "Flight_mortalsId_key" ON "Flight"("mortalsId");
CREATE INDEX "Flight_userId_idx" ON "Flight"("userId");
CREATE INDEX "Flight_faFlightId_idx" ON "Flight"("faFlightId");
CREATE INDEX "Flight_scheduledOff_idx" ON "Flight"("scheduledOff");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

View File

@@ -1,9 +0,0 @@
-- CreateTable
CREATE TABLE "Invite" (
"id" TEXT NOT NULL PRIMARY KEY,
"slackId" TEXT NOT NULL,
"invitedBy" TEXT NOT NULL
);
-- CreateIndex
CREATE UNIQUE INDEX "Invite_slackId_key" ON "Invite"("slackId");

View File

@@ -0,0 +1,92 @@
-- CreateTable
CREATE TABLE "public"."Flight" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"channelId" TEXT NOT NULL,
"faFlightId" TEXT NOT NULL,
"mortalsId" INTEGER NOT NULL,
"ident" TEXT NOT NULL,
"identIcao" TEXT NOT NULL,
"identIata" TEXT,
"registration" TEXT,
"aircraftType" TEXT,
"originIcao" TEXT NOT NULL,
"originIata" TEXT NOT NULL,
"originName" TEXT NOT NULL,
"originCity" TEXT NOT NULL,
"originTimezone" TEXT NOT NULL,
"destinationIcao" TEXT NOT NULL,
"destinationIata" TEXT NOT NULL,
"destinationName" TEXT NOT NULL,
"destinationCity" TEXT NOT NULL,
"destinationTimezone" TEXT NOT NULL,
"scheduledOut" TIMESTAMP(3),
"scheduledOff" TIMESTAMP(3) NOT NULL,
"scheduledOn" TIMESTAMP(3) NOT NULL,
"scheduledIn" TIMESTAMP(3),
"estimatedOut" TIMESTAMP(3),
"estimatedOff" TIMESTAMP(3),
"estimatedOn" TIMESTAMP(3),
"estimatedIn" TIMESTAMP(3),
"actualOut" TIMESTAMP(3),
"actualOff" TIMESTAMP(3),
"actualOn" TIMESTAMP(3),
"actualIn" TIMESTAMP(3),
"status" TEXT NOT NULL,
"departureDelay" INTEGER,
"arrivalDelay" INTEGER,
"cancelled" BOOLEAN NOT NULL DEFAULT false,
"diverted" BOOLEAN NOT NULL DEFAULT false,
"progressPercent" INTEGER,
"gateOrigin" TEXT,
"gateDestination" TEXT,
"terminalOrigin" TEXT,
"terminalDestination" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Flight_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "public"."AsAccount" (
"email" TEXT NOT NULL,
"password" TEXT NOT NULL,
"key" TEXT NOT NULL,
"usage" INTEGER NOT NULL DEFAULT 0,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"lastResetDate" TIMESTAMP(3),
CONSTRAINT "AsAccount_pkey" PRIMARY KEY ("email")
);
-- CreateTable
CREATE TABLE "public"."Invite" (
"id" TEXT NOT NULL,
"slackId" TEXT NOT NULL,
"invitedBy" TEXT NOT NULL,
CONSTRAINT "Invite_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "Flight_faFlightId_key" ON "public"."Flight"("faFlightId");
-- CreateIndex
CREATE UNIQUE INDEX "Flight_mortalsId_key" ON "public"."Flight"("mortalsId");
-- CreateIndex
CREATE INDEX "Flight_userId_idx" ON "public"."Flight"("userId");
-- CreateIndex
CREATE INDEX "Flight_faFlightId_idx" ON "public"."Flight"("faFlightId");
-- CreateIndex
CREATE INDEX "Flight_scheduledOff_idx" ON "public"."Flight"("scheduledOff");
-- CreateIndex
CREATE UNIQUE INDEX "AsAccount_email_key" ON "public"."AsAccount"("email");
-- CreateIndex
CREATE UNIQUE INDEX "Invite_slackId_key" ON "public"."Invite"("slackId");

View File

@@ -1,3 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "sqlite"
provider = "postgresql"

View File

@@ -6,7 +6,7 @@ generator client {
}
datasource db {
provider = "sqlite"
provider = "postgresql"
url = env("DATABASE_URL")
}
@@ -31,11 +31,13 @@ model Flight {
originIata String // iata code (agp)
originName String // airport name
originCity String // city name
originTimezone String // string timezone "region/capital"
destinationIcao String // icao code
destinationIata String // iata code
destinationName String // airport name
destinationCity String // city name
destinationTimezone String // string timezone "region/capital"
// timing (stored in iso 8601 format on the api)
scheduledOut DateTime?

View File

@@ -315,10 +315,12 @@ app.action('flight_selection', async ({ body, ack, respond }) => {
originIata: flightData.origin.code_iata,
originName: flightData.origin.name,
originCity: flightData.origin.city,
originTimezone: flightData.origin.timezone,
destinationIcao: flightData.destination.code_icao,
destinationIata: flightData.destination.code_iata,
destinationName: flightData.destination.name,
destinationCity: flightData.destination.city,
destinationTimezone: flightData.destination.timezone,
scheduledOut: flightData.scheduled_out,
scheduledOff: flightData.scheduled_off,
scheduledOn: flightData.scheduled_on,

View File

@@ -7,9 +7,9 @@ export class FlightUpdater {
public start() {
if (this.updateInterval) return;
console.log('flight updater starting');
this.updateInterval = setInterval(() => this.manageFlightPolling(), 10 * 60 * 1000);
this.manageFlightPolling();
}
@@ -19,8 +19,8 @@ export class FlightUpdater {
clearInterval(this.updateInterval);
this.updateInterval = null;
}
this.flightIntervals.forEach(interval => clearInterval(interval));
this.flightIntervals.forEach((interval) => clearInterval(interval));
this.flightIntervals.clear();
}
@@ -30,15 +30,27 @@ export class FlightUpdater {
where: {
actualIn: null,
cancelled: false,
scheduledOff: {
gte: new Date(Date.now() - 4 * 60 * 60 * 1000),
lte: new Date(Date.now() + 24 * 60 * 60 * 1000),
}
}
OR: [
{
AND: [
{ actualOff: null },
{
scheduledOff: {
gte: new Date(Date.now() - 4 * 60 * 60 * 1000).toISOString(),
lte: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
},
},
],
},
{
AND: [{ actualOff: { not: null } }, { actualOn: null }],
},
],
},
});
const currentlyTracked = new Set(this.flightIntervals.keys());
const activeFlightIds = new Set(flights.map(f => f.id));
const activeFlightIds = new Set(flights.map((f) => f.id));
// remove intervals for flights no longer active
for (const flightId of currentlyTracked) {
@@ -64,12 +76,14 @@ export class FlightUpdater {
private setupFlightPolling(flight: Flight) {
const pollInterval = this.calculatePollInterval(flight);
console.log(`Setting up polling for flight ${flight.ident} every ${pollInterval / 60000} minutes`);
console.log(
`Setting up polling for flight ${flight.ident} every ${pollInterval / 60000} minutes`
);
// initial update
this.updateSingleFlight(flight);
// set up interval
const interval = setInterval(() => this.updateSingleFlightById(flight.id), pollInterval);
this.flightIntervals.set(flight.id, interval);
@@ -130,14 +144,14 @@ export class FlightUpdater {
private async updateSingleFlightById(flightId: string) {
try {
const flight = await db.flight.findUnique({
where: { id: flightId }
where: { id: flightId },
});
if (!flight) {
this.removeFlightPolling(flightId);
return;
}
await this.updateSingleFlight(flight);
} catch (error) {
console.error(`Error fetching flight ${flightId}:`, error);
@@ -148,9 +162,9 @@ export class FlightUpdater {
console.log(`updating flight ${flight.ident} (${flight.id})`);
try {
const currentFlight = await db.flight.findUnique({
where: { id: flight.id }
where: { id: flight.id },
});
if (!currentFlight || currentFlight.actualIn) {
this.removeFlightPolling(flight.id);
return;
@@ -158,53 +172,61 @@ export class FlightUpdater {
const flightInfo = await flightAware.getFlightInfo(currentFlight.faFlightId);
const newData = flightInfo.flights[0];
if (!newData) return;
const changes = [];
if (currentFlight.status !== newData.status) {
changes.push(`Status: ${newData.status}`);
}
if (Math.abs((currentFlight.departureDelay || 0) - (newData.departure_delay || 0)) > 10) {
changes.push(`Departure delay: ${newData.departure_delay || 0} minutes`);
}
if (currentFlight.gateOrigin !== newData.gate_origin && newData.gate_origin) {
changes.push(`Gate changed to: ${newData.gate_origin}`);
}
if (!currentFlight.actualOff && newData.actual_off) {
changes.push('✈️ Flight has taken off!');
this.adjustFlightPolling(flight.id, flight);
}
if (!currentFlight.actualOn && newData.actual_on) {
changes.push('🛬 Flight has landed!');
this.removeFlightPolling(flight.id);
}
if (!currentFlight.cancelled && newData.cancelled) {
changes.push('❌ Flight cancelled');
this.removeFlightPolling(flight.id);
}
if (!currentFlight.diverted && newData.diverted) {
changes.push(`🚨 Flight diverted to ${newData.destination.code_iata} (${newData.destination.name})`);
changes.push(
`🚨 Flight diverted to ${newData.destination.code_iata} (${newData.destination.name})`
);
}
// 10 multiple updates (0 - 10, 10 - 20, etc.)
if (currentFlight.progressPercent !== null &&
newData.progress_percent !== null &&
newData.actual_off &&
!newData.actual_on &&
!currentFlight.actualOn) {
if (
currentFlight.progressPercent !== null &&
newData.progress_percent !== null &&
newData.actual_off &&
!newData.actual_on &&
!currentFlight.actualOn
) {
const oldTens = Math.floor((currentFlight.progressPercent || 0) / 10);
const newTens = Math.floor(newData.progress_percent / 10);
if (oldTens !== newTens && newData.progress_percent !== 100) {
changes.push(`🔄 Flight progress: ${newData.progress_percent}%\n${this.slackProgressbar(newData.progress_percent)}`);
changes.push(
`🔄 Flight progress: ${newData.progress_percent}%\n${this.slackProgressbar(
newData.progress_percent
)}`
);
}
}
@@ -222,7 +244,7 @@ export class FlightUpdater {
diverted: newData.diverted,
gateOrigin: newData.gate_origin,
progressPercent: newData.progress_percent,
}
},
});
// stop polling on completion
@@ -231,16 +253,18 @@ export class FlightUpdater {
}
if (changes.length > 0) {
const message = `🔔 *${currentFlight.ident}* (${currentFlight.originIata}${currentFlight.destinationIata})\n${changes.join('\n')}`;
const message = `🔔 *${currentFlight.ident}* (${currentFlight.originIata}${
currentFlight.destinationIata
})\n${changes.join('\n')}`;
await app.client.chat.postMessage({
channel: currentFlight.channelId,
text: message
text: message,
});
}
} catch (error) {
console.error(`error updating flight ${flight.ident}:`, error);
// adjust polling for error
this.adjustFlightPolling(flight.id, flight, true);
}
@@ -253,7 +277,7 @@ export class FlightUpdater {
}
let newInterval = this.calculatePollInterval(flight);
if (isError) {
newInterval *= 2;
}
@@ -276,4 +300,4 @@ export class FlightUpdater {
const empty = 10 - filled;
return `\`${'█'.repeat(filled)}${'░'.repeat(empty)}\` ${percent}%`;
}
}
}