diff --git a/apps/data_handler/README.md b/apps/data_handler/README.md index 37e0d922..104144b8 100644 --- a/apps/data_handler/README.md +++ b/apps/data_handler/README.md @@ -95,27 +95,10 @@ Go to bash docker-compose exec backend bash ``` -## Running Migration Command: -1. Go to root folder `derisk-research` - -### Prepare the Environment -2. Run up db in docker: -``` -docker-compose -f devops/dev/docker-compose.db.yaml up -d --remove-orphans -``` -3. Navigate to the `data_hander` directory: -``` -cd apps/data_handler -``` -4. Install all dependencies: -``` -poetry install -``` -5. Go back to apps folder: -``` -cd .. -``` -5. Run migration command: -``` -alembic -c data_handler/alembic.ini revision --autogenerate -m "your migration message here" +## How to run migration command: +1. Set up `.env.dev` into `derisk-research/apps/data_handler` +2. Go back to `derisk-research/apps` directory +3. Then run bash script to migrate: +```bash +bash data_handler/migrate.sh ``` diff --git a/apps/data_handler/migrate.sh b/apps/data_handler/migrate.sh new file mode 100644 index 00000000..f6a5482e --- /dev/null +++ b/apps/data_handler/migrate.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +if [ "$(basename $(dirname $(pwd)))/$(basename $(pwd))" != "derisk-research/apps" ]; then + echo "Current path to run this script should be in the \"derisk-research/apps\" directory" + exit 1 +fi + +echo "Running DB in Docker container..." +docker-compose -f ../devops/dev/docker-compose.db.yaml --env-file data_handler/.env.dev up -d --remove-orphans + +echo "Installing Poetry globally..." +curl -sSL https://install.python-poetry.org | python3 - + +echo "Installing all dependencies for \"data_handler\" with Poetry..." +poetry -C data_handler install + +echo "Activating environment..." +poetry -C data_handler shell + +echo "Applying latest existing migrations..." +poetry -C data_handler run alembic -c data_handler/alembic.ini upgrade head + +echo "Generating new migration..." +poetry -C data_handler run alembic -c data_handler/alembic.ini revision --autogenerate -m "Migration" diff --git a/apps/data_handler/poetry.lock b/apps/data_handler/poetry.lock index b39c2d49..09ec9f72 100644 --- a/apps/data_handler/poetry.lock +++ b/apps/data_handler/poetry.lock @@ -4219,4 +4219,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = ">=3.11,<3.13" -content-hash = "38a0fe7b97c28ce7fc382279757601e566119e4c677f778949299b4173716cc6" +content-hash = "38a0fe7b97c28ce7fc382279757601e566119e4c677f778949299b4173716cc6" \ No newline at end of file