mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: migrate orgconfig model across the app
This commit is contained in:
parent
6485b6e1bb
commit
28a2456d69
12 changed files with 467 additions and 363 deletions
|
|
@ -1,5 +1,13 @@
|
|||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, Depends
|
||||
from h11 import Request
|
||||
from sqlmodel import Session, select
|
||||
from config.config import get_learnhouse_config
|
||||
from migrations.orgconfigs.v0tov1 import migrate_v0_to_v1
|
||||
from src.core.events.database import get_db_session
|
||||
from src.db.organization_config import OrganizationConfig
|
||||
from src.db.organizations import Organization
|
||||
from src.db.users import PublicUser
|
||||
from src.security.auth import get_current_user
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
|
@ -11,4 +19,20 @@ async def config():
|
|||
return config.dict()
|
||||
|
||||
|
||||
@router.post("/migrate_orgconfig_v0_to_v1")
|
||||
async def migrate(
|
||||
db_session: Session = Depends(get_db_session),
|
||||
):
|
||||
"""
|
||||
Migrate organization config from v0 to v1
|
||||
"""
|
||||
statement = select(OrganizationConfig)
|
||||
result = db_session.exec(statement)
|
||||
|
||||
for orgConfig in result:
|
||||
orgConfig.config = migrate_v0_to_v1(orgConfig.config)
|
||||
|
||||
db_session.add(orgConfig)
|
||||
db_session.commit()
|
||||
|
||||
return {"message": "Migration successful"}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ def check_limits_and_config(db_session: Session, organization: Organization):
|
|||
)
|
||||
|
||||
# Check if the Organizations has AI enabled
|
||||
if org_config.config["AIConfig"]["enabled"] == False:
|
||||
if org_config.config["features"]["ai"]["enabled"] == False:
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="Organization has AI disabled",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue