diff --git a/README.md b/README.md index d0a8c4980..c7efc102c 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ NMSampleLocations is a FastAPI-based backend service designed to manage geospati - ๐Ÿ”Ž Filtering by location, date, type, and more - ๐Ÿ“ฆ PostgreSQL + PostGIS database backend - ๐Ÿ” Optional authentication and role-based access -- ๐Ÿงพ Interactive API documentation via Swagger and ReDoc +- ๐Ÿงพ Interactive API documentation via OpenAPI and ReDoc --- @@ -29,42 +29,142 @@ NMSampleLocations is a FastAPI-based backend service designed to manage geospati ### Prerequisites - Python 3.11+ -- PostgreSQL with PostGIS extension - [`uv`](https://github.com/astral-sh/uv) package manager +- Docker Desktop 4+ if wanting to host server/database locally with containers +- PostgreSQL with PostGIS extension if wanting to host server/database locally without containers -### Installation +### Installation & Setup + +#### 1. Clone the repository ```bash -# Clone the repository git clone https://github.com/DataIntegrationGroup/NMSampleLocations.git cd NMSampleLocations +``` + +#### 2. Set up virtual environment and install depdencies + -# Set up virtual environment and install dependencies + + + + + + + + + +
+ Mac/Linux + + Windows +
+ +```bash uv venv source .venv/bin/activate -uv pip install -r requirements.txt +uv sync --locked +``` + + -# Set up pre-commit hooks +```bash +uv venv +source .venv/Scripts/activate +uv sync --locked +``` + +
+ + +#### 3. Setup pre-commit hookes + +```bash pre-commit install +``` -# Set up environment variables -cp .env.example .env +#### 4. Setup environment variables + +```bash # Edit `.env` to configure database connection and app settings +cp .env.example .env +``` + +#### 5. Database and server + -# Run database migrations -alembic upgrade head + + + + + + + + + + + + + + + + + + + + + +
+ PostgreSQL + PostGIS installed locally + + Docker +
-# Start the development server +```bash +#run database migrations +alembic upgrade head + +# start development server uvicorn app.main:app --reload ``` + + + +```bash +# include -d flag for silent/detached build +docker compose up --build +``` + +
+Requires PostgreSQL and PostGIS extensions to be installed locally + +Requires Docker Desktop to be installed locally +
+ +Run docker exec -it nmsamplelocations-app-1 bash to open a shell inside the running app container. +
+ +After the database container is running, you can run tests with Pytest from your local command line (not necessarily inside the app container). +
+ ### ๐Ÿงญ Project Structure ```text app/ -โ”œโ”€โ”€ api/ # Route declarations -โ”œโ”€โ”€ core/ # Settings and application config -โ”œโ”€โ”€ db/ # Database models, sessions, migrations -โ”œโ”€โ”€ schemas/ # Pydantic data models -โ”œโ”€โ”€ services/ # Business logic and helpers -โ””โ”€โ”€ main.py # FastAPI entry point +โ”œโ”€โ”€ .env # Environment variables +โ”œโ”€โ”€ .pre-commit-config.yaml # pre-commit hook configuration file +โ”œโ”€โ”€ constants.py # Static variables used throughout the code +โ”œโ”€โ”€ docker-compose.yml # Docker compose file to build database and start server +โ”œโ”€โ”€ entrypoint.sh # Used by Docker to run database migrations and start server +โ”œโ”€โ”€ main.py # FastAPI entry point +| +โ”œโ”€โ”€ alembic/ # Alembic configuration and migration scripts +โ”œโ”€โ”€ api/ # Route declarations +โ”œโ”€โ”€ core/ # Settings, application config, and dependencies +โ”œโ”€โ”€ db/ # Database models, sessions, and engine +โ”œโ”€โ”€ docker/ # Custom Docker files +โ”œโ”€โ”€ schemas/ # Pydantic schemas and validations +โ”œโ”€โ”€ services/ # Reusable business logic, helpers, and database interactions +โ”œโ”€โ”€ tests/ # Code tests +โ””โ”€โ”€ transfers/ # Scripts to transfer data from NM_Aquifer to current db schema ``` \ No newline at end of file diff --git a/schemas_v2/sample.py b/schemas_v2/sample.py new file mode 100644 index 000000000..e69de29bb diff --git a/migration/data/location.csv b/transfers/data/location.csv similarity index 100% rename from migration/data/location.csv rename to transfers/data/location.csv diff --git a/migration/data/water_levels.csv b/transfers/data/water_levels.csv similarity index 100% rename from migration/data/water_levels.csv rename to transfers/data/water_levels.csv diff --git a/migration/data/welldata.csv b/transfers/data/welldata.csv similarity index 100% rename from migration/data/welldata.csv rename to transfers/data/welldata.csv diff --git a/migration/migration.py b/transfers/transfer.py similarity index 99% rename from migration/migration.py rename to transfers/transfer.py index 82802157f..9c0741f41 100644 --- a/migration/migration.py +++ b/transfers/transfer.py @@ -20,7 +20,6 @@ import pyproj from shapely import Point from shapely.ops import transform -from sqlalchemy.exc import ProgrammingError from db import * from db.location import Location diff --git a/migration/migration2.py b/transfers/transfer2.py similarity index 98% rename from migration/migration2.py rename to transfers/transfer2.py index da486480a..114341517 100644 --- a/migration/migration2.py +++ b/transfers/transfer2.py @@ -15,7 +15,6 @@ # =============================================================================== import time -from datetime import datetime import numpy as np import pandas as pd @@ -23,11 +22,10 @@ from shapely import Point from shapely.ops import transform -from db import Location, LocationThingAssociation, Thing, Sensor +from db import Location, LocationThingAssociation from db.engine import session_ctx # from db.observation.groundwaterlevel import GroundwaterLevelObservation -from db.observation import Observation # from db.series.groundwaterlevel import GroundwaterLevelSeries # from db.series.series import Series