mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
wip: add more schemas
This commit is contained in:
parent
732b14866c
commit
b4dcc14749
15 changed files with 319 additions and 8 deletions
|
|
@ -2,27 +2,47 @@ import logging
|
|||
from fastapi import FastAPI
|
||||
import motor.motor_asyncio
|
||||
from sqlmodel import Field, SQLModel, Session, create_engine
|
||||
from src.rewrite.services.db import users
|
||||
|
||||
engine = create_engine('postgresql://learnhouse:learnhouse@db:5432/learnhouse', echo=True)
|
||||
from src.rewrite.services.db import (
|
||||
user_organizations,
|
||||
users,
|
||||
roles,
|
||||
organization_settings,
|
||||
organizations,
|
||||
courses,
|
||||
course_authors,
|
||||
chapters,
|
||||
activities,
|
||||
course_chapters,
|
||||
chapter_activities,
|
||||
blocks,
|
||||
collections,
|
||||
)
|
||||
|
||||
engine = create_engine(
|
||||
"postgresql://learnhouse:learnhouse@db:5432/learnhouse", echo=True
|
||||
)
|
||||
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
|
||||
# mongodb
|
||||
app.mongodb_client = motor.motor_asyncio.AsyncIOMotorClient( # type: ignore
|
||||
app.learnhouse_config.database_config.mongodb_connection_string) # type: ignore
|
||||
app.db = app.mongodb_client["learnhouse"] # type: ignore
|
||||
app.learnhouse_config.database_config.mongodb_connection_string # type: ignore
|
||||
) # type: ignore
|
||||
app.db = app.mongodb_client["learnhouse"] # type: ignore
|
||||
|
||||
|
||||
def get_db_session():
|
||||
with Session(engine) as session:
|
||||
yield session
|
||||
|
||||
|
||||
async def close_database(app: FastAPI):
|
||||
app.mongodb_client.close() # type: ignore
|
||||
logging.info("LearnHouse has been shut down.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue