Skip to content

Commit

Permalink
Merge pull request #349 from vitaliypopel/feature/migrations-script
Browse files Browse the repository at this point in the history
feature: migrations script
  • Loading branch information
djeck1432 authored Nov 29, 2024
2 parents 11d21ef + 2cef8fe commit 8764daf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
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.

0 comments on commit 8764daf

Please sign in to comment.