Skip to content

Commit 95d059c

Browse files
committed
breaking(BA-5653): drop sessions/kernels access_key columns
Schema-only step following the BA-5650 refactor stack. The access_key column is removed from both the sessions and kernels tables; downstream code resolves the owner's main_access_key from the users table at read time (keypair-scoped concurrency tracking, resource policy lookups, agent RPC payloads). The user_uuid column stays on both tables as the canonical owner reference. Adds alembic migration 8c1d2e3f4a5b_drop_session_kernel_access_key on top of 2a531e0c528e.
1 parent 7cad928 commit 95d059c

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

changes/11040.breaking.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Drop the `access_key` column from `sessions` and `kernels` tables. Downstream code now resolves the owner's `main_access_key` from the `users` table at read time (keypair-scoped concurrency tracking, resource policy lookups, agent RPC payloads). The `user_uuid` column stays as the canonical owner reference on both tables.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""drop sessions/kernels access_key columns
2+
3+
Part of BA-5653. The ``access_key`` column is removed from the
4+
``sessions`` and ``kernels`` tables. Downstream code now resolves the
5+
owner's ``main_access_key`` from the ``users`` table when needed
6+
(keypair-scoped concurrency tracking, resource policy lookups, agent
7+
RPC payloads). The ``user_uuid`` column is kept on both tables as the
8+
canonical owner reference; only the redundant ``access_key`` snapshot
9+
is dropped.
10+
11+
Revision ID: 8c1d2e3f4a5b
12+
Revises: 2a531e0c528e
13+
Create Date: 2026-04-14
14+
15+
"""
16+
17+
import sqlalchemy as sa
18+
from alembic import op
19+
20+
# revision identifiers, used by Alembic.
21+
revision = "8c1d2e3f4a5b"
22+
down_revision = "2a531e0c528e"
23+
branch_labels = None
24+
depends_on = None
25+
26+
27+
def _column_names(inspector: sa.engine.reflection.Inspector, table: str) -> set[str]:
28+
return {c["name"] for c in inspector.get_columns(table)}
29+
30+
31+
def _index_names(inspector: sa.engine.reflection.Inspector, table: str) -> set[str]:
32+
return {ix["name"] for ix in inspector.get_indexes(table) if ix["name"] is not None}
33+
34+
35+
def upgrade() -> None:
36+
bind = op.get_bind()
37+
inspector = sa.inspect(bind)
38+
39+
for table in ("sessions", "kernels"):
40+
cols = _column_names(inspector, table)
41+
if "access_key" not in cols:
42+
continue
43+
# Drop any index referencing access_key on this table first.
44+
for ix_name in _index_names(inspector, table):
45+
if "access_key" in ix_name:
46+
op.drop_index(ix_name, table_name=table)
47+
op.drop_column(table, "access_key")
48+
49+
50+
def downgrade() -> None:
51+
"""Recreate the ``access_key`` columns as nullable.
52+
53+
NOTE: This downgrade is intentionally lossy. Previous values cannot
54+
be restored because the upgrade does not preserve them. Callers that
55+
depended on the old column must resolve ``main_access_key`` via the
56+
``users`` table instead.
57+
"""
58+
bind = op.get_bind()
59+
inspector = sa.inspect(bind)
60+
61+
for table in ("sessions", "kernels"):
62+
cols = _column_names(inspector, table)
63+
if "access_key" in cols:
64+
continue
65+
op.add_column(
66+
table,
67+
sa.Column("access_key", sa.String(length=20), nullable=True),
68+
)

0 commit comments

Comments
 (0)