Add missing indexes on foreign keys#198
Conversation
Signed-off-by: BOUHOURS Antoine <antoine.bouhours@rte-france.com>
📝 WalkthroughWalkthroughThe PR adds a database index to the join table between ChangesJoin Table Index Addition
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/resources/db/changelog/changesets/changelog_20260520T115416Z.xml`:
- Around line 3-6: Add a precondition to the Liquibase changeSet that checks for
the existing index before creating it: for changeSet id "1779278070381-1" which
creates index "identifier_list_filter_entity_id_idx" on table
"identifier_list_filter_filter_equipment_entity_list", add an indexExists
precondition targeting that index and set onFail="MARK_RAN" so the createIndex
is skipped when the index already exists (this guards against environments where
IdentifierListFilterEntity.java JPA annotations already created the index).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7f8b43e1-2bfd-4f06-a80c-8bd7aee27cf5
📒 Files selected for processing (3)
src/main/java/org/gridsuite/filter/server/entities/identifierlistfilter/IdentifierListFilterEntity.javasrc/main/resources/db/changelog/changesets/changelog_20260520T115416Z.xmlsrc/main/resources/db/changelog/db.changelog-master.yaml
| <changeSet author="bouhoursant (generated)" id="1779278070381-1"> | ||
| <createIndex indexName="identifier_list_filter_entity_id_idx" tableName="identifier_list_filter_filter_equipment_entity_list"> | ||
| <column name="identifier_list_filter_entity_id"/> | ||
| </createIndex> |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify whether this index/table pair is already declared in existing changelogs.
fd -i 'changelog_*.xml' src/main/resources/db/changelog/changesets \
| xargs rg -n -C2 'identifier_list_filter_entity_id_idx|identifier_list_filter_filter_equipment_entity_list'Repository: gridsuite/filter-server
Length of output: 7015
Guard this index creation with a precondition to avoid rollout failures.
The index identifier_list_filter_entity_id_idx is already declared in the JPA entity annotation (IdentifierListFilterEntity.java), so Hibernate may have already created it in existing databases. This Liquibase changeset will fail on those environments without a precondition. Add an indexExists precondition with onFail="MARK_RAN".
Proposed change
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="bouhoursant (generated)" id="1779278070381-1">
+ <preConditions onFail="MARK_RAN">
+ <not>
+ <indexExists indexName="identifier_list_filter_entity_id_idx"
+ tableName="identifier_list_filter_filter_equipment_entity_list"/>
+ </not>
+ </preConditions>
<createIndex indexName="identifier_list_filter_entity_id_idx" tableName="identifier_list_filter_filter_equipment_entity_list">
<column name="identifier_list_filter_entity_id"/>
</createIndex>
</changeSet>
</databaseChangeLog>🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/main/resources/db/changelog/changesets/changelog_20260520T115416Z.xml`
around lines 3 - 6, Add a precondition to the Liquibase changeSet that checks
for the existing index before creating it: for changeSet id "1779278070381-1"
which creates index "identifier_list_filter_entity_id_idx" on table
"identifier_list_filter_filter_equipment_entity_list", add an indexExists
precondition targeting that index and set onFail="MARK_RAN" so the createIndex
is skipped when the index already exists (this guards against environments where
IdentifierListFilterEntity.java JPA annotations already created the index).
|



PR Summary
After DB analysis, we noticed that some critical foreign keys were missing indexes. We add one here.