# RootHVN rollback

## Before cutover

- Record the production code archive checksum and database backup checksum.
- Record the RootHVN patch commit and patch archive checksum.
- Confirm the database backup can be decompressed and that its expected tables are present.
- Keep the former `roothvn-planner.php` untouched until the replacement passes production smoke tests.
- The shared bootstrap redirects that legacy planner to `roothvn.php` only after the complete new schema signature is present. A rollback may remove that redirect only after confirming the preserved legacy table signature is compatible; the old file itself is not a database rollback.

## Code rollback

Restore only the files listed in the release manifest from the verified pre-cutover archive. Remove only release-created RootHVN files listed in that same manifest. Do not recursively replace `content/uploads`, configuration, license files, caches or third-party vendor trees.

Course originals are intentionally outside the document root in the install-specific `.roothvn-private-<install>/course-media` directory. Disabling or rolling back RootHVN code makes these files unreachable but does not delete them. Preserve that directory during incident review; delete an asset only after its `rh_course_media` record, replacement history and backup have been reconciled.

## Database rollback

RootHVN migrations create namespaced `rh_*` tables. A code rollback can leave those tables dormant for investigation. Do not drop them during an incident response. Restore the database backup only when data integrity requires it and after preserving an incident copy of the current database.

When the installer encounters the exact retired planner signatures, it creates `rh_legacy_habits_pre_foundation`, `rh_legacy_habit_days_pre_foundation`, and `rh_legacy_notebooks_pre_foundation` safety tables before changing a legacy column. It verifies source/backup row counts and completion-copy counts. The legacy habit-days foreign key is read from `information_schema`, dropped only for the referenced-column rename, then recreated against `habit_id`; constraint identifiers must pass a strict identifier allowlist. Keep the safety tables through acceptance and incident review. A rollback must restore from the verified safety tables or the full database backup; never drop the migrated tables merely to make the old planner load.

## Module rollback

The owner can put a RootHVN module into `maintenance` without deleting its data. For a utility-wide incident, restore the previous controller/theme files and route signed-in users to the preserved planner only after confirming its schema compatibility.

Recipe-created grocery lists are ordinary private `rh_items`/`rh_subtasks` rows linked through `source_type = 'recipe_grocery'`. A code rollback makes conversion unavailable but must not delete or reset those user-owned lists or their completion state.

Astronomy preferences are ordinary `rh_preferences` rows under the `astronomy` key. Older code ignores them. A rollback may remove the vendored browser library and sky UI but must preserve the preference row for a later forward repair.

Public Summit event responses live only in `rh_calendar_event_keys` and `rh_calendar_event_rsvps`. Disable `event_rsvp` first during an incident. A code rollback may leave both additive tables dormant; do not delete member responses or public events while investigating. Public Summit events remain ordinary `rh_items` rows and must be preserved with the Calendar data.

For a Summit incident, disable or maintain the `cohorts` module first. Do not delete the linked native Sngine Groups: their posts, membership rows and invitations are user data. Keep `rh_cohort_sngine_links`, membership audits, invitation audits and settings audits for reconciliation. A previous code release will ignore the additive `0004` tables safely.

The staging-only Summit discussion overlay can be restored from `roothvn-summit-discussion-v14-rollback-20261129.zip` after verifying SHA-256 `2fadb4e30a3a3e0e6083f080543d25ecb75aed9e670ff24a983cd006159a36f0`. The staging-only unlink-control overlay can be restored from `roothvn-summit-unlink-v15-rollback-20261129.zip` after verifying SHA-256 `8eedd9aa381e1aa257a5ccae2e3e29758e420a1d6cc86886380af32ce4cf4762`. Extract either archive only over the staging document root, never production, and repeat the module-gate/Summit contracts plus the affected browser path afterward. These code rollbacks must not delete the retained course, native group, memberships, posts or audit rows.

## Migration rollback

- Never edit an applied migration to force a checksum match.
- `0003_learning_engine.sql` is immutable. Summit integration is additive in `0004_cohort_module.sql`.
- If `0004` fails before its version row is recorded, correct the staging cause and rerun it; its schema statements are repeatable and do not alter Sngine tables.
- `0005_course_flashcards.sql` adds only the namespaced checkpoint-card table. A prior code release ignores it safely; preserve its rows during forward repair or rollback.
- `0006_calendar_depth.sql` only adds the `emoji` value to RootHVN's namespaced item-type enum. Older code ignores those rows; preserve them and keep Calendar disabled while rolling back to a build that cannot edit that type.
- `0007_calendar_event_rsvp.sql` adds only namespaced event-key/response tables and one default-disabled module row. Earlier code ignores those tables; preserve their rows for forward repair.
- `0008_focus_publishing_forums.sql` enables Focus and the guarded Publishing hub, and creates a RootHVN forum section only when the native forum table is completely empty. A rollback should disable Focus/Publishing through the audited owner controls if required; preserve all forum rows and member-created discussions rather than deleting them.
- Do not manually insert a migration version or checksum.
- Restore the verified pre-cutover database only when forward repair is unsafe, after preserving the failed database for investigation.

## Evidence to retain

- release/rollback file manifests and checksums
- PHP lint, migration rehearsal and clean build output
- owner/admin/member access matrix
- offline restart/replay/conflict results
- reminder schedule/update/cancel/cleanup results
- physical-device/PWA acceptance results
- exact rollback actions and timestamps
- Summit native-group link, membership-count and invitation reconciliation results

## Staging rehearsal retained on 2026-11-29

The owner-only v17 candidate verifier created a private mode-0600 manifest and
backup outside the document root, restored 125 pre-candidate files, removed two
candidate-only paths, and left the namespaced database and retained Course and
Summit fixtures untouched. The rolled-back Today page rendered normally.
Re-extracting the frozen 127-file archive then passed 127/127 byte hashes,
34/34 host PHP lints on PHP 8.4.28, all required extension checks and fresh
Today/Learn/Summits browser smoke checks. Production still requires a new
production-specific code/database backup and restore rehearsal immediately
before an explicitly authorized publication.
