# Changelog

## 0.10.0 (2026-11-27)
- **MySQL 8 storage** (`WORKSHARE_DATABASE_URL=mysql://...` or `WORKSHARE_DATABASE_URL_FILE`), next to PostgreSQL and
  files. Same tables, same behaviour: one transaction per request before the answer, diff-based writes, reload and
  HTTP 503 on a failed commit, trash, Kavion accounts, audit log. Uses the `mysql2` driver (optional dependency,
  loaded only for mysql:// addresses). TCP, unix socket, TLS (`sslmode`, `sslrootcert`).
- `tools/db-setup.js`: checks the address, login, version (MySQL 8.0+) and creates the tables, with readable hints.
- Installer `--mysql-url-file <file>`: uses the company's MySQL instead of installing PostgreSQL (address stored in
  `/etc/workshare/database-url`, mode 640), installs the driver, checks, moves existing models over.
- Backups: `mysqldump --single-transaction` via `tools/db-dump.js` (password in a private option file, never on the
  command line); restore steps in `deploy/backup.sh`. `update.sh` refreshes the driver.
- Tests: `db-roundtrip-test.js` (database-neutral, proven on PostgreSQL here), `mysql-shape-test.js` (offline checks of
  every MySQL statement), `db-mode-mysql-test.js` (round trip, import and all HTTP suites on a real MySQL).
  GitHub Actions runs them on MySQL 8.0 and 8.4 on every push, plus the smoke test with MySQL storage and a
  mysqldump backup. 1,104 checks here (566 + 538 on PostgreSQL), plus the MySQL suites in CI.

## 0.9.0 (2026-11-27)
- **Kavion login** (`WORKSHARE_KAVION_AUTH` = off | optional | required, default off). The app sends the customer's
  Kavion login (`X-Kavion-Mobile` / `X-Kavion-Token`); the server checks it with parent.globalinfocloud.in
  (`WORKSHARE_KAVION_VERIFY_URL`, default `ReceivedTemplateList`: `status: true` = valid), caches the answer
  (5 min; up to 24 h if Kavion is unreachable), and never stores or logs the token.
- Members are linked to Kavion accounts (an HMAC of the mobile number with `WORKSHARE_ACCOUNT_SECRET`; no mobile
  numbers stored, only a masked hint). A linked member key only works with its own account's login.
- `optional`: a login links the member on first use; key-only requests still work. `required`: every request,
  create, join and event stream needs a valid login (HTTP 401, code 10 otherwise).
- Customers create models with their login instead of the create token, limited by `WORKSHARE_MAX_MODELS_PER_ACCOUNT`
  (20, counted across all workers). Staff can still use the create token.
- `GET /me/models` (Find my models) and `POST /models/:id/rekey` (a key for this device through the login). Up to 5
  device keys per member, so one account on several PCs never locks itself out; an admin key reset revokes them all.
  Joining again with the same account reuses the membership.
- Database migration 3: `members.account_ref`, `accounts` rows (`kavion_user_id` = account key, `hint`).
- `tools/kavion-login-check.js`: checks the real Kavion API with your own login, prints no token / mobile / data.
- The installer creates `WORKSHARE_ACCOUNT_SECRET` once; backups include it. The server refuses to start with the
  login switched on and no proper secret.
- Unity (`UnityClientPatch_0.9/`): `WorkshareKavionLogin` (reads the app's login_data.json), Find my models,
  automatic key renewal through the login.
- Tests: 1,068 checks (549 on files, 519 on PostgreSQL), new `kavion-auth-test.js` against a fake Kavion backend.

## 0.8.0 (2026-11-27)
- **Push updates**: `GET /models/:id/events` (Server-Sent Events). Others' syncs, borrows, requests and admin changes
  reach every open app within ~25 ms instead of the next 10 s poll. Events carry no house data (only "look again,
  newest version N"), are sent only after the commit, work across worker threads, end with `revoked` when a member
  is removed or their key reset, `deleted` on delete, `bye` on restart. Limits per member (2), per model (200), per
  server (`WORKSHARE_MAX_STREAMS`, 5000; 0 = off). Polling stays as the fallback. nginx config updated (no buffering).
- **Trash for deleted models**: `DELETE /models/:id` moves the model to the trash for `WORKSHARE_TRASH_DAYS` (30);
  its admin brings it back with `POST /models/:id/undelete` (versions, members, join code). `?purge=1` deletes for
  good at once. Hourly housekeeping purges expired trash. Trashed models count toward `WORKSHARE_MAX_MODELS`.
  The delete answer stays `true` (apps before 0.8.0 keep working); `state.trashDays` tells the app the period.
- **Durable writes**: every file is fsync'ed before the rename that makes it current, and the folder after
  (`WORKSHARE_FSYNC`, on). Cost measured at ~15 ms per sync.
- **Audit retention**: entries older than `WORKSHARE_AUDIT_DAYS` (365) are removed by housekeeping. File mode now
  writes monthly `audit-YYYY-MM.jsonl` files (mode 600).
- Database migration 2: `models.deleted_at`. Import tool moves trashed models too.
- Smoke test: 20 steps (new: push updates through the real proxy chain; the temporary model is purged).
- Unity client (`UnityClientPatch_0.8/`): live updates with automatic fallback, Restore for deleted models.
- Tests: 908 checks (471 on files, 437 on PostgreSQL), new `safety-test.js` and `events-test.js`.

## 0.7.0 (2026-11-27)
- **PostgreSQL storage** for customer data: models, members, workset and element ownership, element versions, editing
  requests, version history, review submissions, audit log (`WORKSHARE_DATABASE_URL`). House files stay in the data
  folder. Without a database address the server works on files as before.
- Built-in PostgreSQL client (`src/db/pg.js`): unix socket with peer login, SCRAM-SHA-256 (server signature checked),
  MD5, TLS with certificate and host name check. Still no npm dependencies.
- Every change is committed in one transaction before the answer is sent; a failed commit answers HTTP 503 (code 9,
  `Retry-After`), saves nothing and reloads the model. Diff-based writes (one changed element = a few rows).
- Audit log of member and admin actions (actor, client address; never keys). File mode writes `audit.jsonl`.
- `/ready` includes the database. "Last seen" of read-only requests is stored at most once a minute.
- `tools/import-files-to-db.js`: moves existing models into the database (dry run, idempotent, verified read-back).
- Linux installer sets up PostgreSQL (local socket, no password, not on the network) and moves existing models over;
  `--files` keeps file storage. Backups include a `pg_dump`; restore steps in `deploy/backup.sh`.
- Tests: the HTTP, production, version-check and worker-pool suites also run on a real PostgreSQL, plus driver,
  round-trip, outage/rollback, import and backup/restore tests. CI runs them and a smoke test with a PostgreSQL service.

## 0.6.0 (2026-11-21)
- App version check: the Unity app sends `X-App-Version`; `WORKSHARE_MIN_APP_VERSION` blocks too-old apps (HTTP 426,
  code 8, download link), `WORKSHARE_LATEST_APP_VERSION` makes older apps show "update available". `GET /app-version`.
- Access log records each request's app version.
- `tools/smoke-test.js`: two-user check against any running server; also run in CI.

## 0.5.0
- Version and change files stored gzip-compressed (~10x smaller); plain files from older servers still read.
- Retention: newest 50 versions + one per day for 30 days + version 1 + every member's base version are kept; history
  entries and change lists of pruned versions stay. The version limit counts stored versions only.
- Backups include the compressed files.

## 0.4.0
- Worker threads (`WORKSHARE_WORKERS`): each worker owns a share of the models and serializes their requests, so one
  large sync no longer blocks other customers. Crash restart, restart with another worker count.
- `WORKSHARE_MAX_MODELS` configurable.

## 0.3.0
- Production: settings from environment variables, HTTPS through Caddy / nginx, proxy-aware client address,
  rate limits per member (office NAT), gzip in and out, request ids, `/ready`, graceful shutdown, JSON logs.
- Create token / create lock, admin promote / demote, member key reset.
- Linux installer, update with automatic rollback, nightly backups, Docker, systemd, GitHub Actions (CI + manual deploy).

## 0.2.0
- Development server (local only): central model, worksets, borrowing, sync / reload, requests, history, review mode.
