Service for integrating external APIs
- Create
.env
from.env.example
. Fill in variables in file. - Run commands.
> docker-compose build
> docker-compose up -d
Configuration is done via environment variables:
- SECRET_KEY - A secret key for a particular. This is used to provide cryptographic signing, and should be set to a unique, unpredictable value.
- API_ROOT_PATH - path prefix
- DB_URL - "postgres://:@:/<db_name>" (or sqlite://:memory: for in-memory use)
- GS_ACCOUNT_KEY - Google cloud base64-encoded service account json key
(for postgresql in docker-compose)
- POSTGRES_DB - postgres db
- POSTGRES_USER - postgres user
- POSTGRES_PASSWORD - postgres password
- POSTGRES_HOST - postgres host
- POSTGRES_PORT - postgres port
Background: aerich calculates differences between
current application models and last models
applied to the database based on the field content
in the aerich
table
The problem: table content
is populated with description of
current models each time you run upgrade. So, recreating
content
based on migration history only is not possible.
You have to manually rollback git to specific version
to calculate diffs
Solutions:
- (Easy way) Connect to production database and create migrations based on actual live latest database state. This will require you to know production (or sandbox) database credentials
- (Hard way) Reproduce production database state locally and create migrations
For the ease of use, aerich commands were implemented in cdm-api cli, so that they run in the same context as application itself
Also, aerich migration code has a bug that we've manually fixed in aerich_monkeypatch.py
Before you begin You might need to genrate initial migration if it's your first migration
- Run
DB_URL=... city-search db-migrate-initial
The easy way
- Run
DB_URL=... city-search db-migrate <migration name>
Where DB_URL value you can find in vault
The hard way
- Rollback to current production version
- Initialize empty database locally in the same database (postresql/mysql/etc..) as production database
- Upgrade database locally to production version (this populates
content
field inaerich
table used to calculate diffs) - Fetch latest version
- Generate migrations
- Done, enjoy your migrations script