Add the scoped PostgreSQL/pgvector schema, independent ingestion settings and ports, embedding profile checks, and trusted administrator bootstrap. Include repository contracts and guidance, organized provider-free and PostgreSQL tests, deployment setup, and byte-preserving migration attributes. Validation: 163 tests passed; all 48 PostgreSQL cases passed with pgvector Python 0.5.0 and 0.3.6. No production schema or historical metadata was changed.
57 lines
2.1 KiB
Python
57 lines
2.1 KiB
Python
"""Check dedicated PostgreSQL/pgvector prerequisites without printing credentials."""
|
|
import os
|
|
import sys
|
|
|
|
from sqlalchemy import create_engine, text
|
|
|
|
from tests.support.postgres import (
|
|
fresh_test_database, prepare_extension, validated_test_url,
|
|
)
|
|
|
|
|
|
def main():
|
|
engine = None
|
|
failed = False
|
|
versions = None
|
|
try:
|
|
raw = os.environ.get("TEST_DATABASE_URL")
|
|
if not raw:
|
|
raise ValueError("Missing isolated test database configuration")
|
|
url = validated_test_url(raw)
|
|
engine = create_engine(url, hide_parameters=True,
|
|
connect_args={"connect_timeout": 5})
|
|
with engine.begin() as connection:
|
|
server = connection.execute(text("SHOW server_version")).scalar_one()
|
|
can_create_db = connection.execute(text("""
|
|
SELECT rolsuper OR rolcreatedb FROM pg_roles WHERE rolname=current_user
|
|
""")).scalar_one()
|
|
if not can_create_db:
|
|
raise ValueError("Test role requires database creation privileges")
|
|
prepare_extension(connection)
|
|
vector = connection.execute(text("""
|
|
SELECT extversion FROM pg_extension WHERE extname='vector'
|
|
""")).scalar_one()
|
|
versions = (server, vector)
|
|
# Exercise actual CREATE/DROP DATABASE and extension privileges up front.
|
|
with fresh_test_database(url) as scratch:
|
|
scratch_engine = create_engine(scratch, hide_parameters=True)
|
|
try:
|
|
with scratch_engine.begin() as connection:
|
|
prepare_extension(connection)
|
|
finally:
|
|
scratch_engine.dispose()
|
|
except Exception:
|
|
failed = True
|
|
finally:
|
|
if engine is not None:
|
|
engine.dispose()
|
|
if failed:
|
|
print("PostgreSQL prerequisites failed: verify TEST_DATABASE_URL, connectivity, isolated _test database, pgvector namespace and CREATE DATABASE/extension privileges.", file=sys.stderr)
|
|
return 1
|
|
print(f"PostgreSQL prerequisites passed: server {versions[0]}, vector {versions[1]}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|