Open tickets list for the support inbox

Database · PostgreSQL · beginner · modification

Adds the endpoint behind the new support inbox. `queries/open_tickets.sql` (new) selects the workspace's open and pending tickets, latest activity first, capped at 100. `app/tickets.py` maps `GET /open` on the existing tickets router, above the `/{ticket_id}` route so `open` is never read as a ticket id, and returns the rows. `tests/test_open_tickets.py` (new) checks the status filter and the order, and that another workspace's tickets stay out of the list.

Helpdesk API on PostgreSQL 16 and Python 3.12 (FastAPI 0.115, psycopg 3.2 with dict rows, plain SQL, no ORM). Existing and unchanged: `tickets` (`id bigserial` primary key, `workspace_id bigint NOT NULL`, `subject text NOT NULL`, `status text NOT NULL` with a CHECK that it is one of `open`, `pending`, `solved`, `closed`, `updated_at timestamptz NOT NULL`) holds the tickets of every workspace, about 2,000 workspaces and 3 million tickets, with an index on `(workspace_id, updated_at DESC, id DESC)`. `app.db.get_conn` yields a connection from the app's pool for the request. `app.queries.q(name)` returns the text of `queries/<name>.sql`, read once and cached; queries use psycopg named placeholders (`%(workspace_id)s`), so values are always sent as parameters. `app.auth.require_member` answers 401 or 403 itself unless the signed-in user is a member of the workspace in the path. `queries/ticket_by_id.sql` selects one ticket by `workspace_id` and `id`. Tests run with pytest against a fresh test database built from `migrations/`; `tests/conftest.py` provides `db` (a connection to that database, `tickets` emptied before each test) and `client_for(workspace_id)` (a FastAPI `TestClient` signed in as a member of that workspace only). The inbox page (web app) ships separately and only reads this endpoint.

Requirements

Files touched

Review this PR

Database practice