Skip to content

Commit

Permalink
Merge pull request #169 from 35C4n0r/feat-prisma-models
Browse files Browse the repository at this point in the history
Feat prisma models
  • Loading branch information
dhruv-1001 authored Sep 21, 2024
2 parents a679623 + 9911fa8 commit 920a911
Show file tree
Hide file tree
Showing 35 changed files with 1,333 additions and 738 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ src/.DS_Store
/src/geojson-data/
/src/geoquery.in.data/
db.mmdb


.env
139 changes: 139 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-fastify": "^10.3.0",
"@nestjs/swagger": "^7.3.1",
"@prisma/client": "^5.17.0",
"@samagra-x/stencil": "^0.0.6",
"@turf/turf": "^6.5.0",
"@types/multer": "^1.4.11",
Expand Down Expand Up @@ -60,6 +61,7 @@
"husky": "8.0.3",
"jest": "^29.5.0",
"prettier": "^3.0.0",
"prisma": "^5.17.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
Expand Down
12 changes: 12 additions & 0 deletions prisma/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "3.9"

services:
postgis:
container_name: geopostgis
image: postgis/postgis:16-3.4-alpine
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_USER=admin
- POSTGRES_DB=gis
85 changes: 85 additions & 0 deletions prisma/migrations/20240906152553_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
-- CreateExtension
CREATE EXTENSION IF NOT EXISTS "fuzzystrmatch";

-- CreateExtension
CREATE EXTENSION IF NOT EXISTS "postgis";

-- CreateTable
CREATE TABLE "State" (
"id" SERIAL NOT NULL,
"state_code" INTEGER NOT NULL,
"state_name" TEXT NOT NULL,
"metadata" JSONB,
"geometry" geometry NOT NULL,

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

-- CreateTable
CREATE TABLE "District" (
"id" SERIAL NOT NULL,
"district_code" INTEGER NOT NULL,
"district_name" TEXT NOT NULL,
"geometry" geometry NOT NULL,
"metadata" JSONB,
"state_id" INTEGER,

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

-- CreateTable
CREATE TABLE "SubDistrict" (
"id" SERIAL NOT NULL,
"subdistrict_code" INTEGER NOT NULL,
"subdistrict_name" TEXT NOT NULL,
"geometry" geometry NOT NULL,
"metadata" JSONB,
"district_id" INTEGER,
"state_id" INTEGER,

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

-- CreateTable
CREATE TABLE "Village" (
"id" SERIAL NOT NULL,
"village_code" SERIAL NOT NULL,
"geometry" geometry NOT NULL,
"village_name" TEXT NOT NULL,
"metadata" JSONB,
"subdistrict_id" INTEGER,
"district_id" INTEGER,
"state_id" INTEGER,

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

-- CreateIndex
CREATE UNIQUE INDEX "State_state_code_key" ON "State"("state_code");

-- CreateIndex
CREATE UNIQUE INDEX "State_state_name_key" ON "State"("state_name");

-- CreateIndex
CREATE UNIQUE INDEX "District_district_code_key" ON "District"("district_code");

-- CreateIndex
CREATE UNIQUE INDEX "SubDistrict_subdistrict_code_key" ON "SubDistrict"("subdistrict_code");

-- AddForeignKey
ALTER TABLE "District" ADD CONSTRAINT "District_state_id_fkey" FOREIGN KEY ("state_id") REFERENCES "State"("state_code") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "SubDistrict" ADD CONSTRAINT "SubDistrict_district_id_fkey" FOREIGN KEY ("district_id") REFERENCES "District"("district_code") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "SubDistrict" ADD CONSTRAINT "SubDistrict_state_id_fkey" FOREIGN KEY ("state_id") REFERENCES "State"("state_code") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Village" ADD CONSTRAINT "Village_subdistrict_id_fkey" FOREIGN KEY ("subdistrict_id") REFERENCES "SubDistrict"("subdistrict_code") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Village" ADD CONSTRAINT "Village_district_id_fkey" FOREIGN KEY ("district_id") REFERENCES "District"("district_code") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Village" ADD CONSTRAINT "Village_state_id_fkey" FOREIGN KEY ("state_id") REFERENCES "State"("state_code") ON DELETE SET NULL ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
76 changes: 76 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

// Command for migration: npx prisma migrate dev --name init

generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions"]
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [postgis(), fuzzystrmatch()]
}

model State {
id Int @id @default(autoincrement())
state_code Int @unique
state_name String @unique
metadata Json?
geometry Unsupported("geometry")
district District[]
subdistrict SubDistrict[]
village Village[]
}

model District {
id Int @id @default(autoincrement())
district_code Int @unique
district_name String
geometry Unsupported("geometry")
metadata Json?
state_id Int?
state State? @relation(fields: [state_id], references: [state_code])
subdistrict SubDistrict[]
village Village[]
}

model SubDistrict {
id Int @id @default(autoincrement())
subdistrict_code Int @unique
subdistrict_name String
geometry Unsupported("geometry")
metadata Json?
district_id Int?
district District? @relation(fields: [district_id], references: [district_code])
state_id Int?
state State? @relation(fields: [state_id], references: [state_code])
village Village[]
}

model Village {
id Int @id @default(autoincrement())
village_code Int @default(autoincrement())
geometry Unsupported("geometry")
village_name String
metadata Json?
subdistrict_id Int?
subdistrict SubDistrict? @relation(fields: [subdistrict_id], references: [subdistrict_code])
district_id Int?
district District? @relation(fields: [district_id], references: [district_code])
state_id Int?
state State? @relation(fields: [state_id], references: [state_code])
}
Loading

0 comments on commit 920a911

Please sign in to comment.