Skip to content

Commit

Permalink
Merge pull request #6 from bacpop/bacpop-197-species-old-projects
Browse files Browse the repository at this point in the history
Bacpop-197 Add Data migration to set default species to pneumo
  • Loading branch information
absternator authored Oct 9, 2024
2 parents 33528d5 + 5fb934f commit 4bd8747
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/Pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ on:
push:
branches:
- main
- master
- "bacpop-*"
pull_request:
branches:
- main
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,14 @@ We have one copy of `beebop` deployed:
* server: `beebop.dide.ic.ac.uk`
* config: `prod.yml`
* command to run: `./beebop start prod`

### Running data migrations

All data migrations are stored in the migration folder in the server. The naming convention is `YYYYMMDDHHMMSS_<migration_name>.sh`.

To run them, you can use the following command from the **root**, and replace the migration file with the one you want to run:

```bash
docker exec beebop-redis bash -c "$(cat ./migrations/<migration_file>)"

```
16 changes: 16 additions & 0 deletions migrations/20241008_default_species.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -eu

# This script will set the species field to "Streptococcus pneumoniae" for all projects in the database

projectKeys=$(redis-cli --scan | grep -E ^beebop:project:[a-zA-Z0-9]+$)


echo "Number of found projects: $(echo "$projectKeys" | wc -w)"

for key in $projectKeys; do
currentSpecies=$(redis-cli HGET "$key" species)
if [ -z "$currentSpecies" ]; then
redis-cli HSET "$key" species "Streptococcus pneumoniae"
fi
done
2 changes: 1 addition & 1 deletion src/beebop_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def api_configure(container, cfg):
print("[api] Storage db already exists, doing nothing")
else:
print("[api] Downloading storage database")
args = ["./scripts/download_db"]
args = ["./scripts/download_databases"]
mounts = [docker.types.Mount("/beebop/storage",
cfg.volumes["storage"])]
container.client.containers.run(str(cfg.api_ref), args, mounts=mounts,
Expand Down

0 comments on commit 4bd8747

Please sign in to comment.