Skip to content

Commit

Permalink
Production release (#349)
Browse files Browse the repository at this point in the history
* feat: update role coumn in use profilem, now role will be store in array

* fix: fix role issues of user in profile update endpoint

* feat: added new endpoints for project centroids

* feat: update status & ongoing task on project endpoint

* fix: remove unused code from update profile

* feat: update role text on signin/signup

* feat: redirect to complete profile page if the current signin role is not includes in role list

* feat:  update text `Drone Oprerator` to `DRONE_OPERATOR` and `Project Creator` to `PROJECT_CREATOR`

* feat: update role case for readability

* feat: post new role with existing role on profile add as new role

* feat: update text `DRONE_OPERATOR` to `DRONE_PILOT`

* feat(project-dashboard): fetch projects centroid list

* feat(project-dashboard): use separate api to show all projects (not-paginated) on map

* fix: return, don't redirect to complete profile if userDetail is not success

* feat: added user role in access token

* feat: added role of user in auth

* fix: reslove project completed status after images processing

* feat: return row data on table row click

* feat(individual-project): add task_id on contribution table row

* feat: cursor pointer if handleTableRowClick function is available

* feat: update type of handleRowClick function params

* feat(individual-project): store necessary details of task clicked on table on redux

* fix: update task counts & user task based on role

* feat: show popup on setting property from outside the map

* feat: added restriction on task lock request, only project author & drone operator can request the task

* feat:(individual-project): pass clicked task details , popup coordinarte on AsyncPopup component and clear task details state on popup close

* refac: remove print & commented code from get projects

* feat: add user role on login payload

* fix: added role on pydentic class to validate

* refac: update user task lists & added log for user role

* feat: added new image processing state called as IMAGE_PROCESSING_FAILED

* feat: call user details api on gogle login success and store on local storage

* feat: redirect to complete profile section if the current user role is not exists on users details role list

* feat: remove set timeout

* feat: redirect to complete profile section if the current user role is not exists on users details role list

* feat(task-description): show response message on toast on task lock/unlock

* updated s3 utility function for forward slash

* feat(profile-complete): update profile and invalidate the query to refetch the updated profile data

* feat(user-profile): fetch user details on edit profile page mount

* feat: added the new state for task when image processing failed

* fix: reslove syntax errors on statistics endpoint

* feat: remove api call on user profile for user details page and call on header

* feat: update status in project details endpoint

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.6.9 → v0.7.0](astral-sh/ruff-pre-commit@v0.6.9...v0.7.0)

* feat: update the status & project creation time on project lists

* feat: update task events endpoint for the task image uploaded

* feat: added the new case for re-run the image task processing...

* feat: updated status of task on get_assets_info

* feat: add static cumulative task status values

* feat(dashboard): Show task list as per active status card and show detailed status on status column on list

* feat(project-details): Replace old Breadcrumb with dynamic one

* feat(project-details): Show Unflyable task on map

* feat(main-dashboard): add unit of task area on table column header

* fix: updating image after image processing...

* feat(task-description): remove padding

* feat(task-description): update breadcrumb

* fix: comment the task restrictions

* feat(task-description): remove unnecessary animation code

* feat(task-description): show image processing status show re-upload and re-run `processing button in case of failure

* feat: upload image component UI and functionality

* feat(task-description): update UI of TaskDescription

* feat(task-description): trigger status updating api on image upload and image processing starter api success

* feat: update image processing rerun function

* fix(task-description): make rerun button visible  only on imnage process failure

* fix(task-description): make rerun button visible  only on image process failure

* feat: create utill function to format the string with the help of regex

remove underscore

make first character uppercase and rest of the character lowercase

* feat: convert the task state into readable text

* feat: added the get orthophoto tile endpoints

* hotfix: update task status as completed after image processing...

* hotfix: update task status as completed after image processing...

* hotfix(taskStatus): update task status as completed after image processing...

* fix: pass the matching args to download_and_upload_assets_from_odm_to_s3

* fix: update state of task after image processes

* feat: re-upload the images from pre-signed urls

* feat(individual-project): show image-processed/task-completed on map

* feat: handle state event for image re-upload

* feat(project-description): add `image processing failed` state of map task on map

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/commitizen-tools/commitizen: v3.29.1 → v3.30.0](commitizen-tools/commitizen@v3.29.1...v3.30.0)
- [github.com/astral-sh/ruff-pre-commit: v0.7.0 → v0.7.1](astral-sh/ruff-pre-commit@v0.7.0...v0.7.1)

* feat(task-description): save uploading image (replace/add) on redux store

* feat(task-description): add options to choose want to replace the image or add on existing imags while uploading images

* feat(task-description): get presigned url as per the type(replace the images/ add to existing images)

* fix: update status text on formating `Image Processed` to `Completed`

* fix: issues slove on updated imgaes delete on s3 buckets

* fix: options passed in odm task

* fix: added options for image processing for orthophooto formats

* feat(task-description): update status on rerun processing

* feat: create orhtophoto preview modal

* fix: added options dsm true only

* feat: update outline and bbox of task in task details endpoint

* docs: start documentation for setting up dev server

* ci: update docs build trigger to develop branch

* build: update node and web ODM versions, document compose file

* docs: extra info in dev setup docs

* docs: info for creating wpml flightplan manually

* docs: fix link to generate-flightplans.md

* build: add extra dependency groups to pyproject

* docs: indent code so list counting works

* docs: update progress in roadmap, image upload is possible

* fix: Adjust task dimensions to allow customization and prevent accidental rectangles

* refac: remove ## from import section

* feat(project-details): add more details on task listing table like outline and bbox and save clicked task geometry details on redux store

* feat: add TaskOrthophotoPreview component

* feat(orthophoto-preview): get taskId from redux store

* feat(orthophoto-preview): add tile size

* feat(orthophoto-preview): save outline of task on taskDescription response success

* feat(task-description): update status on rerun processing

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.1 → v0.7.2](astral-sh/ruff-pre-commit@v0.7.1...v0.7.2)

* fix(s3-config): update S3 bucket name & path prefix to mimic with dev & prd

* refac: s3 bucket path name

* refac: refactor orthophoto tile retrieval for improved safety and efficiency

* feat(orthophoto-preview): fit bounds before adding orthophoto source and layer

* feat(orthophoto-preview): Load orthophoto tiles dynamically based on viewport and zoom level

restrict loading to zoom levels >= 12 and task bound is not on view

* FrontendImageScan: Disabled as aquasec db fetch failed numerous times

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/commitizen-tools/commitizen: v3.30.0 → v3.30.1](commitizen-tools/commitizen@v3.30.0...v3.30.1)
- [github.com/astral-sh/ruff-pre-commit: v0.7.2 → v0.7.3](astral-sh/ruff-pre-commit@v0.7.2...v0.7.3)

* feat: add `COGOrthophotoViewer` component

* feat: add `@geomatico/maplibre-cog-protocol` and update `maplibre-gl` version to support COG file

* feat: implement `COGOrthophotoViewer` to preview task orthophoto

* refactor: add task validation with pydantic, Improve DB handling & error logging (#328)

* refac: refactor database connection handling and improve error logging in task processing

* feat: add task retrieval endpoint with Pydantic validation

* feat: Add Pydantic validation for task statistics endpoint response

* refactor: vove event handling logic from route.py to logic.py

* feat: add reprojection of orthophoto to EPSG:3857 before uploading to S3

* docs: added docs string on image processing function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* feat: added try-except to handle/track the error

* feat: Add reprojection of orthophoto to EPSG:3857 before uploading to S3 (#333)

* feat: add reprojection of orthophoto to EPSG:3857 before uploading to S3

* docs: added docs string on image processing function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* feat: added try-except to handle/track the error

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* feat: add s3 endpoint to vite `defineConfig`

* feat(orthophoto-preview): add dynamic source with the url prepended with `cog://` to preview orthophoto

* Update MapLibre and Integrate COG Protocol for Efficient Orthophoto Rendering (#334)

* feat: add `COGOrthophotoViewer` component

* feat: add `@geomatico/maplibre-cog-protocol` and update `maplibre-gl` version to support COG file

* feat: implement `COGOrthophotoViewer` to preview task orthophoto

* feat: add s3 endpoint to vite `defineConfig`

* feat(orthophoto-preview): add dynamic source with the url prepended with `cog://` to preview orthophoto

---------

Co-authored-by: Sujit <[email protected]>

* feat: make required changes for `loadImage` on map libre version updation to 4

* feat: make required changes for cluster on map libre version updation to 4

* feat: add `COG_URL`

* feat: remove rio tiler package & update authord_id in project details endpoint

* feat: update author_id in project lists

* feat: remove rio-tiler package & update author_id in project details endpoint (#337)

* feat: add reprojection of orthophoto to EPSG:3857 before uploading to S3

* docs: added docs string on image processing function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* feat: added try-except to handle/track the error

* feat: remove rio tiler package & update authord_id in project details endpoint

* feat: update author_id in project lists

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* fix: remove rio_tiler from project logic

* Feat: Refactor project creartion form UI and improve map interactivity (#339)

* feat(project-creation-form): form wrapper UI update

* feat(project-creation-form): form header update

* feat(project-creation-form): form step switcher UI update

* feat(project-creation-form): update wrapper of form content and description

* feat(project-creation-form): update basic information form information and form content

* feat(project-creation-form): update define AOI form information and form content

* feat(project-creation-form): update Key parameters form information and form content UI

* feat(project-creation-form): update generate task step form information and form content UI

* feat(project-creation-form): add animaiton on info text

* feat(project-creation-form): update contribution step form information and form content UI

* feat(project-creation-form): update style on form wrapper

* feat(dashboard): make UI responsive

* feat(project-creation-form): clear all state on form component unmount

* feat(task-description): prevent click event untill processing starter api and status updation success

* feat(project-description): add getLayerOptionsByStatus static function

* feat(project-description): refactor dynamic fill color as per task status using `getLayerOptionsByStatus`

* feat(project-description): separate the logic of showing `go To Task`/`Lock Task` button by the use of `showPrimaryButton` function

* feat: restrict user redirection to complete profile if user profile is loading

* feat: add maxBounds `[[-179, -89],[179, 89]]` to restrict map panning

---------

Co-authored-by: Sujit <[email protected]>

* [pre-commit.ci] pre-commit autoupdate (#340)

updates:
- [github.com/commitizen-tools/commitizen: v3.30.1 → v3.31.0](commitizen-tools/commitizen@v3.30.1...v3.31.0)
- [github.com/astral-sh/ruff-pre-commit: v0.7.3 → v0.7.4](astral-sh/ruff-pre-commit@v0.7.3...v0.7.4)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Fix: Application crash on file upload and implement zoom to orthophoto  (#341)

* feat(project-creation-form): form wrapper UI update

* feat(project-creation-form): form header update

* feat(project-creation-form): form step switcher UI update

* feat(project-creation-form): update wrapper of form content and description

* feat(project-creation-form): update basic information form information and form content

* feat(project-creation-form): update define AOI form information and form content

* feat(project-creation-form): update Key parameters form information and form content UI

* feat(project-creation-form): update generate task step form information and form content UI

* feat(project-creation-form): add animaiton on info text

* feat(project-creation-form): update contribution step form information and form content UI

* feat(project-creation-form): update style on form wrapper

* feat(dashboard): make UI responsive

* feat(project-creation-form): clear all state on form component unmount

* feat(task-description): prevent click event untill processing starter api and status updation success

* feat(project-description): add getLayerOptionsByStatus static function

* feat(project-description): refactor dynamic fill color as per task status using `getLayerOptionsByStatus`

* feat(project-description): separate the logic of showing `go To Task`/`Lock Task` button by the use of `showPrimaryButton` function

* feat: restrict user redirection to complete profile if user profile is loading

* feat: add maxBounds `[[-179, -89],[179, 89]]` to restrict map panning

* fix(#332): fix crash application on file upload on firefox

in firefox `File.lastmodifiedDate` has no longer support fixed replacing `lastModifiedDate` with `lastModified`

* feat: add zoomToLayer optional  feature on COGOrthophotoViewer component

* feat(orthophoto-preview): implement zoom to orthohphoto

---------

Co-authored-by: Sujit <[email protected]>

* Upload align.laz along with Drone Images (#343)

* Upload GCP along with Drone Images

* Add align.laz to available uploads

* Add descriptions for align

* add align.laz modal

---------

Co-authored-by: Niraj Adhikari <[email protected]>

* fix: update take-off point from 200m to 350m (#348)

* docs: add pull request template

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refactor(frontend): reset takeoff point state incase the location is not valid (#351)

* optimize: zoom to geotiff to bounds

---------

Co-authored-by: Sujit <[email protected]>
Co-authored-by: Niraj Adhikari <[email protected]>
Co-authored-by: Niraj Adhikari <[email protected]>
Co-authored-by: Sujit <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sam <[email protected]>
Co-authored-by: spwoodcock <[email protected]>
Co-authored-by: Nischal Shrestha <[email protected]>
Co-authored-by: Stephen Mather <[email protected]>
Co-authored-by: Bijay Rauniyar <[email protected]>
  • Loading branch information
11 people authored Nov 22, 2024
1 parent 1c76836 commit 90ae194
Show file tree
Hide file tree
Showing 95 changed files with 3,778 additions and 1,263 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ SITE_NAME=${SITE_NAME:-"DTM-Drone Tasking Manager"}
BASE_URL=${BASE_URL:-http://localhost:8000/api}
API_URL_V1=${API_URL_V1:-http://localhost:8000/api}
NODE_ODM_URL=${NODE_ODM_URL:-http://odm-api:3000}
COG_URL=${COG_URL}


### ODM ###
Expand Down
39 changes: 39 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## What type of PR is this? (check all applicable)

- [ ] 🍕 Feature
- [ ] 🐛 Bug Fix
- [ ] 📝 Documentation
- [ ] 🧑‍💻 Refactor
- [ ] ✅ Test
- [ ] 🤖 Build or CI
- [ ] ❓ Other (please specify)

## Related Issue

Example: Fixes #123

## Describe this PR

A brief description of how this solves the issue.

## Screenshots

Please provide screenshots of the change.

## Alternative Approaches Considered

Did you attempt any other approaches that are not documented in code?

## Review Guide

Notes for the reviewer. How to test this change?

## Checklist before requesting a review

- 📖 Read the HOT Code of Conduct: <https://docs.hotosm.org/code-of-conduct>
- 👷‍♀️ Create small PRs. In most cases, this will be possible.
- ✅ Provide tests for your changes.
- 📝 Use descriptive commit messages.
- 📗 Update any related documentation and include any relevant screenshots.

## [optional] What gif best describes this PR or how it makes you feel?
1 change: 1 addition & 0 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
image_name: ghcr.io/${{ github.repository }}/frontend
dockerfile: Dockerfile
extra_build_args: BASE64_ARGS_TO_ENV=${{ needs.encode-envs.outputs.ENCODED_ENV }}
scan_image: false
secrets: inherit

deploy_to_vm:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- docs/**
- src/**
- mkdocs.yml
branches: [main]
branches: [develop]
# Allow manual trigger (workflow_dispatch)
workflow_dispatch:

Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ repos:

# Versioning: Commit messages & changelog
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.29.1
rev: v3.31.0
hooks:
- id: commitizen
stages: [commit-msg]

# Lint / autoformat: Python code
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: "v0.6.9"
rev: "v0.7.4"
hooks:
# Run the linter
- id: ruff
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ To get started with Drone TM:
|| 🖥️ simple UI with user sign up and login |
|| 🖥️ project area subdivision into smaller task areas for operators |
|| 📱 flight plan generation in task areas for DJI drones |
|| 🖥️ upload of drone imagery collected during flight |
|⚙️| 📱 follow terrain during flight plan generation in hilly/mountainous regions |
|⚙️| 📱 allow adjustments to the flight plan orientation based on field conditions |
|⚙️| 🖥️ drone imagery upload merging into a final combined image for the project |
|⚙️| 🖥️ merging of drone imagery into a final combined image for the project |
| | 🖥️ user access management for each part of the UI |
| | 📱 & 🖥️ real-time updates for drone flight progress |
| | 📱 flight plan generation for other drone manufacturers |
Expand Down
49 changes: 27 additions & 22 deletions docker-compose.odm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,7 @@ volumes:
odm-db-data:

services:
odm-db:
image: docker.io/opendronemap/webodm_db:latest
container_name: odm-db
volumes:
- odm-db-data:/var/lib/postgresql/data:Z
ports:
- 5999:5432
networks:
- dtm-network
restart: unless-stopped
oom_score_adj: -100

# This container does the actual imagery processing (not persistent, scalable)
odm-api:
image: docker.io/opendronemap/nodeodm:3.5.3
# This is hardcoded by default
Expand All @@ -29,8 +18,9 @@ services:
restart: unless-stopped
oom_score_adj: 500

# UI to coordinate queueing of tasks and display of output
odm-web:
image: docker.io/opendronemap/webodm_webapp:2.5.4
image: docker.io/opendronemap/webodm_webapp:2.5.5
container_name: odm-web
entrypoint: /bin/bash -c "chmod +x /webodm/*.sh && /bin/bash -c \"/webodm/wait-for-postgres.sh odm-db /webodm/wait-for-it.sh -t 0 odm-broker:6379 -- /webodm/start.sh\""
volumes:
Expand All @@ -47,16 +37,9 @@ services:
restart: unless-stopped
oom_score_adj: 0

odm-broker:
image: docker.io/redis:7.0.10
container_name: odm-broker
networks:
- dtm-network
restart: unless-stopped
oom_score_adj: -500

# Instance of WebODM that uses Celery to manage processing jobs
odm-worker:
image: docker.io/opendronemap/webodm_webapp:2.5.4
image: docker.io/opendronemap/webodm_webapp:2.5.5
container_name: odm-worker
entrypoint: /bin/bash -c "/webodm/wait-for-postgres.sh odm-db /webodm/wait-for-it.sh -t 0 odm-broker:6379 -- /webodm/wait-for-it.sh -t 0 odm-web:8000 -- /webodm/worker.sh start"
volumes:
Expand All @@ -72,3 +55,25 @@ services:
- dtm-network
restart: unless-stopped
oom_score_adj: 250

# Redis broker to manage job queue
odm-broker:
image: docker.io/redis:7.4.1
container_name: odm-broker
networks:
- dtm-network
restart: unless-stopped
oom_score_adj: -500

# Stores data related to the web instance & queueing
odm-db:
image: docker.io/opendronemap/webodm_db:latest
container_name: odm-db
volumes:
- odm-db-data:/var/lib/postgresql/data:Z
ports:
- 5999:5432
networks:
- dtm-network
restart: unless-stopped
oom_score_adj: -100
61 changes: 61 additions & 0 deletions docs/dev/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Setting Up Drone TM For Development

!!! important

You must have Docker and Docker Compose installed first.

Docker install guide: [https://docs.docker.com/engine/install][1]

Compose install guide: [https://docs.docker.com/compose/install][2]

## (Optional) Configure Google OAuth

- Create a new client ID and secret in your Google account for OAuth2.
- Set the redirect URL to your local frontend URL, e.g. `http://localhost:3040/auth`.

!!! note

This step is only required to use the frontend.

## Configure Your Dotenv

- There is an example `.env.example` file that can be copied:
`cp .env.example .env`
- If you only plan on using the backend then everything should be
configured for you.
- Else, if you set up Google OAuth credentials, set the variables here:
```dotenv
GOOGLE_CLIENT_ID="YOUR_CLIENT_ID"
GOOGLE_CLIENT_SECRET="YOUR_CLIENT_SECRET"
GOOGLE_LOGIN_REDIRECT_URI="http://localhost:3040/auth"
```

## Build The Containers

```bash
docker compose build
```

### Run The Containers

This will also run ODM alongside DroneTM:

```bash
docker compose -f docker-compose.yml -f docker-compose.odm.yml up -d
```

### Access The Services

DroneTM Backend: [http://localhost:8000](http://localhost:8000)

DroneTM Frontend: [http://localhost:3040](http://localhost:3040)

Web ODM: [http://localhost:9900](http://localhost:9900)

- Default user: `admin`
- Default password: `password`

> Note the ports may be different if you changed them in the dotenv file.
[1]: https://docs.docker.com/engine/install/#other-linux-distros "Docker Install Guide"
[2]: https://docs.docker.com/compose/install/#scenario-two-install-the-compose-plugin "Docker Compose Install Guide"
53 changes: 53 additions & 0 deletions docs/manuals/generate-flightplans.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Generating Flightplans

## Manually Via Command Line

1. Calculate Flight Parameters:

```python
python calculate_parameters.py \
--forward_overlap 70 \
--side_overlap 70 \
--altitude_above_ground_level 115 \
--image_interval 2
```

> This will output a JSON that can be used in step 5 below.
2. Creating Waypoints:

```python
python waypoints.py \
--project_geojson_polygon aoi.geojson \
--altitude_above_ground_level 115 \
--forward_overlap 70 \
--side_overlap 70 \
--generate_each_points \
--take_off_point LON,LAT \
--output_file_path ./waypoints.geojson
```

3. Add Eleveation Data From A DEM File:

```python
python add_elevation_from_dem.py dsm.tif waypoints.geojson waypoints_with_elevation.geojson
```

> Here we need a DEM in .tiff format.
4. Create Placemark File (For KMZ File):

```python
python create_placemarks.py \
--waypoints_geojson waypoints_with_elevation.geojson \
--parameters '{"forward_photo_height": 84.0, "side_photo_width": 149.0, "forward_spacing": 20.95, "side_spacing": 44.6, "ground_speed": 10.47, "altitude_above_ground_level": 115}' \
--outfile placemarks.geojson
```

5. Create WMPL Flightplan:

```python
python wpml.py \
--placemark placemarks.geojson \
--outfile flightplan.wpml
```
4 changes: 4 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ nav:
- Code of Conduct: https://docs.hotosm.org/code-of-conduct
- FAQ: about/faq.md
- The Team: about/team.md
- User Manuals:
- Flightplans: manuals/generate-flightplans.md
- Developer Guide:
- Setup: dev/setup.md
- Timeline: timeline.md
2 changes: 1 addition & 1 deletion src/backend/app/db/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class GroundControlPoint(Base):
class DbUserProfile(Base):
__tablename__ = "user_profile"
user_id = cast(str, Column(String, ForeignKey("users.id"), primary_key=True))
role = cast(UserRole, Column(Enum(UserRole), default=UserRole.DRONE_PILOT))
role = cast(list, Column(ARRAY(Enum(UserRole))))
phone_number = cast(str, Column(String))
country = cast(str, Column(String))
city = cast(str, Column(String))
Expand Down
65 changes: 65 additions & 0 deletions src/backend/app/migrations/versions/4ea77c60b715_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
Revision ID: 4ea77c60b715
Revises: b36a13183a83
Create Date: 2024-10-21 04:28:29.415392
"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = "4ea77c60b715"
down_revision: Union[str, None] = "b36a13183a83"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


# Define the new enum type
new_state_enum = sa.Enum(
"UNLOCKED_TO_MAP",
"LOCKED_FOR_MAPPING",
"UNLOCKED_TO_VALIDATE",
"LOCKED_FOR_VALIDATION",
"UNLOCKED_DONE",
"REQUEST_FOR_MAPPING",
"UNFLYABLE_TASK",
"IMAGE_UPLOADED",
"IMAGE_PROCESSED",
"IMAGE_PROCESSING_FAILED",
name="state",
)

old_state_enum = sa.Enum(
"UNLOCKED_TO_MAP",
"LOCKED_FOR_MAPPING",
"UNLOCKED_TO_VALIDATE",
"LOCKED_FOR_VALIDATION",
"UNLOCKED_DONE",
"REQUEST_FOR_MAPPING",
"UNFLYABLE_TASK",
"IMAGE_UPLOADED",
"IMAGE_PROCESSED",
name="state",
)


def upgrade() -> None:
op.execute("ALTER TYPE state ADD VALUE 'IMAGE_PROCESSING_FAILED'")


def downgrade() -> None:
# Rename the enum type
op.execute("ALTER TYPE state RENAME TO state_old")
# Recreate the old enum type
old_state_enum.create(op.get_bind(), checkfirst=False)
# Alter the column to use the old enum type
op.execute(
"ALTER TABLE task_events ALTER COLUMN state TYPE state_old USING state::state_old"
)
# Drop the old enum type
op.execute("DROP TYPE state_old")
Loading

0 comments on commit 90ae194

Please sign in to comment.