Skip to content

feat: add integration tests for Alembic migrations#463

Merged
jirhiker merged 7 commits intostagingfrom
feature/356-alembic-migration-tests
Feb 4, 2026
Merged

feat: add integration tests for Alembic migrations#463
jirhiker merged 7 commits intostagingfrom
feature/356-alembic-migration-tests

Conversation

@kbighorse
Copy link
Contributor

@kbighorse kbighorse commented Feb 4, 2026

Summary

Add comprehensive integration tests for Alembic migrations to ensure CI catches migration errors before merge.

Fixes #356

Changes

New test file: tests/integration/test_alembic_migrations.py

Test Categories

Category Tests Purpose
Migration History 3 No branching, chain integrity, current revision
Schema Verification 7 Core tables, NMA tables, columns, PostGIS
FK Integrity 5 Data model relationships
Indexes 1 Spatial index verification
Downgrade 1 (skipped) Manual downgrade testing

Tests Added

Migration History:

  • test_migrations_have_no_multiple_heads - Ensures no branching in migration history
  • test_all_migrations_have_down_revision - Validates migration chain is unbroken
  • test_current_revision_matches_head - Verifies DB is at latest migration

Schema Verification:

  • test_core_tables_exist - Verifies 13 core tables
  • test_legacy_nma_tables_exist - Verifies 9 NMA legacy tables
  • test_thing_table_has_required_columns - Checks required columns including legacy PKs
  • test_location_table_has_geometry_column - Verifies PostGIS geometry
  • test_observation_table_has_required_columns - Checks observation schema
  • test_alembic_version_table_exists - Verifies migration tracking
  • test_postgis_extension_enabled - Verifies PostGIS extension

FK Integrity:

  • test_observation_has_sample_fk
  • test_sample_has_field_activity_fk
  • test_field_activity_has_field_event_fk
  • test_field_event_has_thing_fk
  • test_nma_chemistry_has_thing_fk

Indexes:

  • test_location_has_spatial_index - Verifies GIST spatial index

Test Plan

  • All 16 tests pass locally (1 skipped by design)
  • CI passes
================== 16 passed, 1 skipped in 9.97s ==================

🤖 Generated with Claude Code

kbighorse and others added 2 commits February 4, 2026 09:14
Add comprehensive test coverage for Alembic migrations to catch
migration errors before deployment.

Tests include:
- Migration history validation (no branching, chain integrity)
- Schema verification (core tables, NMA legacy tables, columns)
- Foreign key integrity (data model relationships)
- Index verification (spatial indexes)
- Downgrade capability (skipped by default for safety)

Fixes #356

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 4, 2026 17:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive integration tests for Alembic database migrations to catch migration errors in CI before merging. The tests verify migration history consistency, schema structure, foreign key relationships, indexes, and downgrade capability.

Changes:

  • Added 16 integration tests covering migration history, schema verification, foreign key integrity, and indexes
  • Tests validate core tables, NMA legacy tables, required columns, PostGIS configuration, and spatial indexes
  • Included downgrade test (skipped by default to avoid schema modification)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/integration/test_alembic_migrations.py New test file with comprehensive Alembic migration tests organized into four test classes
admin/views/chemistry_sampleinfo.py Removed extraneous blank line

Address Copilot review comment about inconsistent indentation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 4, 2026 17:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Add missing `Request` and `HasOne` imports that were causing
NameError during test collection.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 4, 2026 17:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

kbighorse and others added 2 commits February 4, 2026 09:29
Add tests that verify all admin view modules can be imported
successfully. This catches missing imports (like Request, HasOne)
during CI before they cause runtime errors.

Tests include:
- Package-level import verification
- Individual module import verification
- Core view module parametrized tests
- Configuration attribute validation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@kbighorse kbighorse requested a review from Copilot February 4, 2026 17:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@kbighorse kbighorse requested a review from jirhiker February 4, 2026 17:32
@jirhiker jirhiker merged commit 88602e4 into staging Feb 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for Alembic migrations

2 participants