Files
coder/coderd/database/migrations/000617_connection_logs_method_app_name.up.sql
T
Ehab Younes 5b060beeb1 feat: separate connection log methods from app names (#30466)
Connection logs now record how a connection was made
(`connection_method`) separately from which app made it (`app_name`).
Storage, the HTTP API, search filters, and the UI move to the new
fields. Legacy agent reports and the deprecated `type` field keep
working.

- Add `connection_method` (`ssh`, `reconnecting_pty`, `workspace_app`,
  `port_forwarding`, `tunnel`) and optional `app_name` and
  `app_display_name` to `GET /api/v2/connectionlog`. Deprecate `type`
  and make it a plain string in the API and the Go SDK.
- Add `method:` and repeatable `app:` search filters. `type:` keeps its
  old results but can't be combined with the new filters.
- Replace the Type menu with a Method menu, show the app next to the
  method in each row, and warn when a filter uses `type:`.
- Change the Active SSH connections preset to `method:ssh`, so it also
  includes SSH sessions from VS Code and JetBrains apps.
- Generate `codersdk.ConnectionLogMethod` from the database enum with
  `typegen dbenums`.
- Migration 000617 rewrites `connection_logs` under an ACCESS EXCLUSIVE
  lock, which takes about 50 seconds for 10 million rows. `vscode` and
  `jetbrains` rows become `ssh` rows with that app. Rolling back folds
  apps into the old types and loses per-app names.
- Document the new filters and how to replace each `type:` value.

Closes #27412
2026-10-12 15:56:40 +03:00

27 lines
1.1 KiB
SQL

CREATE TYPE connection_log_method AS ENUM (
'ssh', 'reconnecting_pty', 'workspace_app', 'port_forwarding', 'tunnel'
);
-- Convert both columns in one rewrite under an ACCESS EXCLUSIVE lock.
ALTER TABLE connection_logs
ALTER COLUMN slug_or_port TYPE text USING (
CASE
WHEN type::text IN ('vscode', 'jetbrains') THEN type::text
WHEN type::text IN ('ssh', 'reconnecting_pty', 'tunnel') THEN NULL
ELSE NULLIF(slug_or_port, '')
END
),
ALTER COLUMN type TYPE connection_log_method USING (
CASE
WHEN type::text IN ('vscode', 'jetbrains') THEN 'ssh'
ELSE type::text
END
)::connection_log_method;
ALTER TABLE connection_logs RENAME COLUMN type TO connection_method;
ALTER TABLE connection_logs RENAME COLUMN slug_or_port TO app_name_or_port;
DROP TYPE connection_type;
COMMENT ON COLUMN connection_logs.connection_method IS 'How the connection was established.';
COMMENT ON COLUMN connection_logs.app_name_or_port IS 'Self-reported name of the connecting application for SSH and reconnecting PTY; destination slug or port for workspace apps and port forwarding. Null when absent.';