diff --git a/apps/backend/prisma/migrations/20241205183812_gtfs_routes/migration.sql b/apps/backend/prisma/migrations/20241205183812_gtfs_routes/migration.sql new file mode 100644 index 00000000..c86881cf --- /dev/null +++ b/apps/backend/prisma/migrations/20241205183812_gtfs_routes/migration.sql @@ -0,0 +1,33 @@ +-- CreateTable +CREATE TABLE "GtfsRoute" ( + "id" TEXT NOT NULL, + "type" TEXT NOT NULL, + "shortName" TEXT NOT NULL, + "longName" TEXT, + "url" TEXT, + "color" TEXT, + "isNight" BOOLEAN, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "GtfsRoute_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "GtfsRouteStop" ( + "id" TEXT NOT NULL, + "routeId" TEXT NOT NULL, + "directionId" TEXT NOT NULL, + "stopId" TEXT NOT NULL, + "stopSequence" INTEGER NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "GtfsRouteStop_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "GtfsRouteStop_routeId_directionId_stopId_stopSequence_key" ON "GtfsRouteStop"("routeId", "directionId", "stopId", "stopSequence"); + +-- AddForeignKey +ALTER TABLE "GtfsRouteStop" ADD CONSTRAINT "GtfsRouteStop_routeId_fkey" FOREIGN KEY ("routeId") REFERENCES "GtfsRoute"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/apps/backend/prisma/schema.prisma b/apps/backend/prisma/schema.prisma index 93934949..595a2dea 100644 --- a/apps/backend/prisma/schema.prisma +++ b/apps/backend/prisma/schema.prisma @@ -71,6 +71,36 @@ model PlatformsOnRoutes { @@unique([platformId, routeId]) } +model GtfsRoute { + id String @id + type String + shortName String + longName String? + url String? + color String? + isNight Boolean? + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + GtfsRouteStop GtfsRouteStop[] +} + +model GtfsRouteStop { + id String @id @default(uuid()) + + routeId String + route GtfsRoute @relation(fields: [routeId], references: [id]) + + directionId String + stopId String + stopSequence Int + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + @@unique([routeId, directionId, stopId, stopSequence]) +} + model Log { id BigInt @id @default(autoincrement()) level LogLevel