alembic 1.1

This commit is contained in:
2025-10-01 12:24:09 +03:00
parent 5deffdfcf1
commit 28a853c865
3 changed files with 6 additions and 39 deletions

2
run.py
View File

@@ -3,7 +3,7 @@ from server.backend import endpoints# импортируем FastAPI экзем
import asyncio import asyncio
from server.database import db from server.database import db
if __name__ == "__main__": if __name__ == "__main__":
asyncio.run(db.main()) #asyncio.run(db.main())
uvicorn.run( uvicorn.run(
"server.backend.endpoints:api", "server.backend.endpoints:api",
host="127.0.0.1", host="127.0.0.1",

View File

@@ -1,32 +0,0 @@
"""add description2 to users
Revision ID: a29593b8fb22
Revises: 4182906fdea3
Create Date: 2025-09-30 15:18:33.377319
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'a29593b8fb22'
down_revision: Union[str, Sequence[str], None] = '4182906fdea3'
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.add_column('users', sa.Column('description2', sa.String(), nullable=True))
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('users', 'description2')
# ### end Alembic commands ###

View File

@@ -39,11 +39,10 @@ class User(Base):
created_at = Column(DateTime(timezone=True), server_default=func.now()) created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now()) updated_at = Column(DateTime(timezone=True), onupdate=func.now())
last_login = Column(DateTime(timezone=True)) last_login = Column(DateTime(timezone=True))
description2 = Column(String, nullable=True)
async def init_db(): # async def init_db():
async with async_engine.begin() as conn: # async with async_engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all) # await conn.run_sync(Base.metadata.create_all)
async def create_user(user_info): async def create_user(user_info):
async with AsyncSessionLocal() as session: async with AsyncSessionLocal() as session:
new_user = User(email=user_info.email, description=user_info.description, activated=user_info.activated, password=hash_password(user_info.password)) new_user = User(email=user_info.email, description=user_info.description, activated=user_info.activated, password=hash_password(user_info.password))
@@ -95,5 +94,5 @@ async def reset_user(user_info):
await session.commit() await session.commit()
return user return user
return None return None
async def main(): # async def main():
await init_db() # await init_db()