mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2026-01-17 11:40:39 +03:00
add alembic migrations
This commit is contained in:
@@ -8,22 +8,15 @@ from the_app.utils import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
app = FastAPI(title="Stuff And Nonsense API", version="0.3")
|
||||
app = FastAPI(title="Stuff And Nonsense API", version="0.4")
|
||||
|
||||
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()
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
logger.info("Starting up...")
|
||||
await start_db()
|
||||
|
||||
|
||||
@app.on_event("shutdown")
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# for Alembic and unit tests
|
||||
from the_app.models.stuff import * # noqa
|
||||
from the_app.models.nonsense import * # noqa
|
||||
from the_app.models.shakespeare import * # noqa
|
||||
@@ -18,7 +18,7 @@ metadata = Base.metadata
|
||||
|
||||
class Character(Base):
|
||||
__tablename__ = "character"
|
||||
__table_args__ = (PrimaryKeyConstraint("id", name="character_pkey"), {"schema": "shakespeare_i_like"})
|
||||
__table_args__ = (PrimaryKeyConstraint("id", name="character_pkey"), {"schema": "shakespeare"})
|
||||
|
||||
id = Column(String(32))
|
||||
name = Column(String(64), nullable=False)
|
||||
@@ -32,7 +32,7 @@ class Character(Base):
|
||||
|
||||
class Wordform(Base):
|
||||
__tablename__ = "wordform"
|
||||
__table_args__ = (PrimaryKeyConstraint("id", name="wordform_pkey"), {"schema": "shakespeare_i_like"})
|
||||
__table_args__ = (PrimaryKeyConstraint("id", name="wordform_pkey"), {"schema": "shakespeare"})
|
||||
|
||||
id = Column(Integer)
|
||||
plain_text = Column(String(64), nullable=False)
|
||||
@@ -43,7 +43,7 @@ class Wordform(Base):
|
||||
|
||||
class Work(Base):
|
||||
__tablename__ = "work"
|
||||
__table_args__ = (PrimaryKeyConstraint("id", name="work_pkey"), {"schema": "shakespeare_i_like"})
|
||||
__table_args__ = (PrimaryKeyConstraint("id", name="work_pkey"), {"schema": "shakespeare"})
|
||||
|
||||
id = Column(String(32))
|
||||
title = Column(String(32), nullable=False)
|
||||
@@ -68,7 +68,7 @@ class Chapter(Base):
|
||||
UniqueConstraint(
|
||||
"work_id", "section_number", "chapter_number", name="chapter_work_id_section_number_chapter_number_key"
|
||||
),
|
||||
{"schema": "shakespeare_i_like"},
|
||||
{"schema": "shakespeare"},
|
||||
)
|
||||
|
||||
id = Column(Integer)
|
||||
@@ -104,7 +104,7 @@ class Paragraph(Base):
|
||||
),
|
||||
ForeignKeyConstraint(["work_id"], ["shakespeare.work.id"], name="paragraph_work_id_fkey"),
|
||||
PrimaryKeyConstraint("id", name="paragraph_pkey"),
|
||||
{"schema": "shakespeare_i_like"},
|
||||
{"schema": "shakespeare"},
|
||||
)
|
||||
|
||||
id = Column(Integer)
|
||||
|
||||
Reference in New Issue
Block a user