Skip to content

Commit

Permalink
Consistency in migration make commands
Browse files Browse the repository at this point in the history
  • Loading branch information
daphnegold committed Aug 15, 2023
1 parent d4a675d commit 482830b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ check: format-check lint test
# Docker starts the image for the DB but it's not quite
# fully ready, so add a 5 second sleep so upgrade doesn't
# fail because the DB hasn't started yet.
init-db: start-db sleep-5 db-upgrade
init-db: start-db sleep-5 db-migrate

start-db:
docker-compose up --detach main-db
Expand All @@ -131,13 +131,13 @@ db-recreate: clean-volumes init-db
alembic_config := ./src/db/migrations/alembic.ini
alembic_cmd := $(PY_RUN_CMD) alembic --config $(alembic_config)

db-upgrade: ## Apply pending migrations to db
db-migrate: ## Apply pending migrations to db
$(PY_RUN_CMD) db-migrate

db-downgrade: ## Rollback last migration in db
db-migrate-down: ## Rollback last migration in db
$(PY_RUN_CMD) db-migrate-down

db-downgrade-all: ## Rollback all migrations
db-migrate-down-all: ## Rollback all migrations
$(PY_RUN_CMD) db-migrate-down-all

check-migrate-msg:
Expand Down
28 changes: 14 additions & 14 deletions documentation/api/database/database-management.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Database Management

- [Basic operations](#basic-operations)
- [Initialize](#initialize)
- [Start](#start)
- [Destroy and reinitialize](#destroy-and-reinitialize)
- [Running migrations](#running-migrations)
- [Creating new migrations](#creating-new-migrations)
- [Multi-head situations](#multi-head-situations)
- [Database Management](#database-management)
- [Basic operations](#basic-operations)
- [Initialize](#initialize)
- [Start](#start)
- [Destroy and reinitialize](#destroy-and-reinitialize)
- [Running migrations](#running-migrations)
- [Creating new migrations](#creating-new-migrations)
- [Multi-head situations](#multi-head-situations)

## Basic operations
### Initialize
Expand All @@ -32,8 +33,8 @@ To clean the database, use the following command:
make db-recreate
```

This will remove _all_ docker project volumes, rebuild the database volume, and
run all pending migrations. Once completed, only the database container will be
This will remove _all_ docker project volumes, rebuild the database volume, and
run all pending migrations. Once completed, only the database container will be
running. Simply run `make start` to bring up all other project containers.

## Running migrations
Expand All @@ -43,9 +44,9 @@ against your db so it has all the required tables. `make init` does this, but if
needing to work with the migrations directly, some common commands:

```sh
make db-upgrade # Apply pending migrations to db
make db-downgrade # Rollback last migration to db
make db-downgrade-all # Rollback all migrations
make db-migrate # Apply pending migrations to db
make db-migrate-down # Rollback last migration to db
make db-migrate-down-all # Rollback all migrations
```

## Creating new migrations
Expand All @@ -54,7 +55,7 @@ If you've changed a python object model, auto-generate a migration file for the

```sh
$ make db-migrate-create MIGRATE_MSG="<brief description of change>"
$ make db-upgrade
$ make db-migrate
```

<details>
Expand Down Expand Up @@ -121,4 +122,3 @@ Or, if you wish to avoid creating extra migrations, you can manually adjust
the `down_revision` of one of the migrations to point to the other one. This
is also the necessary approach if the migrations need to happen in a defined
order.

0 comments on commit 482830b

Please sign in to comment.