Skip to content

Conversation

@dfcoffin
Copy link
Contributor

Summary

Fixes incorrect index mapping in the electric_power_quality_summaries table where idx_epqs_summary_interval_start was indexing the id column instead of the summary_interval_start column.

Root Cause

This issue was introduced in commit d5e321b when uuid columns were removed and replaced with id PRIMARY KEY columns. During the migration, one index was incorrectly remapped:

Before (incorrect):

CREATE INDEX idx_epqs_summary_interval_start ON electric_power_quality_summaries (uuid);

After uuid removal (still incorrect):

CREATE INDEX idx_epqs_summary_interval_start ON electric_power_quality_summaries (id);

Fixed (correct):

CREATE INDEX idx_epqs_summary_interval_start ON electric_power_quality_summaries (summary_interval_start);

Changes

  • File Modified: openespi-common/src/main/resources/db/migration/V3__Create_additiional_Base_Tables.sql
  • Line: 644
  • Change: Index now correctly points to summary_interval_start column

Analysis of UUID Index Removals

Commit d5e321b removed 25 uuid indexes across V1 and V3 migrations:

  • 24 removals were correct: All tables have id CHAR(36) PRIMARY KEY which automatically creates an index
  • 1 bug found: idx_epqs_summary_interval_start was indexing wrong column

Testing

  • ✅ All H2 repository tests passing (60+ tests)
  • ✅ Flyway migrations V1, V2, V3 execute successfully
  • ✅ Index now correctly targets summary_interval_start column
  • ⚠️ TestContainers integration tests skipped due to Docker Desktop 29.1.3 compatibility issue (unrelated to this fix)

Impact

Queries filtering by summary_interval_start will now properly use this index for improved performance.

Related Issues

TestContainers Issue (not addressed in this PR):

  • TestContainers 1.20.1 has compatibility issues with Docker Desktop 29.1.3
  • This is an environmental issue separate from the index fix
  • Recommend creating a separate issue for investigation

🤖 Generated with Claude Code

Fix incorrect index mapping where idx_epqs_summary_interval_start was
indexing the 'id' column instead of the 'summary_interval_start' column.

This issue was introduced when uuid columns were removed and replaced
with id PRIMARY KEY columns. The index name suggests it should index
summary_interval_start, not id.

Changes:
- V3 migration: Change idx_epqs_summary_interval_start to index
  summary_interval_start column instead of id column

Testing:
- All H2 repository tests passing (60+ tests)
- Flyway migrations V1, V2, V3 execute successfully
- Index now correctly targets summary_interval_start column

Fixes issue identified in commit d5e321b where uuid index removal
inadvertently created an incorrectly mapped index.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@dfcoffin dfcoffin merged commit a866f03 into main Dec 20, 2025
5 checks passed
@dfcoffin dfcoffin deleted the fix/flyway-index-corrections branch December 20, 2025 22:40
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.

2 participants