You've already forked RekomenciBackend
fix(): add flush to uow.add to ensure db sync
This commit is contained in:
@@ -10,8 +10,9 @@ class DefaultUnitOfWork(UnitOfWork):
|
|||||||
self._session = session
|
self._session = session
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def add(self, *entities: Any) -> None:
|
async def add(self, *entities: Any) -> None:
|
||||||
self._session.add_all(entities)
|
self._session.add_all(entities)
|
||||||
|
await self._session.flush()
|
||||||
|
|
||||||
@override
|
@override
|
||||||
async def commit(self) -> None:
|
async def commit(self) -> None:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from typing import Any, Protocol
|
|||||||
|
|
||||||
class UnitOfWork(Protocol):
|
class UnitOfWork(Protocol):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def add(self, *entities: Any) -> None:
|
async def add(self, *entities: Any) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ class UserSignUpInteractor:
|
|||||||
|
|
||||||
response = UserSignUpResponse(access_token=crypted_access_token)
|
response = UserSignUpResponse(access_token=crypted_access_token)
|
||||||
|
|
||||||
self.unit_of_work.add(user, access_token)
|
for entity in (user, access_token): # preserve creation order
|
||||||
|
await self.unit_of_work.add(entity)
|
||||||
|
|
||||||
await self.unit_of_work.commit()
|
await self.unit_of_work.commit()
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: ad80834713c3
|
||||||
|
Revises:
|
||||||
|
Create Date: 2025-11-12 00:03:31.080899
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = 'ad80834713c3'
|
||||||
|
down_revision: Union[str, Sequence[str], None] = None
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
"""Upgrade schema."""
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('users',
|
||||||
|
sa.Column('id', sa.UUID(), nullable=False),
|
||||||
|
sa.Column('email', sa.String(), nullable=False),
|
||||||
|
sa.Column('hashed_password', sa.String(), nullable=False),
|
||||||
|
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.UniqueConstraint('email')
|
||||||
|
)
|
||||||
|
op.create_table('access_token',
|
||||||
|
sa.Column('id', sa.UUID(), nullable=False),
|
||||||
|
sa.Column('user_id', sa.UUID(), nullable=False),
|
||||||
|
sa.Column('revoked', sa.Boolean(), nullable=False),
|
||||||
|
sa.Column('expires_in', sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
"""Downgrade schema."""
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_table('access_token')
|
||||||
|
op.drop_table('users')
|
||||||
|
# ### end Alembic commands ###
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import selectors
|
|
||||||
import sys
|
import sys
|
||||||
from collections.abc import AsyncIterator
|
from collections.abc import AsyncIterator
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import asyncio
|
|
||||||
|
|
||||||
from dishka import FromDishka
|
from dishka import FromDishka
|
||||||
from dishka.integrations.fastapi import DishkaRoute
|
from dishka.integrations.fastapi import DishkaRoute
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
|||||||
Reference in New Issue
Block a user