Skip to content

Local development and debugging

This page covers working with the CMS SQL models and the MkDocs site in hq/sql_models/ without Docker.

Prerequisites

Requirement Notes
Python 3.12 Matches the hq workspace venv and cms-api.
MySQL (optional) Only needed for live bootstrap/integration tests against a real cms_db.
Workspace layout Run from <workspace>/hq/sql_models/ with hq as the parent package.

Explore the models locally

The models are plain SQLAlchemy declarations under hq/sql_models/. Import them from the workspace root:

cd /path/to/frontstory
export PYTHONPATH=".:${PYTHONPATH:-}"
python -c "from hq.sql_models.template import Template; print(Template.__tablename__)"

No separate install step — hq is a namespace package consumed via PYTHONPATH.

Bootstrap a local cms_db (optional)

To create tables and seed data on a MySQL instance:

cd /path/to/frontstory
export PYTHONPATH=".:${PYTHONPATH:-}"
export CMS_DB_HOST=127.0.0.1 CMS_DB_USER=... CMS_DB_PASSWORD=... CMS_DB_NAME=cms_db
python -m hq.cms.db bootstrap

The bootstrap reads SQLAlchemy metadata from hq.sql_models and applies guarded DDL from hq/sql_models/ddl/. See hq/cms/db/ for connection settings.

Run tests

cd /path/to/frontstory/hq
.venv/bin/pytest tests/test_cms_template_models.py -q
.venv/bin/pytest tests/integration/test_cms_schema_integration.py -q

Integration tests may skip or require a live MySQL depending on env vars. Unit tests under hq/tests/test_cms_*.py run offline.

Build and serve these docs

cd hq/sql_models
python3.12 -m venv .venv_docs && source .venv_docs/bin/activate
pip install -r requirements-docs.txt
mkdocs build --strict
mkdocs serve   # http://127.0.0.1:8000/

mkdocstrings resolves hq.sql_models.template with paths: ["../.."] in mkdocs.yml, so the workspace root must contain the hq/ package (standard org-folder layout).

Debugging tips

Task Approach
Model column mismatch Compare hq/sql_models/template.py with hq/sql_models/ddl/ post-create scripts.
Seed data inspection Read ddl/0015_page_types_and_css_version.sql for real celebrity-v1 descriptors.
mkdocstrings build failure Run from hq/sql_models/; confirm PYTHONPATH includes workspace root.
Schema drift on stage python -m hq.cms.db drift-check (when wired to the target DB).