mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2026-01-17 11:40:39 +03:00
add migrations
This commit is contained in:
@@ -14,16 +14,16 @@ app.include_router(stuff_router)
|
||||
app.include_router(nonsense_router)
|
||||
|
||||
|
||||
async def start_db():
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
await engine.dispose()
|
||||
# async def start_db():
|
||||
# async with engine.begin() as conn:
|
||||
# await conn.run_sync(Base.metadata.create_all)
|
||||
# await engine.dispose()
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
logger.info("Starting up...")
|
||||
await start_db()
|
||||
# await start_db()
|
||||
|
||||
|
||||
@app.on_event("shutdown")
|
||||
|
||||
@@ -10,6 +10,9 @@ from the_app.models.base import Base
|
||||
|
||||
class Nonsense(Base):
|
||||
__tablename__ = "nonsense"
|
||||
__table_args__ = (
|
||||
{"schema": "the_others"},
|
||||
)
|
||||
id = Column(UUID(as_uuid=True), unique=True, default=uuid.uuid4, autoincrement=True)
|
||||
name = Column(String, nullable=False, primary_key=True, unique=True)
|
||||
description = Column(String, nullable=False)
|
||||
@@ -18,6 +21,7 @@ class Nonsense(Base):
|
||||
self.name = name
|
||||
self.description = description
|
||||
|
||||
|
||||
@classmethod
|
||||
async def find(cls, db_session: AsyncSession, name: str):
|
||||
"""
|
||||
|
||||
@@ -10,6 +10,9 @@ from the_app.models.base import Base
|
||||
|
||||
class Stuff(Base):
|
||||
__tablename__ = "stuff"
|
||||
__table_args__ = (
|
||||
{"schema": "the_others"},
|
||||
)
|
||||
id = Column(UUID(as_uuid=True), unique=True, default=uuid.uuid4, autoincrement=True)
|
||||
name = Column(String, nullable=False, primary_key=True, unique=True)
|
||||
description = Column(String, nullable=False)
|
||||
|
||||
Reference in New Issue
Block a user