Skip to content

Commit ba320c9

Browse files
authored
Maintain order in explicit naming contingency lists (#134)
1 parent 0c8f3ef commit ba320c9

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/main/java/org/gridsuite/actions/server/entities/IdBasedContingencyListEntity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
public class IdBasedContingencyListEntity extends AbstractContingencyEntity {
3434

3535
@OneToMany(cascade = CascadeType.ALL)
36+
@OrderColumn(name = "identifier_order")
3637
private List<IdentifierListEntity> identifiersListEntities;
3738

3839
public IdBasedContingencyListEntity(IdBasedContingencyList idBasedContingencyList) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
2+
<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">
3+
<changeSet author="braquartdav (generated)" id="1756286263175-7">
4+
<addColumn tableName="id_based_contingency_list_identifiers_list_entities">
5+
<column name="identifier_order" type="integer"/>
6+
</addColumn>
7+
<!-- mandatory: init this new column with a default order -->
8+
<sql dbms="postgresql">
9+
WITH ordered_aleas AS (
10+
SELECT identifiers_list_entities_id, ROW_NUMBER() OVER (PARTITION BY id_based_contingency_list_entity_id
11+
ORDER BY identifiers_list_entities_id) - 1 as id_order
12+
FROM id_based_contingency_list_identifiers_list_entities
13+
)
14+
UPDATE id_based_contingency_list_identifiers_list_entities a
15+
SET identifier_order = oa.id_order
16+
FROM ordered_aleas oa
17+
WHERE a.identifiers_list_entities_id = oa.identifiers_list_entities_id;
18+
</sql>
19+
</changeSet>
20+
</databaseChangeLog>

src/main/resources/db/changelog/db.changelog-master.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ databaseChangeLog:
4040
file: changesets/changelog_20250704T094426Z.xml
4141
relativeToChangelogFile: true
4242

43+
- include:
44+
file: changesets/changelog_20250827T091725Z.xml
45+
relativeToChangelogFile: true

0 commit comments

Comments
 (0)