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
10 changes: 7 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install -e ".[dev]"
- run: pip install -e ".[dev]" pytest-cov
- name: Enable pg_trgm extension
run: |
PGPASSWORD=discogs psql -h localhost -p 5433 -U discogs -d postgres \
-c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
- name: Run integration and E2E tests
- name: Run all tests with coverage
env:
DATABASE_URL_TEST: postgresql://discogs:discogs@localhost:5433/postgres
run: pytest -m 'postgres or e2e' -v
run: >-
pytest -m 'not mysql' -v
--cov=scripts --cov=lib
--cov-report=term-missing
--cov-fail-under=80
29 changes: 28 additions & 1 deletion tests/integration/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,39 @@ def test_no_unique_constraints_on_child_tables(self) -> None:
assert unique_constraints == [], f"Unexpected UNIQUE constraints: {unique_constraints}"

def test_schema_is_idempotent(self) -> None:
"""Running the schema twice doesn't error (IF NOT EXISTS)."""
"""Running the schema twice doesn't error."""
conn = psycopg.connect(self.db_url, autocommit=True)
with conn.cursor() as cur:
cur.execute(SCHEMA_DIR.joinpath("create_database.sql").read_text())
conn.close()

def test_schema_clears_stale_data_on_rerun(self) -> None:
"""Re-running the schema drops old data so import doesn't hit UniqueViolation."""
conn = psycopg.connect(self.db_url, autocommit=True)

# Insert data as if a previous pipeline run completed
with conn.cursor() as cur:
cur.execute("INSERT INTO release (id, title) VALUES (1, 'DOGA')")
cur.execute(
"INSERT INTO release_artist (release_id, artist_name, extra) "
"VALUES (1, 'Juana Molina', 0)"
)
cur.execute("SELECT count(*) FROM release")
assert cur.fetchone()[0] == 1

# Re-run schema (simulates a fresh pipeline run)
with conn.cursor() as cur:
cur.execute(SCHEMA_DIR.joinpath("create_database.sql").read_text())

# Tables should be empty — no stale data to conflict with new imports
with conn.cursor() as cur:
cur.execute("SELECT count(*) FROM release")
assert cur.fetchone()[0] == 0
cur.execute("SELECT count(*) FROM release_artist")
assert cur.fetchone()[0] == 0

conn.close()


class TestCreateBaseIndexes:
"""Verify create_indexes.sql creates base trigram indexes."""
Expand Down
Loading