Skip to content

Commit

Permalink
Replace enums ordinal in database with their names
Browse files Browse the repository at this point in the history
Signed-off-by: Seddik Yengui <[email protected]>
  • Loading branch information
Seddik Yengui committed Sep 3, 2024
1 parent 7f95c07 commit 076eda6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--
Copyright (c) 2021, RTE (http://www.rte-france.com)
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
License, v. 2.0. If a copy of the MPL was not distributed wigit th this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@

package org.gridsuite.filter.server.entities.identifierlistfilter;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.gridsuite.filter.server.entities.AbstractFilterEntity;
import org.gridsuite.filter.utils.EquipmentType;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.List;

/**
Expand All @@ -33,6 +29,7 @@
@Table(name = "identifier_list_filter")
public class IdentifierListFilterEntity extends AbstractFilterEntity {

@Enumerated(EnumType.STRING)
@Column(name = "equipmentType")
private EquipmentType equipmentType;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<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="yenguised (generated)" id="1725320054035-1">
<addColumn tableName="identifier_list_filter">
<column name="equipment_type_new" type="varchar(255)" />
</addColumn>
<sql>
UPDATE identifier_list_filter
SET equipment_type_new = CASE
WHEN equipment_type = 0 THEN 'LINE'
WHEN equipment_type = 1 THEN 'GENERATOR'
WHEN equipment_type = 2 THEN 'LOAD'
WHEN equipment_type = 3 THEN 'SHUNT_COMPENSATOR'
WHEN equipment_type = 4 THEN 'STATIC_VAR_COMPENSATOR'
WHEN equipment_type = 5 THEN 'BATTERY'
WHEN equipment_type = 6 THEN 'BUS'
WHEN equipment_type = 7 THEN 'BUSBAR_SECTION'
WHEN equipment_type = 8 THEN 'DANGLING_LINE'
WHEN equipment_type = 9 THEN 'LCC_CONVERTER_STATION'
WHEN equipment_type = 10 THEN 'VSC_CONVERTER_STATION'
WHEN equipment_type = 11 THEN 'TWO_WINDINGS_TRANSFORMER'
WHEN equipment_type = 12 THEN 'THREE_WINDINGS_TRANSFORMER'
WHEN equipment_type = 13 THEN 'HVDC_LINE'
WHEN equipment_type = 14 THEN 'SUBSTATION'
WHEN equipment_type = 15 THEN 'VOLTAGE_LEVEL'
END;
</sql>
<dropColumn tableName="identifier_list_filter" columnName="equipment_type" />
<renameColumn tableName="identifier_list_filter" oldColumnName="equipment_type_new" newColumnName="equipment_type" />
</changeSet>
</databaseChangeLog>
3 changes: 3 additions & 0 deletions src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ databaseChangeLog:
relativeToChangelogFile: true
- include:
file: changesets/changelog_20240426T120841Z.xml
relativeToChangelogFile: true
- include:
file: changesets/changelog_20240902T233408Z.xml
relativeToChangelogFile: true

0 comments on commit 076eda6

Please sign in to comment.