-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
114 changed files
with
2,208 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require("dotenv").config({ path: "./.env.local" }) | ||
const { length, lineString } = require("@turf/turf") | ||
const { PrismaClient } = require("@prisma/client") | ||
|
||
const db = new PrismaClient() | ||
/* | ||
* This function is executed when you run `calc-lengthkm`. | ||
*/ | ||
const calculateLengthKm = async () => { | ||
const subsections = await db.subsection.findMany() | ||
console.log("subsections successfully fetched") | ||
subsections.forEach(async (subsection) => { | ||
const calculatedLengthKm = Number( | ||
length(lineString(subsection.geometry), { units: "kilometers" }).toFixed(3), | ||
) | ||
const updatedSubsection = await db.subsection.update({ | ||
where: { id: subsection.id }, | ||
data: { lengthKm: calculatedLengthKm }, | ||
}) | ||
console.log( | ||
`updated subsection ${updatedSubsection.id} successfuly`, | ||
updatedSubsection.lengthKm, | ||
) | ||
}) | ||
const subsubsections = await db.subsubsection.findMany() | ||
console.log("subsubsections successfully fetched") | ||
subsubsections.forEach(async (subsubsection) => { | ||
const calculatedLengthKm = | ||
subsubsection.type === "AREA" | ||
? 0.1 // AREAs are SF, they have no length so they get a default | ||
: Number(length(lineString(subsubsection.geometry), { units: "kilometers" }).toFixed(3)) | ||
const updatedSubsubsection = await db.subsubsection.update({ | ||
where: { id: subsubsection.id }, | ||
data: { lengthKm: calculatedLengthKm }, | ||
}) | ||
console.log( | ||
`updated subsubsection ${updatedSubsubsection.id} successfuly`, | ||
updatedSubsubsection.lengthKm, | ||
) | ||
}) | ||
} | ||
|
||
calculateLengthKm() |
5 changes: 5 additions & 0 deletions
5
db/migrations/20240109075002_surveyresponse_add_field_source/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- CreateEnum | ||
CREATE TYPE "SurveyResponseSourceEnum" AS ENUM ('EMAIL', 'LETTER', 'FORM'); | ||
|
||
-- AlterTable | ||
ALTER TABLE "SurveyResponse" ADD COLUMN "source" "SurveyResponseSourceEnum" NOT NULL DEFAULT 'FORM'; |
2 changes: 2 additions & 0 deletions
2
db/migrations/20240118153118_subsubsection_add_planning_period/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Subsubsection" ADD COLUMN "planningPeriod" DOUBLE PRECISION; |
2 changes: 2 additions & 0 deletions
2
db/migrations/20240118153201_subsubsection_add_construction_period/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Subsubsection" ADD COLUMN "constructionPeriod" DOUBLE PRECISION; |
2 changes: 2 additions & 0 deletions
2
db/migrations/20240118153339_subsubsection_add_quarter_planned_completion/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Subsubsection" ADD COLUMN "quarterPlannedCompletion" TEXT; |
12 changes: 12 additions & 0 deletions
12
...grations/20240123152216_subsection_and_subsubsection_make_lengthkm_required/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
Warnings: | ||
- Made the column `lengthKm` on table `Subsection` required. This step will fail if there are existing NULL values in that column. | ||
- Made the column `lengthKm` on table `Subsubsection` required. This step will fail if there are existing NULL values in that column. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Subsection" ALTER COLUMN "lengthKm" SET NOT NULL; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Subsubsection" ALTER COLUMN "lengthKm" SET NOT NULL; |
9 changes: 9 additions & 0 deletions
9
...ubsection_replace_quarter_planned_completion_with_estimated_completion_date/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `quarterPlannedCompletion` on the `Subsubsection` table. All the data in the column will be lost. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Subsubsection" DROP COLUMN "quarterPlannedCompletion", | ||
ADD COLUMN "estimatedCompletionDate" TIMESTAMP(3); |
23 changes: 23 additions & 0 deletions
23
db/migrations/20240125095210_subsection_add_field_network_hierarchy/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- AlterTable | ||
ALTER TABLE "Subsection" ADD COLUMN "networkHierarchyId" INTEGER; | ||
|
||
-- CreateTable | ||
CREATE TABLE "NetworkHierarchy" ( | ||
"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 "NetworkHierarchy_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "NetworkHierarchy_projectId_slug_key" ON "NetworkHierarchy"("projectId", "slug"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Subsection" ADD CONSTRAINT "Subsection_networkHierarchyId_fkey" FOREIGN KEY ("networkHierarchyId") REFERENCES "NetworkHierarchy"("id") ON DELETE SET NULL ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "NetworkHierarchy" ADD CONSTRAINT "NetworkHierarchy_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
5 changes: 5 additions & 0 deletions
5
db/migrations/20240125104441_subsection_add_field_priority/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- CreateEnum | ||
CREATE TYPE "PriorityEnum" AS ENUM ('OPEN', 'TOP', 'HIGH', 'MEDIUM', 'LOW'); | ||
|
||
-- AlterTable | ||
ALTER TABLE "Subsection" ADD COLUMN "priority" "PriorityEnum" NOT NULL DEFAULT 'OPEN'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.