Skip to content

Add missing indexes on foreign keys#198

Merged
antoinebhs merged 1 commit into
mainfrom
add-missing-index-on-foreign-key
May 21, 2026
Merged

Add missing indexes on foreign keys#198
antoinebhs merged 1 commit into
mainfrom
add-missing-index-on-foreign-key

Conversation

@antoinebhs
Copy link
Copy Markdown
Contributor

PR Summary

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

Signed-off-by: BOUHOURS Antoine <antoine.bouhours@rte-france.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds a database index to the join table between IdentifierListFilterEntity and its related filter equipment entities. The change includes an explicit @JoinTable annotation in the entity mapping, a Liquibase migration to create the index, and registration of that migration in the master changelog.

Changes

Join Table Index Addition

Layer / File(s) Summary
Index on identifier list filter join table
src/main/java/org/gridsuite/filter/server/entities/identifierlistfilter/IdentifierListFilterEntity.java, src/main/resources/db/changelog/changesets/changelog_20260520T115416Z.xml, src/main/resources/db/changelog/db.changelog-master.yaml
JPA entity declares an explicit join table with a named index on identifier_list_filter_entity_id. Liquibase migration creates the index in the database. Master changelog registers the new migration for execution.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add missing indexes on foreign keys' directly matches the main objective of the changeset, which adds an explicit index on a foreign key column in the database.
Description check ✅ Passed The description explains that after DB analysis, critical foreign keys were missing indexes and provides context for the changes made, which aligns with the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3be9a5b and b1ed2b7.

📒 Files selected for processing (3)
  • src/main/java/org/gridsuite/filter/server/entities/identifierlistfilter/IdentifierListFilterEntity.java
  • src/main/resources/db/changelog/changesets/changelog_20260520T115416Z.xml
  • src/main/resources/db/changelog/db.changelog-master.yaml

Comment on lines +3 to +6
<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>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 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).

@sonarqubecloud
Copy link
Copy Markdown

@antoinebhs antoinebhs merged commit 5ccc614 into main May 21, 2026
5 checks passed
@antoinebhs antoinebhs deleted the add-missing-index-on-foreign-key branch May 21, 2026 08:47
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