Rename the user's name to display name and let users edit it
Database · PostgreSQL · intermediate · modification
Renames the user's `name` to `display_name` and lets users change it. `migrations/0043_rename_users_name.sql` renames the column. `app/users.py` reads and writes `display_name` and adds `PATCH /api/me`, which validates the new name and returns the updated profile. `tests/test_profile.py` (new) covers reading the profile, updating the name and the empty and too-long 422 cases.
Accounts API: FastAPI 0.115 on Python 3.12 with psycopg 3.2 (plain SQL, no ORM; `app.db.pool` is a `psycopg_pool.ConnectionPool`, at most 10 connections per pod, and `pool.connection()` commits when its block exits without an error), PostgreSQL 16, one primary. `users` (migration `0001`, unchanged: `id bigint` identity primary key, `email text NOT NULL UNIQUE`, `name text NOT NULL`, `created_at timestamptz NOT NULL DEFAULT now()`) holds about 60,000 rows. Rows are inserted only by `create_user`, which the existing signup flow (`app/signup.py`, unchanged) calls positionally as `create_user(conn, email, name)` inside its transaction; before this PR nothing updated a user's name. `app.auth.current_user_id` (existing) is a FastAPI dependency that returns the signed-in user's id or answers 401, and `app/main.py` (existing) includes `users.router`. Migrations are plain SQL files in `migrations/`, applied in order by the existing runner `python -m app.migrate` (unchanged): each pending file runs as one transaction with `SET LOCAL lock_timeout = '5s'` (retried up to 3 times on a lock timeout) and is recorded in `schema_migrations` in the same transaction. Deploys: the pipeline runs the runner against the production database first; if it fails, the deploy stops. It then replaces the 8 API pods one at a time, each new pod taking traffic once it is healthy, which takes about ten minutes, and until a pod is replaced it keeps serving on the previous release. The web and mobile clients do not call `PATCH /api/me` until a later client release, after this rollout. Removing a column is done in a separate cleanup release once no running code uses it (team convention). The test suite (`tests/conftest.py`, existing) builds a fresh test database from all migrations and provides `db` (an autocommit connection to it, `users` emptied before each test) and `client_for(user_id)` (a test client signed in as that user).
Requirements
- The `users.name` column becomes `display_name`: invoicing adds a separate legal name next quarter, and `name` on its own would be ambiguous. `create_user` and `GET /api/me` use `display_name`; the response keeps its field `name`, so the web and mobile clients are unchanged.
- New `PATCH /api/me` with body `{"name": "..."}` lets the signed-in user change their display name. Surrounding whitespace (characters with the Unicode `White_Space` property) is stripped; the name must then be 1 to 50 characters, counted as Unicode code points the way Python's `len()` counts them, with no control characters (U+0000 to U+001F, U+007F to U+009F), otherwise 422. It answers with the updated profile, the same shape as `GET /api/me`.
- This release goes out with the usual rolling deploy (see context). No request may fail because of the deploy, including the requests that pods on the previous release serve until they are replaced.
- The PR's tests run with the existing pytest setup.
Files touched
- migrations/0043_rename_users_name.sql
- app/users.py
- tests/test_profile.py