Files
DocsGPT/tests/storage/db/test_migration_0041.py
arc53-machine a1789d2ab4 Merge main (roles and access revamp) into connectors
Main's access model (team editors and viewers, edit_credentials, owner-only
OAuth servers, per-user tool preferences, resource sponsors) now applies to
connection-backed tools and sources. Our migrations are renumbered to
0040_connections and 0041_connection_account_name, after main's
0038_resource_access_settings and 0039_resource_sponsors.

Where the two sides met: MCP tools save and load their connections as the
tool owner, editors may add a key (a new connection on the owner's account)
but never rewrite an existing connection's secret, fixed values stay
owner-only, and a member's own connection is used in member mode.
2026-09-29 14:02:26 +01:00

51 lines
1.4 KiB
Python

"""Migration round-trip test for 0041_connection_account_name."""
from __future__ import annotations
import os
import subprocess
import sys
from pathlib import Path
import pytest
from sqlalchemy import text
pytestmark = pytest.mark.integration
_0039 = "0041_connection_account_name"
_0038 = "0040_connections"
def _run_alembic(url: str, *args: str) -> None:
ini = Path(__file__).resolve().parents[3] / "docsgpt" / "alembic.ini"
subprocess.check_call(
[sys.executable, "-m", "alembic", "-c", str(ini), *args],
timeout=120,
env={**os.environ, "POSTGRES_URI": url},
)
def _has_column(conn) -> bool:
return conn.execute(
text(
"SELECT 1 FROM information_schema.columns WHERE table_schema = 'public' "
"AND table_name = 'connector_sessions' AND column_name = 'account_name'"
)
).fetchone() is not None
class TestMigration0041RoundTrip:
def test_head_has_account_name(self, pg_engine):
with pg_engine.connect() as conn:
assert _has_column(conn)
def test_downgrade_drops_then_upgrade_restores(self, pg_engine):
url = pg_engine.url.render_as_string(hide_password=False)
_run_alembic(url, "downgrade", _0038)
with pg_engine.connect() as conn:
assert not _has_column(conn)
_run_alembic(url, "upgrade", "head")
with pg_engine.connect() as conn:
assert _has_column(conn)