Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: migrations script #349

Merged
29 changes: 6 additions & 23 deletions apps/data_handler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
24 changes: 24 additions & 0 deletions apps/data_handler/migrate.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion apps/data_handler/poetry.lock

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