Skip to content

Commit

Permalink
migration to postgis
Browse files Browse the repository at this point in the history
* feat: add models and ingestion scripts

Signed-off-by: 35C4n0r <[email protected]>

* feat: improve table schema

Signed-off-by: 35C4n0r <[email protected]>

* fix: fix migration typo

Signed-off-by: 35C4n0r <[email protected]>

* ref: refactor db schema

Signed-off-by: 35C4n0r <[email protected]>

* chore: replace schema

Signed-off-by: 35C4n0r <[email protected]>

* chore: replace schema

Signed-off-by: 35C4n0r <[email protected]>

* feat: migrate codebase

Signed-off-by: 35C4n0r <[email protected]>

* feat: add create/search place APIs

* feat: fix setup script

---------

Signed-off-by: 35C4n0r <[email protected]>
Co-authored-by: 35C4n0r <[email protected]>
Co-authored-by: Jay Kumar <[email protected]>
  • Loading branch information
3 people authored Dec 5, 2024
1 parent a679623 commit 5cc60d3
Show file tree
Hide file tree
Showing 43 changed files with 1,513 additions and 750 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=postgresql://admin:[email protected]:5555/gis
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
141 changes: 140 additions & 1 deletion package-lock.json

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

4 changes: 3 additions & 1 deletion 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,11 +61,12 @@
"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",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
},
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;
10 changes: 10 additions & 0 deletions prisma/migrations/20241203015556_add_place/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- CreateTable
CREATE TABLE "Place" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"type" TEXT NOT NULL,
"tag" TEXT NOT NULL,
"location" geometry(Point, 4326) NOT NULL,

CONSTRAINT "Place_pkey" PRIMARY KEY ("id")
);
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"
Loading

0 comments on commit 5cc60d3

Please sign in to comment.