You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Migration: add environment and session_id to events, last_resolved_at to issues.
2
+
# environment -- first-class column so operators can filter by deployment target
3
+
# without relying on tags JSONB. Partial index covers only rows where the SDK
4
+
# sends the field; rows from older SDKs are excluded from the index automatically.
5
+
# session_id -- correlates events from the same SDK session for session-context
6
+
# queries without decomposing user_context JSONB on every read path.
7
+
# last_resolved_at -- records the timestamp of the last manual resolve so
8
+
# regression detection (resolved -> unresolved flip) can fire regression alerts.
9
+
10
+
pub fn up(pool :: PoolHandle) -> Int ! String do
11
+
Pool.execute(pool, "ALTER TABLE events ADD COLUMN IF NOT EXISTS environment TEXT", []) ?
12
+
Pool.execute(pool, "ALTER TABLE events ADD COLUMN IF NOT EXISTS session_id TEXT", []) ?
13
+
Pool.execute(pool, "ALTER TABLE issues ADD COLUMN IF NOT EXISTS last_resolved_at TIMESTAMPTZ", []) ?
14
+
Pool.execute(pool, "CREATE INDEX IF NOT EXISTS idx_events_environment ON events (project_id, environment, received_at DESC) WHERE environment IS NOT NULL", []) ?
15
+
Pool.execute(pool, "CREATE INDEX IF NOT EXISTS idx_events_session ON events (session_id, received_at DESC) WHERE session_id IS NOT NULL", []) ?
16
+
Pool.execute(pool, "CREATE INDEX IF NOT EXISTS idx_issues_last_resolved ON issues (last_resolved_at) WHERE last_resolved_at IS NOT NULL", []) ?
17
+
Ok(0)
18
+
end
19
+
20
+
pub fn down(pool :: PoolHandle) -> Int ! String do
21
+
Pool.execute(pool, "DROP INDEX IF EXISTS idx_issues_last_resolved", []) ?
22
+
Pool.execute(pool, "DROP INDEX IF EXISTS idx_events_session", []) ?
23
+
Pool.execute(pool, "DROP INDEX IF EXISTS idx_events_environment", []) ?
24
+
Pool.execute(pool, "ALTER TABLE issues DROP COLUMN IF EXISTS last_resolved_at", []) ?
25
+
Pool.execute(pool, "ALTER TABLE events DROP COLUMN IF EXISTS session_id", []) ?
26
+
Pool.execute(pool, "ALTER TABLE events DROP COLUMN IF EXISTS environment", []) ?
limit_str :: String) -> List < Map < String, String > > ! String do
605
610
let lim = String.from(parse_limit(limit_str))
606
-
let sql = "SELECT id::text AS id, title::text AS title, level::text AS level, status::text AS status, event_count::text AS event_count, first_seen::text AS first_seen, last_seen::text AS last_seen, COALESCE(assigned_to::text, '') AS assigned_to FROM issues WHERE project_id = $1::uuid AND ($2 = '' OR status = $2) AND ($3 = '' OR level = $3) AND ($4 = '' OR assigned_to = NULLIF($4, '')::uuid) AND ($5 = '' OR (last_seen, id) < ($5::timestamptz, NULLIF($6, '')::uuid)) ORDER BY last_seen DESC, id DESC LIMIT $7::int"
let sql = "SELECT id::text AS id, title::text AS title, level::text AS level, status::text AS status, event_count::text AS event_count, first_seen::text AS first_seen, last_seen::text AS last_seen, COALESCE(assigned_to::text, '') AS assigned_to FROM issues WHERE project_id = $1::uuid AND ($2 = '' OR status = $2) AND ($3 = '' OR level = $3) AND ($4 = '' OR assigned_to = NULLIF($4, '')::uuid) AND ($5 = '' OR (last_seen, id) < ($5::timestamptz, NULLIF($6, '')::uuid)) AND ($8 = '' OR EXISTS (SELECT 1 FROM events WHERE issue_id = issues.id AND environment = $8 AND received_at > now() - interval '7 days')) ORDER BY last_seen DESC, id DESC LIMIT $7::int"
0 commit comments