-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: configure sqlalchemy and add alembic migrations #12
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI падает
Коммиты названы как попало, последний вообще merge...
История должна быть линейной. Переделай коммиты так, чтобы они были атомарными.
pyproject.toml
Outdated
@@ -14,6 +14,7 @@ sqlalchemy = "^2.0.22" | |||
alembic = "^1.12.1" | |||
celery = "^5.3.4" | |||
python-dotenv = "^1.0.0" | |||
psycopg2-binary = "^2.9.5" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Есть 3 версия и она поддерживается
app/db/postgres/session.py
Outdated
|
||
settings = get_settings() | ||
|
||
engine = create_engine(url=settings.postgres_dsn, echo=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
он точно сможет создать engine от настройки не строки?
зачем echo=True в продакшене?
app/db/postgres/__init__.py
Outdated
@@ -0,0 +1,3 @@ | |||
from sqlalchemy.orm import declarative_base | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мне не нравится идея складывать основные объекты для работы с базой данных в db/postgres, потому что никакой другой базы, кроме этой быть не может.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я бы сложил все, что нужно для работы с базой данных, сессии, миграции, зависимости и прочее в app/db
Модели же должны лежать в отдельных папках связанных с конкретными функциаональными зависимостями (т.е не в app/db)
app/db/alembic.ini
Outdated
# are written from script.py.mako | ||
# output_encoding = utf-8 | ||
|
||
sqlalchemy.url = %(DB_URL)s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут не пользуются капсом, это настройка, а не env переменная
Makefile
Outdated
@@ -1,5 +1,14 @@ | |||
.PHONY: env install-deps up worker app init lint test | |||
|
|||
include .env |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Эта строчка все ломает при чистой установке. В том числе и CI.
Makefile
Outdated
include .env | ||
|
||
args := $(wordlist 2, 100, $(MAKECMDGOALS)) | ||
ifndef args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MESSAGE никогда не используется
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем эта строка?
Makefile
Outdated
@@ -16,6 +25,18 @@ up: | |||
(trap 'docker compose -f dev-docker-compose.yaml down' INT; \ | |||
docker compose -f dev-docker-compose.yaml up --build --force-recreate --remove-orphans) | |||
|
|||
## Open database with docker-compose | |||
open_db: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open_db: | |
open-db: |
Makefile
Outdated
@@ -1,5 +1,14 @@ | |||
.PHONY: env install-deps up worker app init lint test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сюда не добавил новые таргеты
Возможно стоит переложить alembic.ini в /settings |
Configure SQLAlchemy
Add alembic migrations
Add instructions in the makefile to start the database and run migrations