Skip to content
Merged
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 pgdevkit/fetch_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .diff import DiffKind, compute_diff
from .introspect import introspect_db
from .parser import parse_directory
from .parser import IGNORED_DIR_NAMES, parse_directory

_LAYER_PREFIX_RE = re.compile(r"^\d+_?")

Expand Down Expand Up @@ -41,7 +41,7 @@ def layer_folder_for(scripts_dir: Path, schema: str) -> Path:
if no existing folder matches."""
if scripts_dir.is_dir():
for entry in scripts_dir.iterdir():
if not entry.is_dir() or entry.name in ("migrations", "_migration_scripts"):
if not entry.is_dir() or entry.name in ("migrations", "_migration_scripts") or entry.name in IGNORED_DIR_NAMES:
continue
if _LAYER_PREFIX_RE.sub("", entry.name).lower() == schema.lower():
return entry
Expand Down
10 changes: 10 additions & 0 deletions pgdevkit/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@

logger = logging.getLogger(__name__)

# Tooling/scratch dirs that can end up inside a database/ tree (e.g. git
# worktrees checked out under database/.worktree for isolated test DBs) but
# never hold real schema content.
IGNORED_DIR_NAMES = {
".worktree", ".worktrees", ".claude", ".vscode", "node_modules",
"__pycache__", ".pytest_cache", ".mypy_cache", ".ruff_cache",
}

# Regex to extract dollar-quoted body (Postgres-only construct)
_DOLLAR_BODY = re.compile(r'\$(\w*)\$(.*?)\$\1\$', re.DOTALL | re.IGNORECASE)

Expand All @@ -35,6 +43,8 @@ def parse_directory(scripts_dir: Path, *, dialect: str | Dialect = "postgres") -
resolved = resolve_dialect(dialect)
db_schema = DatabaseSchema()
for sql_file in sorted(scripts_dir.rglob("*.sql")):
if IGNORED_DIR_NAMES.intersection(sql_file.relative_to(scripts_dir).parts[:-1]):
continue
_parse_file(sql_file, db_schema, resolved)
return db_schema

Expand Down
4 changes: 3 additions & 1 deletion pgdevkit/testdb/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from ..db.complex_types import ComplexHelper
from ..dialect import Dialect, POSTGRES
from ..parser import IGNORED_DIR_NAMES

logger = logging.getLogger(__name__)
logging.getLogger("sqlglot").setLevel(logging.ERROR)
Expand Down Expand Up @@ -121,7 +122,8 @@ def _get_sql_deps(sql: str, dialect: Dialect = POSTGRES) -> set[str]:
def _iter_sql_files(database_dir: Path, dialect: Dialect = POSTGRES):
"""Yield (Path, sql_content) pairs in dependency-safe execution order."""
files: list[Path] = []
for root, _, dbfiles in os.walk(database_dir):
for root, dirs, dbfiles in os.walk(database_dir):
dirs[:] = [d for d in dirs if d not in IGNORED_DIR_NAMES]
if "_migration_scripts" in root or "migrations" in root:
continue
for file in dbfiles:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ packages = ["pgdevkit"]

[project]
name = "pgdevkit"
version = "0.3.6"
version = "0.3.8"
description = "A helper for developing with Postgres"
readme = "README.md"
requires-python = ">=3.14"
Expand Down
Loading