mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: init migration script from mongodb
This commit is contained in:
parent
99146ca02b
commit
2d822459fb
7 changed files with 307 additions and 8 deletions
|
|
@ -2,10 +2,11 @@ import logging
|
|||
from config.config import get_learnhouse_config
|
||||
from fastapi import FastAPI
|
||||
from sqlmodel import SQLModel, Session, create_engine
|
||||
import motor.motor_asyncio
|
||||
|
||||
learnhouse_config = get_learnhouse_config()
|
||||
engine = create_engine(
|
||||
learnhouse_config.database_config.sql_connection_string, echo=False
|
||||
learnhouse_config.database_config.sql_connection_string, echo=False # type: ignore
|
||||
)
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
|
|
@ -13,9 +14,15 @@ SQLModel.metadata.create_all(engine)
|
|||
async def connect_to_db(app: FastAPI):
|
||||
app.db_engine = engine # type: ignore
|
||||
logging.info("LearnHouse database has been started.")
|
||||
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
# MongoDB for migration purposes
|
||||
# mongodb
|
||||
app.mongodb_client = motor.motor_asyncio.AsyncIOMotorClient( # type: ignore
|
||||
app.learnhouse_config.database_config.mongo_connection_string # type: ignore
|
||||
) # type: ignore
|
||||
app.db = app.mongodb_client["learnhouse"] # type: ignore
|
||||
|
||||
|
||||
def get_db_session():
|
||||
with Session(engine) as session:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue