Closed shpilevskiyevgeniy closed 9 months ago
Hi, and thanks for raising this issue. How do you run your migrations?
alembic revision and alembic upgrade "head"
Are you sure that you have a database running on localhost? Can you connect to it?
Yes, I can join. I am starting your project from scratch, adding a new model, what further commands do I need to do to migrate this model to the database? In the project description, this is the command: alembic upgrade "head" but it throws above error.
This command only works if you have a running and accessible database.
You can check whether postgresql is running by trying to connecting to it directly using postgresql CLI.
psql -h localhost
This template doesn't deploy a database on your machine. But it generates docker-compose configuration that have a database inside.
Instead of running these commands in your shell, you can run them inside docker containers where database is 100% accessible.
docker compose run --rm -it --build -v $(pwd):/app/src/ api bash
This command will start a docker-compose and will create additional container with configuration as your api service and will spawn a shell here, so you can run commands. Or instead of opening bash, you can run alembic command directly.
docker compose run --rm -it --build -v $(pwd):/app/src/ api alembic upgrade "head"
This template starts a database postgres:13.8-bullseye in docker, how do I make migrations to it?
If you don't have a database running on your machine on port 5432 you can modify docker-compose configuration by adding
ports:
- 5432:5432
to your database service.
Or you can get it's IP address and set it in your .env
file. To get IP addresses of all containers, run this command:
docker compose ps -q | xargs docker inspect -f "{{.Name}} {{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}"
After you have the IP of the database, set it in your .env
file.
Still do not understand. You have a migrator in your project that does migrations, it works, but for example, I created a model, then changed its field and I need to make a revision, but when I make a new revision so that the migrator sends it to the database, I get an error: alembic revision --autogenerate -m "update model User"
raise OSError(err, f'Connect call failed {address}') ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 5432)
I didn’t change anything in the project, I just built it and launched it, these containers started up for me:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 65bdbd6ffd0b caireer_hr:latest "taskiq worker caire…" 7 minutes ago Up 7 minutes caireer_hr_taskiq-worker_1 4bb251580513 caireer_hr:latest "/usr/local/bin/pyth…" 7 minutes ago Up 7 minutes 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp caireer_hr_api_1 b7b3c3554e5b bitnami/kafka:3.2.0 "/opt/bitnami/script…" 7 minutes ago Up 7 minutes (healthy) 9092/tcp caireer_hr_kafka_1 aa5610d5eb9a bitnami/zookeeper:3.7.1 "/opt/bitnami/script…" 7 minutes ago Up 7 minutes (healthy) 2181/tcp, 2888/tcp, 3888/tcp, 8080/tcp caireer_hr_zookeeper_1 86fe85285aac bitnami/redis:6.2.5 "/opt/bitnami/script…" 7 minutes ago Up 7 minutes (healthy) 6379/tcp caireer_hr_redis_1 3583c6a15351 postgres:13.8-bullseye "docker-entrypoint.s…" 7 minutes ago Up 7 minutes (healthy) 5432/tcp caireer_hr_db_1
How can I make revisions out of the box in your project, and then migrations?
As I said before. Add ports in docker-compose if you want postgresql be accessible on your localhost.
By default it creates containers that ARE NOT ACCESSIBLE from your local machine. To open some ports, please modify docker-compose.
Closed due to inactivity. The problem seems to be solved.
Error:
raise OSError(err, f'Connect call failed {address}') ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 5432)