Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions graphify/pg_introspect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from pathlib import Path
from pathlib import Path, PurePosixPath
from graphify.extract import extract_sql


Expand Down Expand Up @@ -135,7 +135,7 @@ def introspect_postgres(dsn: str | None = None) -> dict:
info = psycopg.conninfo.conninfo_to_dict(dsn or "")
host = info.get("host", "localhost")
dbname = info.get("dbname", "db")
virtual_path = Path(f"postgresql://{host}/{dbname}")
virtual_path = PurePosixPath(f"postgresql://{host}/{dbname}")

# Pass virtual path and in-memory DDL content to extract_sql
result = extract_sql(virtual_path, content=ddl_string)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_pg_introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,17 @@ def test_pg_introspect_import_error():
with patch.dict("sys.modules", {"psycopg": None}):
with pytest.raises(ImportError, match="psycopg is required"):
introspect_postgres("postgresql://localhost/db")


def test_pg_introspect_uri_forward_slashes():
"""Assert that the virtual path in postgresql introspection output uses forward slashes on all platforms."""
mock_psycopg = _make_mock_psycopg([], [], [], [], host="some-host", dbname="some-db")
with patch.dict("sys.modules", {"psycopg": mock_psycopg}):
res = introspect_postgres("postgresql://some-host/some-db")

# We should have at least the file node
assert len(res["nodes"]) > 0
for node in res["nodes"]:
assert "\\" not in node["source_file"]
assert "postgresql:/some-host/some-db" in node["source_file"]