Decouple PageConfig cross-domain queries + merge cart into db_market

PageConfig (db_blog) decoupling:
- Blog: add page-config, page-config-by-id, page-configs-batch data endpoints
- Blog: add update-page-config action endpoint for events payment admin
- Cart: hydrate_page, resolve_page_config, get_cart_grouped_by_page all
  fetch PageConfig from blog via HTTP instead of direct DB query
- Cart: check_sumup_status auto-fetches page_config from blog when needed
- Events: payment routes read/write PageConfig via blog HTTP endpoints
- Order model: remove cross-domain page_config ORM relationship (keep column)

Cart + Market DB merge:
- Cart tables (cart_items, orders, order_items) moved into db_market
- Cart app DATABASE_URL now points to db_market (same bounded context)
- CartItem.product / CartItem.market_place relationships work again
  (same database, no cross-domain join issues)
- Updated split-databases.sh, init-databases.sql, docker-compose.yml

Ghost sync fix:
- Wrap PostAuthor/PostTag delete+re-add in no_autoflush block
- Use synchronize_session="fetch" to keep identity map consistent
- Prevents query-invoked autoflush IntegrityError on composite PK

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-25 11:59:35 +00:00
parent 3be287532d
commit 3053cb321d
15 changed files with 270 additions and 96 deletions

View File

@@ -1,12 +1,13 @@
from __future__ import annotations
from types import SimpleNamespace
from quart import (
render_template, make_response, Blueprint, g, request
)
from sqlalchemy import select
from shared.models.page_config import PageConfig
from shared.infrastructure.data_client import fetch_data
from shared.infrastructure.actions import call_action
from shared.browser.app.authz import require_admin
from shared.browser.app.utils.htmx import is_htmx_request
@@ -19,20 +20,23 @@ def register():
return {}
async def _load_payment_ctx():
"""Load PageConfig SumUp data for the current page."""
"""Load PageConfig SumUp data for the current page (from blog)."""
post = (getattr(g, "post_data", None) or {}).get("post", {})
post_id = post.get("id")
if not post_id:
return {}
pc = (await g.s.execute(
select(PageConfig).where(PageConfig.container_type == "page", PageConfig.container_id == post_id)
)).scalar_one_or_none()
raw_pc = await fetch_data(
"blog", "page-config",
params={"container_type": "page", "container_id": post_id},
required=False,
)
pc = SimpleNamespace(**raw_pc) if raw_pc else None
return {
"sumup_configured": bool(pc and pc.sumup_api_key),
"sumup_merchant_code": (pc.sumup_merchant_code or "") if pc else "",
"sumup_checkout_prefix": (pc.sumup_checkout_prefix or "") if pc else "",
"sumup_configured": bool(pc and getattr(pc, "sumup_api_key", None)),
"sumup_merchant_code": (getattr(pc, "sumup_merchant_code", None) or "") if pc else "",
"sumup_checkout_prefix": (getattr(pc, "sumup_checkout_prefix", None) or "") if pc else "",
}
@bp.get("/")
@@ -48,31 +52,27 @@ def register():
@bp.put("/")
@require_admin
async def update_sumup(**kwargs):
"""Update SumUp credentials for this page."""
"""Update SumUp credentials for this page (writes to blog's db_blog)."""
post = (getattr(g, "post_data", None) or {}).get("post", {})
post_id = post.get("id")
if not post_id:
return await make_response("Post not found", 404)
pc = (await g.s.execute(
select(PageConfig).where(PageConfig.container_type == "page", PageConfig.container_id == post_id)
)).scalar_one_or_none()
if pc is None:
pc = PageConfig(container_type="page", container_id=post_id, features={})
g.s.add(pc)
await g.s.flush()
form = await request.form
merchant_code = (form.get("merchant_code") or "").strip()
api_key = (form.get("api_key") or "").strip()
checkout_prefix = (form.get("checkout_prefix") or "").strip()
pc.sumup_merchant_code = merchant_code or None
pc.sumup_checkout_prefix = checkout_prefix or None
payload = {
"container_type": "page",
"container_id": post_id,
"sumup_merchant_code": merchant_code,
"sumup_checkout_prefix": checkout_prefix,
}
if api_key:
pc.sumup_api_key = api_key
payload["sumup_api_key"] = api_key
await g.s.flush()
await call_action("blog", "update-page-config", payload=payload)
ctx = await _load_payment_ctx()
html = await render_template("_types/payments/_main_panel.html", **ctx)