refactor(db): map search_space_id ORM attrs to physical workspace_id column

Phase 1 (rename DB) commit 1a: shim every search_space_id /
owner_search_space_id column to the renamed physical column
(workspace_id / owner_workspace_id) via Column("workspace_id", ...),
keeping the ORM attribute name unchanged so existing callers are
untouched. Flip all Table-level references that resolve by column key
(inner __table_args__ strings, the ck_connections_scope_owner CHECK
text, and the _INDEX_DEFINITIONS runtime DDL) plus the searchspace-named
constraint/index names to workspace_id. Update the three raw-SQL test
fixtures that referenced the physical column.

Note: SQLAlchemy defaults a column's key to its name, so passing an
explicit "workspace_id" name moves the Table.c key to workspace_id;
Table-level string refs must therefore change in this phase (the
opposite of the original plan's finding 1). The ORM attribute, the
SearchSpace class, relationships, table names, and FK target strings are
intentionally left for later commits/Phase 2.

Verified: unit 2375 passed/1 skip, integration 346 passed (baseline
parity); create_all builds every table with workspace_id.
This commit is contained in:
CREDO23 2026-06-26 12:05:52 +02:00
parent 3b31352e19
commit 533cdfcc81
3 changed files with 76 additions and 30 deletions

View file

@ -160,7 +160,7 @@ async def _purge_test_search_space(search_space_id: int):
conn = await asyncpg.connect(_ASYNCPG_URL)
try:
result = await conn.execute(
"DELETE FROM documents WHERE search_space_id = $1",
"DELETE FROM documents WHERE workspace_id = $1",
search_space_id,
)
deleted = int(result.split()[-1])

View file

@ -125,11 +125,11 @@ async def race_user_and_space(async_engine):
{"uid": user_id},
)
await cleanup.execute(
text("DELETE FROM search_space_memberships WHERE search_space_id = :id"),
text("DELETE FROM search_space_memberships WHERE workspace_id = :id"),
{"id": space_id},
)
await cleanup.execute(
text("DELETE FROM search_space_roles WHERE search_space_id = :id"),
text("DELETE FROM search_space_roles WHERE workspace_id = :id"),
{"id": space_id},
)
await cleanup.execute(