zd / app /db /init_db.py
Juna190825's picture
Create app/db/init_db.py
17755b4 verified
raw
history blame contribute delete
711 Bytes
from sqlalchemy.orm import Session
from app.db import base # noqa
from app.db.session import engine
from app.models.dictionary_entry import DictionaryEntry
def init_db() -> None:
base.Base.metadata.create_all(bind=engine)
# Optional: seed some initial entries
with Session(bind=engine) as db:
if db.query(DictionaryEntry).count() == 0:
sample = DictionaryEntry(
headword_zomi="Tlang",
headword_english="mountain",
part_of_speech="noun",
definition="A large natural elevation of the earth's surface",
translations="mountain,hill",
)
db.add(sample)
db.commit()