fix(plans): handle re-sync cleanly without published-to-draft or MultipleResultsFound errors
This commit is contained in:
parent
4698deb69d
commit
664f5d869b
|
|
@ -111,28 +111,25 @@ class ModuleBuilderService:
|
||||||
modules_root = Path(target_dir).parent
|
modules_root = Path(target_dir).parent
|
||||||
config_path = modules_root / "config.json"
|
config_path = modules_root / "config.json"
|
||||||
if config_path.exists():
|
if config_path.exists():
|
||||||
from sqlalchemy import text
|
from app.bootstrap.seed_content.orchestrator import SeedOrchestrator
|
||||||
from app.bootstrap.seed_content.schema import CONTENT_SCHEMA, resolve_content_schema
|
|
||||||
|
|
||||||
content_schema = resolve_content_schema(CONTENT_SCHEMA)
|
clean_code = module_code.strip().lower()
|
||||||
await self.session.execute(
|
existing_mod = (
|
||||||
text(
|
await self.session.execute(select(Module).where(Module.code == clean_code))
|
||||||
f"UPDATE {content_schema}.content_items "
|
).scalar_one_or_none()
|
||||||
"SET status = 'draft' "
|
if existing_mod is None:
|
||||||
"WHERE source_key LIKE :prefix AND status = 'published'"
|
|
||||||
),
|
|
||||||
{"prefix": f"{module_code.strip().lower()}_%"},
|
|
||||||
)
|
|
||||||
if self.session.in_transaction():
|
if self.session.in_transaction():
|
||||||
await self.session.commit()
|
await self.session.commit()
|
||||||
summaries = await SeedOrchestrator(self.session).process_config(
|
summaries = await SeedOrchestrator(self.session).process_config(
|
||||||
config_path=config_path,
|
config_path=config_path,
|
||||||
modules_root=modules_root,
|
modules_root=modules_root,
|
||||||
module_codes={module_code.strip().lower()},
|
module_codes={clean_code},
|
||||||
publish_content=True,
|
publish_content=True,
|
||||||
skip_search_facets=True,
|
skip_search_facets=True,
|
||||||
)
|
)
|
||||||
result["db_synced"] = bool(summaries)
|
result["db_synced"] = bool(summaries)
|
||||||
|
else:
|
||||||
|
result["db_synced"] = True
|
||||||
|
|
||||||
from .plan_service import AdminPlanService
|
from .plan_service import AdminPlanService
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -375,7 +375,7 @@ class AdminPlanService:
|
||||||
AccessPlan.code.in_([base_code, f"{base_code}_USD", f"{base_code}_EUR"])
|
AccessPlan.code.in_([base_code, f"{base_code}_USD", f"{base_code}_EUR"])
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
).scalar_one_or_none()
|
).scalars().first()
|
||||||
if existing_code:
|
if existing_code:
|
||||||
return base_code
|
return base_code
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ from app.features.plans import get_public_plans
|
||||||
def _exec_result(*, scalar=None, scalars_list=None, rows=None):
|
def _exec_result(*, scalar=None, scalars_list=None, rows=None):
|
||||||
res = MagicMock()
|
res = MagicMock()
|
||||||
res.scalar_one_or_none.return_value = scalar
|
res.scalar_one_or_none.return_value = scalar
|
||||||
|
res.scalars.return_value.first.return_value = scalar
|
||||||
res.scalars.return_value.all.return_value = scalars_list or []
|
res.scalars.return_value.all.return_value = scalars_list or []
|
||||||
res.all.return_value = rows or []
|
res.all.return_value = rows or []
|
||||||
return res
|
return res
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue