Работа с alembic и БД в docker, вопросы с poetry, linux и общие вопросы про python
Теги:
Database and alembic
How to autogenerate and apply migrations with alembic when the database runs in a container
services:
db:
image: postgres
ports:
- "5432:5432"
environment:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=database
networks:
- app-network
app:
build: .
command: bash -c "cd app/database && alembic upgrade head && cd ../.. && python app/main.py"
volumes:
- .:/code
ports:
- "5000:5000"
depends_on:
- db
networks:
- app-network
networks:
app-network:
Change default postgres port
>export PGHOST=localhost
>export PGPORT=5432
Multiple databases in docker and docker-compose
version: '3.0'
services:
db:
image: postgres
environment:
- POSTGRES_DB
- POSTGRES_USER
- POSTGRES_PASSWORD
ports:
- ${POSTGRES_DEV_PORT}:5432
volumes:
- app-volume:/var/lib/postgresql/data
db-test:
image: postgres
environment:
- POSTGRES_DB
- POSTGRES_USER
- POSTGRES_PASSWORD
ports:
- ${POSTGRES_TEST_PORT}:5432
# Notice I don't even use a volume here since I don't care to persist test data between runs
volumes:
app-volume: #
[docker]
Container exited with code 0 when run from docker-compose
#!/bin/sh
# ... do other pre-launch setup ...
# Run the CMD
exec "$@"
[poetry]
Transfer dependency to –dev in poetry
You can move the corresponding line in the pyproject.toml from the [tool.poetry.dependencies] section to [tool.poetry.dev-dependencies] by hand and run poetry lock –no-update afterwards.
You can also poetry add -D dep
and poetry remove dep
in either order. Just be sure to use the same version constraint. Poetry stops/warns you if you use different constraints as they’d conflict.
[notes/linux]
How to generate a random string
openssl rand -base64 12
openssl rand -hex 12