From 361cc846d259a701a875c99970d70207895e05b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sven=20K=C3=B6nig?= Date: Thu, 23 May 2024 14:10:24 +0200 Subject: [PATCH] StaticDatasets: adapt upload for storing geojsons --- .../migration.sql | 12 ++++++++ db/schema.prisma | 28 +++++++++++++------ db/seeds/pmtiles.ts | 4 +-- scripts/StaticDatasets/api.ts | 2 +- .../StaticDatasets/updateStaticDatasets.ts | 2 +- src/app/admin/uploads/[slug]/page.tsx | 21 ++++++++++---- src/app/api/uploads/[slug]/route.ts | 2 +- src/app/api/uploads/create/route.ts | 6 ++-- src/uploads/schema.ts | 2 +- 9 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 db/migrations/20240523105650_adapt_upload_for_storing_geojsons/migration.sql diff --git a/db/migrations/20240523105650_adapt_upload_for_storing_geojsons/migration.sql b/db/migrations/20240523105650_adapt_upload_for_storing_geojsons/migration.sql new file mode 100644 index 000000000..d859c6c6c --- /dev/null +++ b/db/migrations/20240523105650_adapt_upload_for_storing_geojsons/migration.sql @@ -0,0 +1,12 @@ +-- CreateEnum +CREATE TYPE "UploadCreatedByEnum" AS ENUM ('USER', 'SCRIPT'); + +-- CreateEnum +CREATE TYPE "UploadTypeEnum" AS ENUM ('GEOJSON', 'PMTILES'); + +-- AlterTable +ALTER TABLE "Upload" + RENAME COLUMN "pmtilesUrl" TO "url"; +ALTER TABLE "Upload" + ADD COLUMN "createdBy" "UploadCreatedByEnum" NOT NULL DEFAULT 'SCRIPT', + ADD COLUMN "type" "UploadTypeEnum" NOT NULL DEFAULT 'PMTILES'; diff --git a/db/schema.prisma b/db/schema.prisma index f779ce3ab..5c565e54d 100644 --- a/db/schema.prisma +++ b/db/schema.prisma @@ -131,14 +131,26 @@ model Membership { } model Upload { - id Int @id @default(autoincrement()) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + id Int @id @default(autoincrement()) + createdAt DateTime @default(now()) + createdBy UploadCreatedByEnum @default(SCRIPT) + updatedAt DateTime @updatedAt // - slug String @unique - pmtilesUrl String - configs Json - public Boolean @default(false) + slug String @unique + type UploadTypeEnum @default(PMTILES) + url String + configs Json + public Boolean @default(false) // - regions Region[] + regions Region[] +} + +enum UploadCreatedByEnum { + USER + SCRIPT +} + +enum UploadTypeEnum { + GEOJSON + PMTILES } diff --git a/db/seeds/pmtiles.ts b/db/seeds/pmtiles.ts index bbfd4ea42..b6ffe1e6c 100644 --- a/db/seeds/pmtiles.ts +++ b/db/seeds/pmtiles.ts @@ -16,7 +16,7 @@ const seedUploads = async () => { const seedUploadsNudafa: Prisma.UploadUncheckedCreateInput[] = [ { slug: 'nudafa-combined', - pmtilesUrl: + url: 'https://atlas-private.s3.eu-central-1.amazonaws.com/test-data/nudafa-combined.pmtiles', configs: [ { @@ -39,7 +39,7 @@ const seedUploads = async () => { const seedUploadsBibi: Prisma.UploadUncheckedCreateInput[] = [ { slug: 'two-configs', - pmtilesUrl: + url: 'https://atlas-private.s3.eu-central-1.amazonaws.com/test-data/nudafa-combined.pmtiles', configs: [ { diff --git a/scripts/StaticDatasets/api.ts b/scripts/StaticDatasets/api.ts index e34408ffc..d8149f02b 100644 --- a/scripts/StaticDatasets/api.ts +++ b/scripts/StaticDatasets/api.ts @@ -33,7 +33,7 @@ export const getRegions = async (): Promise<{ id: number; slug: string }[]> => { type UploadData = { uploadSlug: string - pmtilesUrl: string + url: string regionSlugs: string[] isPublic: boolean configs: Record[] diff --git a/scripts/StaticDatasets/updateStaticDatasets.ts b/scripts/StaticDatasets/updateStaticDatasets.ts index e4fc7e9eb..dfdeab980 100644 --- a/scripts/StaticDatasets/updateStaticDatasets.ts +++ b/scripts/StaticDatasets/updateStaticDatasets.ts @@ -181,7 +181,7 @@ for (const { datasetFolderPath, regionFolder, datasetFolder } of datasetFileFold }) await createUpload({ uploadSlug, - pmtilesUrl, + url: pmtilesUrl, regionSlugs, isPublic: metaData.public, configs: mergedConfigs, diff --git a/src/app/admin/uploads/[slug]/page.tsx b/src/app/admin/uploads/[slug]/page.tsx index c1a9ca854..d6322a744 100644 --- a/src/app/admin/uploads/[slug]/page.tsx +++ b/src/app/admin/uploads/[slug]/page.tsx @@ -57,15 +57,26 @@ export default function AdminUploadPage() {

- Vorschau für Devs (_API_KEY_ aus .env/Bitwarden für{' '} - {process.env.NEXT_PUBLIC_APP_ENV}) -