Skip to content

Commit

Permalink
Release 2024-01-10 (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannaPeanut authored Jan 10, 2024
2 parents cabcba9 + 6e1c7cf commit d551ac8
Show file tree
Hide file tree
Showing 182 changed files with 5,110 additions and 3,508 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "SurveyResponse" RENAME COLUMN "surveyId" TO "surveyPart";
23 changes: 23 additions & 0 deletions db/migrations/20231220104810_add_subsubsection_task/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- AlterTable
ALTER TABLE "Subsubsection" ADD COLUMN "subsubsectionTaskId" INTEGER;

-- CreateTable
CREATE TABLE "SubsubsectionTask" (
"id" SERIAL NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"slug" TEXT NOT NULL,
"title" TEXT NOT NULL,
"projectId" INTEGER NOT NULL,

CONSTRAINT "SubsubsectionTask_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "SubsubsectionTask_projectId_slug_key" ON "SubsubsectionTask"("projectId", "slug");

-- AddForeignKey
ALTER TABLE "Subsubsection" ADD CONSTRAINT "Subsubsection_subsubsectionTaskId_fkey" FOREIGN KEY ("subsubsectionTaskId") REFERENCES "SubsubsectionTask"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "SubsubsectionTask" ADD CONSTRAINT "SubsubsectionTask_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- AlterTable
ALTER TABLE "Subsubsection" ADD COLUMN "subsubsectionInfraId" INTEGER;

-- CreateTable
CREATE TABLE "SubsubsectionInfra" (
"id" SERIAL NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"slug" TEXT NOT NULL,
"title" TEXT NOT NULL,
"projectId" INTEGER NOT NULL,

CONSTRAINT "SubsubsectionInfra_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "SubsubsectionInfra_projectId_slug_key" ON "SubsubsectionInfra"("projectId", "slug");

-- AddForeignKey
ALTER TABLE "Subsubsection" ADD CONSTRAINT "Subsubsection_subsubsectionInfraId_fkey" FOREIGN KEY ("subsubsectionInfraId") REFERENCES "SubsubsectionInfra"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "SubsubsectionInfra" ADD CONSTRAINT "SubsubsectionInfra_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Subsubsection" ADD COLUMN "widthExisting" DOUBLE PRECISION;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Subsubsection" ADD COLUMN "isExistingInfra" BOOLEAN DEFAULT false;
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- CreateTable
CREATE TABLE "SubsubsectionSpecial" (
"id" SERIAL NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"slug" TEXT NOT NULL,
"title" TEXT NOT NULL,
"projectId" INTEGER NOT NULL,

CONSTRAINT "SubsubsectionSpecial_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "_SubsubsectionToSubsubsectionSpecial" (
"A" INTEGER NOT NULL,
"B" INTEGER NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "SubsubsectionSpecial_projectId_slug_key" ON "SubsubsectionSpecial"("projectId", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "_SubsubsectionToSubsubsectionSpecial_AB_unique" ON "_SubsubsectionToSubsubsectionSpecial"("A", "B");

-- CreateIndex
CREATE INDEX "_SubsubsectionToSubsubsectionSpecial_B_index" ON "_SubsubsectionToSubsubsectionSpecial"("B");

-- AddForeignKey
ALTER TABLE "SubsubsectionSpecial" ADD CONSTRAINT "SubsubsectionSpecial_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_SubsubsectionToSubsubsectionSpecial" ADD CONSTRAINT "_SubsubsectionToSubsubsectionSpecial_A_fkey" FOREIGN KEY ("A") REFERENCES "Subsubsection"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_SubsubsectionToSubsubsectionSpecial" ADD CONSTRAINT "_SubsubsectionToSubsubsectionSpecial_B_fkey" FOREIGN KEY ("B") REFERENCES "SubsubsectionSpecial"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
CREATE OR REPLACE FUNCTION slugify(input_text TEXT)
RETURNS TEXT AS
$$
DECLARE
slug TEXT;
BEGIN
slug := input_text;
slug := lower(slug);
slug := translate(slug, 'ä,ö,ü,ß', 'a,o,u,s');
slug := regexp_replace(slug, '[^a-z0-9]+', '-', 'g');
slug := regexp_replace(slug, '^[-]+|[-]+$', '', 'g');
RETURN slug;
END;
$$ LANGUAGE plpgsql;

DO
$$
DECLARE
v_project_id INTEGER;
v_task TEXT;
BEGIN
FOR v_project_id IN SELECT id FROM "Project"
LOOP
RAISE NOTICE 'Project: %', v_project_id;
FOR v_task IN SELECT DISTINCT task
FROM "Subsubsection"
WHERE "subsectionId" IN
(SELECT id FROM "Subsection" WHERE "projectId" = v_project_id)
LOOP
RAISE NOTICE ' Task: % %s', v_task, slugify(v_task);
INSERT INTO "SubsubsectionTask" ("updatedAt", slug, title, "projectId")
VALUES ('2023-12-20 19:31:21.496', slugify(v_task), v_task, v_project_id);
UPDATE "Subsubsection"
SET "subsubsectionTaskId" = (SELECT id
FROM "SubsubsectionTask"
WHERE "projectId" = v_project_id
AND title = v_task)
WHERE "subsectionId" IN
(SELECT id FROM "Subsection" WHERE "projectId" = v_project_id)
AND task = v_task;
END LOOP;
END LOOP;
END ;
$$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Subsubsection" ALTER COLUMN "task" DROP NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Subsection" ADD COLUMN "lengthKm" DOUBLE PRECISION;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "Subsubsection"
RENAME COLUMN "length" TO "lengthKm";
101 changes: 81 additions & 20 deletions db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ model Project {
Survey Survey[]
qualityLevels QualityLevel[]
SubsubsectionStatus SubsubsectionStatus[]
SubsubsectionTask SubsubsectionTask[]
SubsubsectionInfra SubsubsectionInfra[]
SubsubsectionSpecial SubsubsectionSpecial[]
}

model Membership {
Expand Down Expand Up @@ -207,6 +210,7 @@ model Subsection {
geometry Json
labelPos LabelPositionEnum @default(top)
description String?
lengthKm Float?
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
Expand All @@ -224,21 +228,23 @@ model Subsection {
}

model Subsubsection {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
subTitle String?
type SubsubsectionTypeEnum @default(ROUTE) // Führungform
geometry Json
labelPos LabelPositionEnum @default(top)
task String // Maßnahmentyp
length Float? // Kilometer
width Float? // Meter
costEstimate Float? // Euro
description String? // Anmerkungen
mapillaryKey String?
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
subTitle String?
type SubsubsectionTypeEnum @default(ROUTE) // Führungform
geometry Json
labelPos LabelPositionEnum @default(top)
task String? // Maßnahmentyp - UNUSED
lengthKm Float? // Kilometer
width Float? // Meter
widthExisting Float? // Meter
costEstimate Float? // Euro
description String? // Anmerkungen
mapillaryKey String?
isExistingInfra Boolean? @default(false) // Bestandsführung
maxSpeed Float? // Maximalgeschwindigkeit
trafficLoad Int? // Verkehrsbelastung
Expand All @@ -257,18 +263,27 @@ model Subsubsection {
ownFunds Float? // Einsatz Eigenmittel
//
qualityLevel QualityLevel? @relation(fields: [qualityLevelId], references: [id])
qualityLevel QualityLevel? @relation(fields: [qualityLevelId], references: [id])
qualityLevelId Int?
//
manager User? @relation(fields: [managerId], references: [id])
manager User? @relation(fields: [managerId], references: [id])
managerId Int?
//
subsection Subsection @relation(fields: [subsectionId], references: [id])
subsection Subsection @relation(fields: [subsectionId], references: [id])
subsectionId Int
//
uploads Upload[]
SubsubsectionStatus SubsubsectionStatus? @relation(fields: [subsubsectionStatusId], references: [id])
//
SubsubsectionStatus SubsubsectionStatus? @relation(fields: [subsubsectionStatusId], references: [id])
subsubsectionStatusId Int?
//
SubsubsectionTask SubsubsectionTask? @relation(fields: [subsubsectionTaskId], references: [id])
subsubsectionTaskId Int?
//
SubsubsectionInfra SubsubsectionInfra? @relation(fields: [subsubsectionInfraId], references: [id])
subsubsectionInfraId Int?
//
specialFeatures SubsubsectionSpecial[]
@@unique([subsectionId, slug])
}
Expand Down Expand Up @@ -308,6 +323,52 @@ model SubsubsectionStatus {
@@unique([projectId, slug])
}

model SubsubsectionTask {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
title String
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
Subsubsection Subsubsection[]
@@unique([projectId, slug])
}

model SubsubsectionInfra {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
title String
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
Subsubsection Subsubsection[]
@@unique([projectId, slug])
}

model SubsubsectionSpecial {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
title String
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
//
Subsubsection Subsubsection[]
@@unique([projectId, slug])
}

model Stakeholdernote {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
Expand Down Expand Up @@ -372,7 +433,7 @@ model SurveySession {

model SurveyResponse {
id Int @id @default(autoincrement())
surveyId Int // surveyParts as specified by the survey JSON files
surveyPart Int
data String
status SurveyResponseStatusEnum? @default(PENDING)
note String?
Expand Down
8 changes: 8 additions & 0 deletions db/seeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import seedQualityLevels from "./seeds/qualityLevels"
import seedStakeholdernotes from "./seeds/stakeholdernotes"
import seedSubsections from "./seeds/subsections"
import seedSubsubsectionStatus from "./seeds/subsubsectionStatus"
import seedSubsubsectionTask from "./seeds/subsubsectionTask"
import seedSubsubsectionInfra from "./seeds/subsubsectionInfra"
import seedSubsubsectionSpecial from "./seeds/subsubsectionSpecial"
import seedSurveyResponseTopics from "./seeds/surveyresponsetopics"
import seedSurveys from "./seeds/surveys"
import seedUploads from "./seeds/uploads"
import seedUsers from "./seeds/users"
import seedDevData from "./seeds/devData"

/*
* This seed function is executed when you run `blitz db seed`.
Expand All @@ -29,6 +33,10 @@ const seed = async () => {
await seedSurveys()
await seedSurveyResponseTopics()
await seedSubsubsectionStatus()
await seedSubsubsectionTask()
await seedSubsubsectionInfra()
await seedSubsubsectionSpecial()
await seedDevData()
}

export default seed
20 changes: 20 additions & 0 deletions db/seeds/devData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { PrismaClient } from "@prisma/client"

/*
# TODO: Document why this exists and could be useful
source .env.local
pg_dump $DATABASE_URL --data-only --column-inserts -t 'public."SubsubsectionSpecial"' | grep 'INSERT INTO'
*/

const sql = `
INSERT INTO public."SubsubsectionSpecial" (id, "createdAt", "updatedAt", slug, title, "projectId") VALUES (1, '2023-12-20 19:31:21.496', '2023-12-20 19:31:21.496', 's1', 'Special 1', 1);
INSERT INTO public."SubsubsectionSpecial" (id, "createdAt", "updatedAt", slug, title, "projectId") VALUES (2, '2023-12-20 19:31:29.162', '2023-12-20 19:31:29.162', 's2', 'Special 22', 1);
INSERT INTO public."SubsubsectionSpecial" (id, "createdAt", "updatedAt", slug, title, "projectId") VALUES (3, '2023-12-20 19:31:36.93', '2023-12-20 19:31:36.93', 's3', 'Special 333', 1);
`

const seedDevData = async () => {
// const prismaClient = new PrismaClient()
// sql.split(';').forEach(statement => prismaClient.$executeRawUnsafe(statement))
}

export default seedDevData
10 changes: 5 additions & 5 deletions db/seeds/subsection_subsubsections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const subsubsections: Omit<Prisma.SubsubsectionUncheckedCreateInput, "sub
],
labelPos: "topLeft",
task: "Ausbau Feldweg",
length: 0.487,
lengthKm: 0.487,
width: 3,
costEstimate: 10_000,
qualityLevelId: 1,
Expand Down Expand Up @@ -47,7 +47,7 @@ export const subsubsections: Omit<Prisma.SubsubsectionUncheckedCreateInput, "sub
],
labelPos: "bottomLeft",
task: "Ufersteg anlegen",
length: 0.922,
lengthKm: 0.922,
width: 3,
costEstimate: null,
qualityLevelId: 2,
Expand Down Expand Up @@ -81,7 +81,7 @@ export const subsubsections: Omit<Prisma.SubsubsectionUncheckedCreateInput, "sub
],
labelPos: "left",
task: "Fahrradstraße gestalten",
length: 1.293,
lengthKm: 1.293,
width: 4,
costEstimate: 20_000,
qualityLevelId: null,
Expand Down Expand Up @@ -110,7 +110,7 @@ export const subsubsections: Omit<Prisma.SubsubsectionUncheckedCreateInput, "sub
geometry: [13.329078172644188, 52.5225862734311],
labelPos: "top",
task: "Fahrbahnmarkierung mit Querung",
length: null,
lengthKm: null,
width: 2,
costEstimate: 30_000,
qualityLevelId: 4,
Expand Down Expand Up @@ -144,7 +144,7 @@ export const subsubsections: Omit<Prisma.SubsubsectionUncheckedCreateInput, "sub
geometry: [13.350034203659277, 52.51973770393019],
labelPos: "top",
task: "Umgestaltung Seitenraum",
length: 0.5,
lengthKm: 0.5,
width: 2,
costEstimate: 10_000,
qualityLevelId: null,
Expand Down
Loading

0 comments on commit d551ac8

Please sign in to comment.