feat: add orgconfig 1.2 migration

This commit is contained in:
swve 2024-11-26 19:05:44 +01:00
parent 6d668006f8
commit 2e618d9c5a
3 changed files with 49 additions and 16 deletions

View file

@ -67,3 +67,33 @@ def migrate_v0_to_v1(v0_config):
} }
return v1_config return v1_config
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
def migrate_to_v1_2(v1_1_config):
v1_2_config = v1_1_config.copy()
v1_2_config['config_version'] = '1.2'
# Enable payments for everyone
v1_2_config['features']['payments']['enabled'] = True
# Only delete stripe_key if it exists
if 'stripe_key' in v1_2_config['features']['payments']:
del v1_2_config['features']['payments']['stripe_key']
return v1_2_config

View file

@ -1,14 +0,0 @@
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

View file

@ -1,8 +1,7 @@
from fastapi import APIRouter, Depends from fastapi import APIRouter, Depends
from sqlmodel import Session, select from sqlmodel import Session, select
from config.config import get_learnhouse_config from config.config import get_learnhouse_config
from migrations.orgconfigs.v0tov1 import migrate_v0_to_v1 from migrations.orgconfigs.orgconfigs_migrations import migrate_to_v1_1, migrate_to_v1_2, 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.core.events.database import get_db_session
from src.db.organization_config import OrganizationConfig from src.db.organization_config import OrganizationConfig
@ -52,3 +51,21 @@ async def migratev1_1(
db_session.commit() db_session.commit()
return {"message": "Migration successful"} return {"message": "Migration successful"}
@router.post("/migrate_orgconfig_v1_to_v1.2")
async def migratev1_2(
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_2(orgConfig.config)
db_session.add(orgConfig)
db_session.commit()
return {"message": "Migration successful"}