mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: init new self-hosting method
This commit is contained in:
parent
d5791d99d5
commit
d1fde17220
11 changed files with 663 additions and 492 deletions
37
apps/api/src/core/events/autoinstall.py
Normal file
37
apps/api/src/core/events/autoinstall.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
from sqlalchemy import create_engine
|
||||
from sqlmodel import SQLModel, Session, select
|
||||
|
||||
from cli import install
|
||||
from config.config import get_learnhouse_config
|
||||
from src.db.organizations import Organization
|
||||
|
||||
|
||||
def auto_install():
|
||||
# Get the database session
|
||||
learnhouse_config = get_learnhouse_config()
|
||||
engine = create_engine(
|
||||
learnhouse_config.database_config.sql_connection_string, echo=False, pool_pre_ping=True # type: ignore
|
||||
)
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
db_session = Session(engine)
|
||||
|
||||
orgs = db_session.exec(select(Organization)).all()
|
||||
|
||||
if len(orgs) == 0:
|
||||
print("No organizations found. Starting auto-installation 🏗️")
|
||||
install(short=True)
|
||||
|
||||
if orgs:
|
||||
for org in orgs:
|
||||
default_org = db_session.exec(select(Organization).where(Organization.slug == 'default')).first()
|
||||
|
||||
if not default_org:
|
||||
print("No default organization found. Starting auto-installation 🏗️")
|
||||
install(short=True)
|
||||
|
||||
else:
|
||||
print("Organizations found. Skipping auto-installation 🚀")
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
from typing import Callable
|
||||
from fastapi import FastAPI
|
||||
from config.config import LearnHouseConfig, get_learnhouse_config
|
||||
from src.core.events.autoinstall import auto_install
|
||||
from src.core.events.content import check_content_directory
|
||||
from src.core.events.database import close_database, connect_to_db
|
||||
from src.core.events.logs import create_logs_dir
|
||||
|
|
@ -25,6 +26,9 @@ def startup_app(app: FastAPI) -> Callable:
|
|||
# Create content directory
|
||||
await check_content_directory()
|
||||
|
||||
# Check if auto-installation is needed
|
||||
auto_install()
|
||||
|
||||
return start_app
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue