add migrations

This commit is contained in:
Jakub Miazek
2022-05-22 15:07:40 +02:00
parent d7ca8bdf51
commit 4658c4c223
9 changed files with 214 additions and 7 deletions

View File

@@ -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")

View File

@@ -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):
"""

View File

@@ -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)