diff --git a/apps/api/migrations/orgconfigs/v0tov1.py b/apps/api/migrations/orgconfigs/orgconfigs_migrations.py similarity index 76% rename from apps/api/migrations/orgconfigs/v0tov1.py rename to apps/api/migrations/orgconfigs/orgconfigs_migrations.py index b010340f..f9d8efe0 100644 --- a/apps/api/migrations/orgconfigs/v0tov1.py +++ b/apps/api/migrations/orgconfigs/orgconfigs_migrations.py @@ -67,3 +67,33 @@ def migrate_v0_to_v1(v0_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 \ No newline at end of file diff --git a/apps/api/migrations/orgconfigs/v1_1.py b/apps/api/migrations/orgconfigs/v1_1.py deleted file mode 100644 index e3a3fabb..00000000 --- a/apps/api/migrations/orgconfigs/v1_1.py +++ /dev/null @@ -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 diff --git a/apps/api/src/routers/dev.py b/apps/api/src/routers/dev.py index 5ce8c1b8..52472875 100644 --- a/apps/api/src/routers/dev.py +++ b/apps/api/src/routers/dev.py @@ -1,8 +1,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 migrations.orgconfigs.orgconfigs_migrations import migrate_to_v1_1, migrate_to_v1_2, migrate_v0_to_v1 from src.core.events.database import get_db_session from src.db.organization_config import OrganizationConfig @@ -51,4 +50,22 @@ async def migratev1_1( db_session.add(orgConfig) db_session.commit() + 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"} \ No newline at end of file