mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: migrate orgconfig to 1.1
This commit is contained in:
parent
1423e4c432
commit
b425f3a6bd
5 changed files with 51 additions and 1 deletions
14
apps/api/migrations/orgconfigs/v1_1.py
Normal file
14
apps/api/migrations/orgconfigs/v1_1.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
def migrate_to_v1_1(v1_config):
|
||||
# Start by copying the existing configuration
|
||||
v1_1_config = v1_config.copy()
|
||||
|
||||
# Update the config version
|
||||
v1_1_config["config_version"] = "1.1"
|
||||
|
||||
# Add the new 'cloud' object at the end
|
||||
v1_1_config['cloud'] = {
|
||||
"plan": "free",
|
||||
"custom_domain": False
|
||||
}
|
||||
|
||||
return v1_1_config
|
||||
|
|
@ -83,12 +83,18 @@ class OrgGeneralConfig(BaseModel):
|
|||
color: str = "normal"
|
||||
watermark: bool = True
|
||||
|
||||
# Cloud
|
||||
class OrgCloudConfig(BaseModel):
|
||||
plan: Literal["free", "standard", "pro"] = "free"
|
||||
custom_domain: bool = False
|
||||
|
||||
|
||||
# Main Config
|
||||
class OrganizationConfigBase(BaseModel):
|
||||
config_version: str = "1.0"
|
||||
config_version: str = "1.1"
|
||||
general: OrgGeneralConfig
|
||||
features: OrgFeatureConfig
|
||||
cloud: OrgCloudConfig
|
||||
|
||||
|
||||
class OrganizationConfig(SQLModel, table=True):
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from fastapi import APIRouter, Depends
|
|||
from sqlmodel import Session, select
|
||||
from config.config import get_learnhouse_config
|
||||
from migrations.orgconfigs.v0tov1 import migrate_v0_to_v1
|
||||
from migrations.orgconfigs.v1_1 import migrate_to_v1_1
|
||||
from src.core.events.database import get_db_session
|
||||
from src.db.organization_config import OrganizationConfig
|
||||
|
||||
|
|
@ -32,3 +33,22 @@ async def migrate(
|
|||
db_session.commit()
|
||||
|
||||
return {"message": "Migration successful"}
|
||||
|
||||
|
||||
@router.post("/migrate_orgconfig_v1_to_v1.1")
|
||||
async def migratev1_1(
|
||||
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_to_v1_1(orgConfig.config)
|
||||
|
||||
db_session.add(orgConfig)
|
||||
db_session.commit()
|
||||
|
||||
return {"message": "Migration successful"}
|
||||
|
|
@ -14,6 +14,7 @@ from src.db.organization_config import (
|
|||
CourseOrgConfig,
|
||||
DiscussionOrgConfig,
|
||||
MemberOrgConfig,
|
||||
OrgCloudConfig,
|
||||
OrgFeatureConfig,
|
||||
OrgGeneralConfig,
|
||||
OrganizationConfig,
|
||||
|
|
@ -350,6 +351,10 @@ def install_create_organization(org_object: OrganizationCreate, db_session: Sess
|
|||
collaboration=CollaborationOrgConfig(enabled=True, limit=0),
|
||||
api=APIOrgConfig(enabled=True, limit=0),
|
||||
),
|
||||
cloud=OrgCloudConfig(
|
||||
plan='free',
|
||||
custom_domain=False
|
||||
)
|
||||
)
|
||||
|
||||
org_config = json.loads(org_config.json())
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ from src.db.organization_config import (
|
|||
CourseOrgConfig,
|
||||
DiscussionOrgConfig,
|
||||
MemberOrgConfig,
|
||||
OrgCloudConfig,
|
||||
OrgFeatureConfig,
|
||||
OrgGeneralConfig,
|
||||
OrganizationConfig,
|
||||
|
|
@ -178,6 +179,10 @@ async def create_org(
|
|||
collaboration=CollaborationOrgConfig(enabled=True, limit=0),
|
||||
api=APIOrgConfig(enabled=True, limit=0),
|
||||
),
|
||||
cloud=OrgCloudConfig(
|
||||
plan='free',
|
||||
custom_domain=False
|
||||
)
|
||||
)
|
||||
|
||||
org_config = json.loads(org_config.json())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue