mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
fix: remove mongo
This commit is contained in:
parent
573b9a43fc
commit
ac70cb534d
4 changed files with 13 additions and 22 deletions
|
|
@ -46,7 +46,7 @@ class HostingConfig(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class DatabaseConfig(BaseModel):
|
class DatabaseConfig(BaseModel):
|
||||||
mongodb_connection_string: Optional[str]
|
sql_connection_string: Optional[str]
|
||||||
|
|
||||||
|
|
||||||
class LearnHouseConfig(BaseModel):
|
class LearnHouseConfig(BaseModel):
|
||||||
|
|
@ -105,8 +105,8 @@ def get_learnhouse_config() -> LearnHouseConfig:
|
||||||
env_allowed_origins = env_allowed_origins.split(",")
|
env_allowed_origins = env_allowed_origins.split(",")
|
||||||
env_allowed_regexp = os.environ.get("LEARNHOUSE_ALLOWED_REGEXP")
|
env_allowed_regexp = os.environ.get("LEARNHOUSE_ALLOWED_REGEXP")
|
||||||
env_self_hosted = os.environ.get("LEARNHOUSE_SELF_HOSTED")
|
env_self_hosted = os.environ.get("LEARNHOUSE_SELF_HOSTED")
|
||||||
env_mongodb_connection_string = os.environ.get(
|
env_sql_connection_string = os.environ.get(
|
||||||
"LEARNHOUSE_MONGODB_CONNECTION_STRING"
|
"LEARNHOUSE_SQL_CONNECTION_STRING"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Sentry Config
|
# Sentry Config
|
||||||
|
|
@ -166,9 +166,9 @@ def get_learnhouse_config() -> LearnHouseConfig:
|
||||||
)
|
)
|
||||||
|
|
||||||
# Database config
|
# Database config
|
||||||
mongodb_connection_string = env_mongodb_connection_string or yaml_config.get(
|
sql_connection_string = env_sql_connection_string or yaml_config.get(
|
||||||
"database_config", {}
|
"database_config", {}
|
||||||
).get("mongodb_connection_string")
|
).get("sql_connection_string")
|
||||||
|
|
||||||
# Sentry config
|
# Sentry config
|
||||||
# check if the sentry config is provided in the YAML file
|
# check if the sentry config is provided in the YAML file
|
||||||
|
|
@ -210,7 +210,7 @@ def get_learnhouse_config() -> LearnHouseConfig:
|
||||||
content_delivery=content_delivery,
|
content_delivery=content_delivery,
|
||||||
)
|
)
|
||||||
database_config = DatabaseConfig(
|
database_config = DatabaseConfig(
|
||||||
mongodb_connection_string=mongodb_connection_string
|
sql_connection_string=sql_connection_string
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create LearnHouseConfig object
|
# Create LearnHouseConfig object
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ hosting_config:
|
||||||
domain: learnhouse.app
|
domain: learnhouse.app
|
||||||
ssl: true
|
ssl: true
|
||||||
allowed_origins:
|
allowed_origins:
|
||||||
- http://localhost:3000
|
- http://localhost:3000
|
||||||
- http://localhost:3001
|
- http://localhost:3001
|
||||||
cookies_config:
|
cookies_config:
|
||||||
domain: ".localhost"
|
domain: ".localhost"
|
||||||
allowed_regexp: '\b((?:https?://)[^\s/$.?#].[^\s]*)\b'
|
allowed_regexp: '\b((?:https?://)[^\s/$.?#].[^\s]*)\b'
|
||||||
|
|
@ -25,4 +25,4 @@ hosting_config:
|
||||||
endpoint_url: ""
|
endpoint_url: ""
|
||||||
|
|
||||||
database_config:
|
database_config:
|
||||||
mongodb_connection_string: mongodb://learnhouse:learnhouse@mongo:27017/
|
sql_connection_string: postgresql://learnhouse:learnhouse@db:5432/learnhouse
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import logging
|
import logging
|
||||||
|
from config.config import get_learnhouse_config
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
import motor.motor_asyncio
|
|
||||||
from sqlmodel import SQLModel, Session, create_engine
|
from sqlmodel import SQLModel, Session, create_engine
|
||||||
|
|
||||||
|
learnhouse_config = get_learnhouse_config()
|
||||||
engine = create_engine(
|
engine = create_engine(
|
||||||
"postgresql://learnhouse:learnhouse@db:5432/learnhouse", echo=False
|
learnhouse_config.database_config.sql_connection_string, echo=False
|
||||||
)
|
)
|
||||||
SQLModel.metadata.create_all(engine)
|
SQLModel.metadata.create_all(engine)
|
||||||
|
|
||||||
|
|
@ -16,12 +16,6 @@ async def connect_to_db(app: FastAPI):
|
||||||
|
|
||||||
SQLModel.metadata.create_all(engine)
|
SQLModel.metadata.create_all(engine)
|
||||||
|
|
||||||
# mongodb
|
|
||||||
app.mongodb_client = motor.motor_asyncio.AsyncIOMotorClient( # 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():
|
def get_db_session():
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
|
|
@ -29,6 +23,5 @@ def get_db_session():
|
||||||
|
|
||||||
|
|
||||||
async def close_database(app: FastAPI):
|
async def close_database(app: FastAPI):
|
||||||
app.mongodb_client.close() # type: ignore
|
|
||||||
logging.info("LearnHouse has been shut down.")
|
logging.info("LearnHouse has been shut down.")
|
||||||
return app
|
return app
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from sqlalchemy import JSON, Column
|
|
||||||
from sqlmodel import Field, SQLModel
|
|
||||||
from sqlalchemy import BigInteger, Column, ForeignKey
|
|
||||||
from sqlmodel import Field, SQLModel
|
from sqlmodel import Field, SQLModel
|
||||||
|
from sqlalchemy import BigInteger, ForeignKey, JSON, Column
|
||||||
|
|
||||||
|
|
||||||
class TrailStepTypeEnum(str, Enum):
|
class TrailStepTypeEnum(str, Enum):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue