The staleness fixture's project goes into the tenant schema, and comes out of it

Same shape as the append-only guards: the project row is created in the
organization's own schema and the cleanup drops that schema. The old cleanup
deleted from public.projects, which since 0005 has cleaned nothing up while
looking like it did - the sort of teardown that reads as careful and is not.
This commit is contained in:
umbra audio
2026-10-03 13:42:02 -07:00
parent 7b12964a9b
commit 9a84a9d227

View File

@@ -177,9 +177,17 @@ def test_a_stored_online_node_reads_offline_through_the_api() -> None:
"INSERT INTO public.organizations (id, name, slug) VALUES (%s, %s, %s)",
(organization, f"Stale {organization.hex[:8]}", f"stale-{organization.hex[:8]}"),
)
# The project is per-tenant since migration 0005. It is created here so the
# node has something to report against, and it goes into the organization's
# own schema under an unqualified name - the shape the application writes.
cursor.execute(
"INSERT INTO public.projects (id, organization_id, name, slug) VALUES (%s, %s, %s, %s)",
(project, organization, "Stale Book", f"stale-book-{project.hex[:8]}"),
"SELECT set_config('search_path', "
"'\"' || app.tenant_schema_name(%s::uuid) || '\", public', true)",
(organization,),
)
cursor.execute(
"INSERT INTO projects (id, name, slug) VALUES (%s, %s, %s)",
(project, "Stale Book", f"stale-book-{project.hex[:8]}"),
)
cursor.execute(
"INSERT INTO public.compute_nodes (id, organization_id, name, status, "
@@ -212,7 +220,10 @@ def test_a_stored_online_node_reads_offline_through_the_api() -> None:
cursor.execute("SAVEPOINT cleanup")
try:
cursor.execute("DELETE FROM public.compute_nodes WHERE id = %s", (node_id,))
cursor.execute("DELETE FROM public.projects WHERE id = %s", (project,))
# The project went into the tenant schema, so that is what has to go.
# `public.projects` is not where it was written and deleting from it
# would clean nothing up.
cursor.execute("DROP SCHEMA IF EXISTS %s CASCADE", (f"tenant_{organization.hex}",))
cursor.execute("DELETE FROM public.organizations WHERE id = %s", (organization,))
except psycopg.Error:
cursor.execute("ROLLBACK TO SAVEPOINT cleanup")