Move to asyncpg instead of psycopg#29
Conversation
|
Looks fine, the bogus |
|
|
||
| [tool.taskipy.tasks] | ||
| lint = "pre-commit run --all-files" | ||
| revision = "docker-compose exec web alembic revision --autogenerate -m" No newline at end of file |
There was a problem hiding this comment.
This doesn't work if we are running the database locally (without docker).
There was a problem hiding this comment.
It works, if you add the database url of your local database to an '.env' file , hence the alembic environment uses the pydantic config.
There was a problem hiding this comment.
How would it work? It runs docker-compose exec, I am not runnning with docker...
There was a problem hiding this comment.
Oh, yes sorry.
However, I think if you run your database locally ( which is way harder than just issuing a simple command, but let's go with the example) you can just simply do poetry run alembic revision [...] (and of course setting the env vars) The PR and this task was meant to solve the problem of creating migrations while using docker, that's why the migrations folder was mounted.
There was a problem hiding this comment.
We can just do it like how we do it on site,
revision = "alembic revision --autogenerate -m"
docker-revision = "docker-compose exec web alembic revision --autogenerate -m"There was a problem hiding this comment.
Yea, this is purely for a docker setup. I would expect most people developing this to be running in docker, due to the psql need. Rather than running their own psql server.
So I'd suggest keeping this as the default and then having local-revision as the alternative for people who want to run psql locally.
Since pydantic is not async, it cannot do database validation with asyncpg. This should instead be deferred to the routes to validate.
8b94b2b to
ce348a5
Compare
Akarys42
left a comment
There was a problem hiding this comment.
Approved by the Python Discord DevOps:tm: Team:tm:
b597cdc to
ce348a5
Compare
This PR moves our migrations to asyncpg, adds a docker volume for migrations and adds a helper task for generating those migrations.
Simply by running
poetry run task revision "Migration message here."while the docker containers are running, a migration will be generated.Something to keep in mind is that, now that we are using asyncpg, no database validation can be run within Pydantic models. This now needs to be deferred to the routes that need that validation instead.