# Company design rollout release and rollback

Prepared for #2957. This document authorizes no deployment or production activation. No production cohort has been selected. The source revision and reviewed evidence must be filled from the accepted local commit before release.

## Behavior

Every company starts with `companies.design_v2_enabled = 0`. Ordinary users and resellers follow their effective company's design. During an admin/superadmin company override, the administrator's own persisted company flag always selects presentation, in both directions, regardless of the selected company's flag or global staff switch. The selected company still supplies all customer data and authorization context; this does not enable its background or newsletter-editor rollout. Outside an override, enabled companies include permitted staff pages, and `/admin/*` plus staff SMTP also retain the independent global staff opt-in. Config/database emergency stops and missing rollout state still resolve to legacy before these choices.

Staff use `/admin/company/{id}/edit` to select a company's design, and `/admin/design-rollout` for staff pages, emergency disable and recent audit history. These controls require an actual admin/superadmin role, CSRF, a boolean and a reason. The company flag is excluded from mass assignment. Writes and actor/previous/new/reason audit records commit atomically. No new optional customer workflow was introduced: both complete interfaces use the existing shared, authorized controllers and records. Manual routes stay retired in both interfaces.

Public authentication uses one production-style username/email login. Public transactional/authentication output and sent email rendering stay shared. Presentation selection cannot be chosen in a cookie or query parameter. Request-local selection, variant-separated view lookup and cleared translation groups prevent view/translation state crossing requests. Authenticated HTML is private/no-store. Missing rollout schema or missing global settings resolve to legacy.

## Approval-gated release sequence

1. Obtain approval for the exact reviewed source revision, complete diff, production host, release path and owner. Freshly identify deployed revision/runtime, untracked files, existing production database/migration state and service ownership. Preserve other work. Use the documented Git-bundle/SFTP delivery route; no server GitHub credential substitution.
2. Record previous release path/revision and verify recoverable code, assets and database backups, with restore owner and evidence. Preserve the rollout settings/audit rows if this is an update. Verify destination space and isolate the release build.
3. Build with the repository lockfile (`npm ci`, `npm run production`) in the approved release environment; `tools/release/build-assets.sh` and `install-assets.sh` do this and the install (docs/ops/asset-release.md). Include `public/mix-manifest.json`, the current bundles and `public/js/legacy/agreement.js`, plus the tracked legacy SMS stylesheet. Do not overwrite a partial asset set. Verify every same-origin CSS/JS URL from ordinary legacy and v2 responses returns 200 and the correct MIME type.
4. Apply only the additive migration `2026_10_16_000001_create_company_design_rollout.php` using the established deployment runner/account, with `php artisan migrate --path=database/migrations/2026_10_16_000001_create_company_design_rollout.php --force`. Verify MySQL's applied migration record, both settings values false, zero enabled companies, and the audit table. Do not activate a company as part of migration. Do not run `config:cache`; Nuhet has a documented historical SMS failure from that operation.
5. Switch the approved release atomically under the existing release runbook, without service reload/restart outside its approval. Verify ordinary/repeat login, existing companies' legacy pages and assets, staff controls, security refusals and manual 404s. Record actual requests, terminal results and previous release identity. No sending worker/scheduler test or real messages are implied.
6. Activate only separately named, approved companies through staff controls with a reason. Capture audit IDs, check a second user in the selected company and an unselected company, effective-company switching, direct URLs and the recipient/newsletter workflows. Staff pages remain independently off unless explicitly approved.

## Immediate disable

On `/admin/design-rollout`, enable **Emergency stop for all new designs**. Its persisted `emergency_disabled = 1` overrides company and staff selections on subsequent requests. Controls remain available in the legacy interface. For operational recovery, the existing environment/config release mechanism can set `NUHET_DESIGN_V2_DISABLED=true`; that brake takes priority over database selections. Apply environment changes only within the approved release procedure. Do not introduce config caching or an unapproved restart.

For one company, set its company design back to **Legacy design**. This preserves its data and audit history. Disabling the global stop restores the individual selections; review them before lifting it.

## Code rollback

First disable v2, preserve audit/settings evidence and confirm ordinary legacy requests. Restore the recorded previous code and complete matching asset set using the approved atomic release mechanism. Leave the additive flag/settings/audit schema in place: older code ignores it, and this preserves the activation history. Do not execute migration `down()` in production as an automatic rollback. Dropping those columns/tables destroys rollout history and requires separate approval, backup and restore validation.

Changing the design or rolling back presentation code does not undo customer data edits, scheduled work or messages already sent. Restoring production customer records is a separate operation. Verify the old release's behavior and assets from ordinary URLs after rollback.
